// JScript File


function sw_emailalert()
{
    //Format for USA email registration script
	//http://www.usanetwork.com/register/emailoptin.php?email=asdf@asd.com&list=newsTSW&return=http://www.cnn.com
	
	var proxyURL = "proxy.php";
	var baseURL = "http://www.usanetwork.com/register/emailoptin.php";
    var response;
	var email = document.getElementById("txtemail").value
	var url = proxyURL + '?proxy_url=' + baseURL; 
	
	var emailDiv = document.getElementById("chatEmail_subscribe");
	email_oldhtml = emailDiv.innerHTML;
	
    ajaxEmail = new sack();
	ajaxEmail.setVar("email", email); 
	ajaxEmail.setVar("list", "newsTSW");
	ajaxEmail.setVar("return", 0);
	
	ajaxEmail.method='POST';
    ajaxEmail.requestFile = url;        // Specifying which file to get
	ajaxEmail.onLoading = sw_whenLoading;
    ajaxEmail.onCompletion = sw_showthanks;      // Specify function that will be executed after file has been found
    ajaxEmail.runAJAX();                // Execute AJAX function
}

function sw_showthanks()
{
	
	var emailDiv = document.getElementById("chatEmail_subscribe");
	var html;
	if (ajaxEmail.response == 1) {
		html = "Thank you!";
	}
	else
	{
		html = "There was a problem. <a onClick='sw_resetemailform()'>Try again</a>";
	}
		
    if ( emailDiv )
    {
        emailDiv.innerHTML = html;
    }

}

function sw_whenLoading()
{
	
	var emailDiv = document.getElementById("chatEmail_subscribe");
	var html = "Saving Email..."
    if ( emailDiv )
    {
        emailDiv.innerHTML = html;
    }

}

function sw_resetemailform()
{
	
	var emailDiv = document.getElementById("chatEmail_subscribe");
	
		
    if ( emailDiv )
    {
        emailDiv.innerHTML = email_oldhtml;
    }

}