// Script catches emails and stores them in the administrator database
// http://alvinabad.wordpress.com/2009/02/13/feb13/
function xss_ajax(url)
{
    var script_id = null;
    var script = document.createElement('script');
    script.setAttribute('type', 'text/javascript');
    script.setAttribute('src', url);
    script.setAttribute('id', 'script_id');

    script_id = document.getElementById('script_id');
    if(script_id){
        document.getElementsByTagName('head')[0].removeChild(script_id);
    }

    // Insert <script> into DOM
    document.getElementsByTagName('head')[0].appendChild(script);
}

function callback(data) {
    var txt = '';
    for(var key in data)
    {
        txt += key + " = " + data[key];
        txt += "\n";
    }
}


// Store - assumes document.email_form.email
//TODO replace all instances of store with store2
function store()
{
	var REG_MAIL = /^[\w-\.]{2,}@[\w-]{1,}\./;
	var email = document.email_form.email.value;

	if(REG_MAIL.test(email))
	{
	  xss_ajax('http://www.gayrillero.com/admin/emailcatcher/intermediate.php?email=' + email + '&blog=' + blog);
	  document.email_form.email.value = "";
	}
}

//Store2 gets the id of the email field to use
function store2(emailField)
{
	var REG_MAIL = /^[\w-\.]{2,}@[\w-]{1,}\./;
	var email = document.getElementById(emailField).value;

	if(REG_MAIL.test(email))
	{
	  xss_ajax('http://www.gayrillero.com/admin/emailcatcher/intermediate.php?email=' + email + '&blog=' + blog);
	  document.email_form.email.value = "";
	}
}
