// JScript File


function checkAndSubmitRegistration()
{
    	

	//var proxyURL = "proxy.php";
	//var baseURL = "http://boards-test.nbcuni.com/usa/create_account_action.php";
	//var url = proxyURL + '?proxy_url=' + baseURL; 
	var url = "/create_account_action.php";

	var email = document.getElementById("email").value;
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	var TC = (document.getElementById("TC").checked) ? "Y" : "N";
	var CAPTCHA = document.getElementById("captcha").value;
	var CAPTCHAID = document.getElementById("captchaID").value;
	
	var formDiv = document.getElementById("reg_cont");
	reg_oldhtml = formDiv.innerHTML;
	
    ajaxReg = new sack();
	ajaxReg.setVar("email", email); 
	ajaxReg.setVar("username", username);
	ajaxReg.setVar("password", password);
	ajaxReg.setVar("TC", TC);
	ajaxReg.setVar("CAPTCHA", CAPTCHA);
	ajaxReg.setVar("CAPTCHAID", CAPTCHAID);
	
	ajaxReg.method='POST';
    ajaxReg.requestFile = url;        // Specifying which file to post to
	ajaxReg.onLoading = reg_whenLoading;
    ajaxReg.onCompletion = reg_showthanks;      // Specify function that will be executed after file has been found
    ajaxReg.runAJAX();                 // Execute AJAX function
}

function reg_loadCaptcha()
{
    	

	//var proxyURL = "proxy.php";
	//var baseURL = "http://boards-test.nbcuni.com/usa/create_account_embed.php";
	
	//var url = proxyURL + '?proxy_url=' + baseURL; 
	var url = "/create_account_embed.php"; 

    ajaxCap = new sack();
		
	ajaxCap.method='GET';
    ajaxCap.requestFile = url;        // Specifying which file to post to
	//ajaxCap.onLoading = reg_whenLoading;
    ajaxCap.onCompletion = reg_showCaptcha;      // Specify function that will be executed after file has been found
    ajaxCap.runAJAX();                 // Execute AJAX function
}

function reg_showCaptcha()
{
	
	var captchaID = ajaxCap.response;
	document.getElementById("captchaID").value = captchaID;
	document.getElementById("captchaImg").src = boardURL + "index.php?s=&act=Reg&CODE=image&rc="+captchaID;
	
	
}

function reg_showthanks()
{
	
	var errorDiv = document.getElementById("errorDiv");
	var formDiv = document.getElementById("reg_cont");
	var html;
	if (ajaxReg.response == 1) {
		//Success! Replace the form with a thank you message
		html = "<p><br>Your registration was successful.</p>";
		if ( formDiv )
		{
			errorDiv.innerHTML = " ";
			formDiv.innerHTML = html;
			
		}
		//Close the thank you message 
		sw_closeRegThanks();
	}
	else
	{
		//If there is an error, show the error message below the form
		html = ajaxReg.response;
		if ( errorDiv )
		{
			errorDiv.innerHTML = html;
		}
	}
		
    

}

function sw_closeRegThanks() 
{
	//After a short delay, close the popup, reset the form
	setTimeout("closeRegistrationPop()",3000);
	setTimeout("reg_resetForm()",3250);
	//setTimeout("joinChatRoom(groupNameToJoin, groupDescription, groupTypeToJoin, groupVideoUrl)",3250);
}

function reg_whenLoading()
{
	
	var errorDiv = document.getElementById("errorDiv");
	var html = "Sending..."
    if ( errorDiv )
    {
        errorDiv.innerHTML = html;
    }

}


function reg_resetForm()
{
	
	var formDiv = document.getElementById("reg_cont");
		
    if ( formDiv )
    {
        formDiv.innerHTML = reg_oldhtml;
    }

}