/*
	checktermsread.js
*/

var CheckTermsRead = 
{
	init : function(cBox, newUser1, newUser2, pswd1, pswd2)
	{
		if ( typeof(cBox) == 'string' )
			CheckTermsRead.termEl = document.getElementById(cBox);
		else
			CheckTermsRead.termEl = cBox;
		
		if ( CheckTermsRead.termEl == null )
			throw new Error("CheckTermsRead.init: " +  cBox + " not found!");
		
		if ( typeof(newUser1) == 'string' )
			CheckTermsRead.firstRadioEl = document.getElementById(newUser1);
		else
			CheckTermsRead.firstRadioEl = newUser1;
		
		if ( CheckTermsRead.firstRadioEl == null )
			throw new Error("CheckTermsRead.init: " + newUser1  + " not found!");
			
		if ( typeof(newUser2) == 'string' )
			CheckTermsRead.secondRadioEl = document.getElementById(newUser2);
		else
			CheckTermsRead.secondRadioEl = newUser2;
		
		if ( CheckTermsRead.secondRadioEl == null )
			throw new Error("CheckTermsRead.init: " + newUser2 + " not found");
			
		if ( typeof(pswd1) == 'string' )
			CheckTermsRead.firstPswdEl = document.getElementById(pswd1);
		else
			CheckTermsRead.firstPswdEl = pswd1;
		
		if ( CheckTermsRead.firstPswdEl == null )
			throw new Error("CheckTermsRead.init: " + pswd1  + " not found!");
			
		if ( typeof(pswd2) == 'string' )
			CheckTermsRead.secondPswdEl = document.getElementById(pswd2);
		else
			CheckTermsRead.seconPswdEl = newpswd2;
		
		if ( CheckTermsRead.secondPswdEl == null )
			throw new Error("CheckTermsRead.init: " + pswd2 + " not found");
	},
	check : function(e)
	{
		if ( !CheckTermsRead.termEl.checked )
		{
			alert("You need to read the terms and conditions first before you can proceed.");
			e.cancelable ? e.preventDefault() : e.returnValue = false;
		}
	},
	checkNewUser : function(e)
	{
		if ( !CheckTermsRead.firstRadioEl.checked && !CheckTermsRead.secondRadioEl.checked )
		{
			alert("New customer or previous customer radio button not checked");
			e.cancelable ? e.preventDefault() : e.returnValue = false;
		}
	},
	passwords : function(e)
	{
		var pswd = new Array(CheckTermsRead.firstPswdEl.value, CheckTermsRead.secondPswdEl.value);
		var flag = true;
		
		for ( var i = 0; i != pswd.length && flag == true; i++ )
		{
			if ( pswd[i].match(/^[a-zA-Z0-9]{6,10}$/) == null )
				flag = false;
		}
		
		if ( flag == false )
		{
			alert("Password Invalid - 6 to 10 long and alpha numeric characters only!");
			e.cancelable ? e.preventDefault() : e.returnValue = false;
		}
	}
};
