/* CASH DONATIONS RELATED FUNCTIONS */
/***** BROWSER DETECTION *****/
var g_UA = navigator.userAgent.toLowerCase();
var g_NETSCAPE = (g_UA.indexOf("netscape")>0);
var g_NETSCAPE8 = (g_UA.indexOf("netscape/8")>0);
var g_NETSCAPE_LESS8 = (g_NETSCAPE && !g_NETSCAPE8);
var g_FIREFOX = (g_UA.indexOf("firefox")>0) 
var g_OPERA = (g_UA.indexOf("opera")>0)
var g_WEBTV = (g_UA.indexOf("webtv")>0)
var g_IE = (!g_OPERA && !g_WEBTV && g_UA.indexOf("msie")>0); //navigator.userAgent contains "msie" for Opera and WebTv too!!
var g_SAFARI = (g_UA.indexOf("safari") != -1);
var g_KONQUEROR = (g_UA.indexOf("konqueror") != -1);
var g_USE_NEW_CONTENT_MANAGER = (document.getElementById && document.designMode && !g_SAFARI && !g_KONQUEROR && !g_NETSCAPE_LESS8);
var g_USE_FCK_CONTENT_MANAGER = (!g_SAFARI && !g_KONQUEROR && !g_NETSCAPE_LESS8 && !g_OPERA);
var g_FormatDate = "MM/DD/YYYY";
var g_IE_VERSION5 = g_IE && (g_UA.charAt(navigator.appVersion.indexOf("msie") + 5) >= 5);
var g_WIN16 = (navigator.platform.indexOf("Win16") > 0);
var g_MAC = (g_UA.indexOf("mac")>0);

/***** GENERAL FUNCTIONS *****/
function check3Phone( PhoneField1ID, PhoneField2ID, PhoneField3ID, isRequired, showAlert )
{
	
	if( (document.getElementById(PhoneField1ID)) && (document.getElementById(PhoneField2ID)) && (document.getElementById(PhoneField3ID)) )
	{
		var PhoneField1 = document.getElementById(PhoneField1ID);
		var PhoneField2 = document.getElementById(PhoneField2ID);
		var PhoneField3 = document.getElementById(PhoneField3ID);
		
		if ((PhoneField1.value.length > 0 ) || (PhoneField2.value.length > 0) || (PhoneField3.value.length > 0)) {
			
			if (PhoneField1.value.length < 3 ) {
				if(showAlert)
					alert('This field must be a 3 digit from an U.S. phone number (like 415-555-1212)');
				PhoneField1.focus();
				return false;
			}
			if (PhoneField2.value.length < 3) {
				if(showAlert)
					alert('This field must be a 3 digit from an U.S. phone number (like 415-555-1212)');
				PhoneField2.focus();
				return false;
			}
			if (PhoneField3.value.length < 4) {
				if(showAlert)
					alert('This field must be a 4 digit from an U.S. phone number (like 415-555-1212)');
				PhoneField3.focus();
				return false;
			}
		}
		else
		{
			if ( isRequired ) 
			{
				if(showAlert)
					alert("Please enter Phone ");
				PhoneField1.focus();
				return false;
			}
		}
	}
	else
	{
		alert("No Phone field present on this form");
	    return false;
	}
	
	return true;
}
function validateUSPhone( strValue ) 
{
	if((isPhone(strValue)) || (isPhone2Format(strValue))){
		return true;
	}
	else{
		return false;
	}
}
function isEmail(str)
{
	var tmp = str + "";
	if(tmp!="")
	{		
		var exclude=/[^@\-\.\[A-Za-z0-9]]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;				
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,5}$/;

		if(((tmp.search(exclude) != -1)||(tmp.search(check)) == -1)||(tmp.search(checkend) == -1))
			return false;	
	}
	return true;	
}

function isPhone(str) //format: NNN-NNN-NNNN
{
	if (str.length != 12)     
	{		
		return false;
	}		
	
	for (var i=0; i<12; i++)
	{
		if ((i == 3 || i == 7) && str.charAt(i) != "-")
		{
			return false;
		}
		if (i!=3 && i!=7 && parseInt(str.charAt(i)) != str.charAt(i))
		{				
			return false;
		}		
	}
	
	return true;                     
}

function isPhone2Format(str) //format: (NNN) NNN-NNNN
{
	return /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/.test(str);                   
}

function isZip (str) // format NNNNN or NNNNN-NNNN
{
	if (str.length!=5 && str.length!=10)
	{	
		return false;
	}
		
	for (var i=0; i < str.length; i++) 
	{
		if(str.length == 5 && parseInt(str.charAt(i)) != str.charAt(i))
		{
			return false;
		}
		if(str.length == 10 && str.charAt(5) != "-")
		{
			return false;
		}			
		if(str.length == 10 && (i != 5 && parseInt(str.charAt(i)) != str.charAt(i)))		
		{		
			return false;
		}
	}

	return true;
}
function StripSpaces(sValue)
{
	return sValue.replace((/\s/g), ""); 
}

function doAssociateObjects( oSource, oTarget, bAssociate )
{
	if(bAssociate)
		oTarget.value = oSource.value;
}

function doClearObject(obj, clearvalue)
{
	obj.value = clearvalue;
}
function isEmpty(str)
{		
	if(g_IE)
	{		
		if(str=="")
			return true;
		var re = /(\S+)/gi;
		var t = re.test(str);
		return !t;
	}
	else
	{		
		if(str=="")	
			return true;
		return false;
	}
}

function changeClass(Elem, myClass) 
{
	return true; // disable css class change
	if(document.getElementById(Elem))
		document.getElementById(Elem).className = myClass;
}
function isInteger( strValue ) {
	var objRegExp  = /(^-?\d\d*$)/;
	return objRegExp.test(strValue);
}
function clearChars( oCtrl ) {
	oCtrl.value = oCtrl.value.replace(/\D/g,'');
}
/* FORM RELATED */
function checkCashDonation()
{
	var IsValid = false;
	
	IsValid = IsValid || ((document.getElementById('chkVM'))? document.getElementById('chkVM').checked : false);
	IsValid = IsValid || ((document.getElementById('chkTRG'))? document.getElementById('chkTRG').checked : false);
	IsValid = IsValid || ((document.getElementById('chkNL'))? document.getElementById('chkNL').checked : false);
	IsValid = IsValid || ((document.getElementById('chkHDR'))? document.getElementById('chkHDR').checked : false);
	IsValid = IsValid || ((document.getElementById('chkGCC'))? document.getElementById('chkGCC').checked : false);
	
	if(!IsValid)
	{
		alert("Please select at least one prize to win!");
	}
	
	return IsValid;
}
function checkIfPrizeSelected()
{
	var IsValid = false;
	
	IsValid = IsValid || ((document.getElementById('chkVM'))? document.getElementById('chkVM').checked : false);
	IsValid = IsValid || ((document.getElementById('chkTRG'))? document.getElementById('chkTRG').checked : false);
	IsValid = IsValid || ((document.getElementById('chkNL'))? document.getElementById('chkNL').checked : false);
	IsValid = IsValid || ((document.getElementById('chkHDR'))? document.getElementById('chkHDR').checked : false);
	IsValid = IsValid || ((document.getElementById('chkGCC'))? document.getElementById('chkGCC').checked : false);
	
	return IsValid;
}
function noPrizeSelected()
{
	var Count = 0;
	
	Count = Count + ((document.getElementById('chkVM'))		? ((document.getElementById('chkVM').checked)?1:0) : 0);
	Count = Count + ((document.getElementById('chkTRG'))	? ((document.getElementById('chkTRG').checked)?1:0) : 0);
	Count = Count + ((document.getElementById('chkNL'))		? ((document.getElementById('chkNL').checked)?1:0) : 0);
	Count = Count + ((document.getElementById('chkHDR'))	? ((document.getElementById('chkHDR').checked)?1:0) : 0);
	Count = Count + ((document.getElementById('chkGCC'))	? ((document.getElementById('chkGCC').checked)?1:0) : 0);
	
	return Count;
}
function CheckSameAsBill ( oChkSame ){
	var objForm = document.forms.frmOnlineDonation;
	if( oChkSame.checked ){
		
		if (!isEmpty(objForm.txtDonorFirstName))
		{
			doAssociateObjects ( objForm.txtDonorFirstName, objForm.txtBillingFirstName, true );
			checkRequired ( objForm.txtDonorFirstName );
			checkRequired ( objForm.txtBillingFirstName );
		}
			
		if (!isEmpty(objForm.txtDonorLastName))
		{
			doAssociateObjects( objForm.txtDonorLastName, objForm.txtBillingLastName, true);
			checkRequired ( objForm.txtDonorLastName );
			checkRequired ( objForm.txtBillingLastName );
		}
			
		if (!isEmpty(objForm.txtDonorAddress1))
		{
			doAssociateObjects( objForm.txtDonorAddress1, objForm.txtBillingAddress1, true);
			checkRequired ( objForm.txtDonorAddress1 );
			checkRequired ( objForm.txtBillingAddress1 );
		}
		
		if (!isEmpty(objForm.txtDonorAddress2))
		{
			doAssociateObjects( objForm.txtDonorAddress2, objForm.txtBillingAddress2, true);
		}
		
		if (!isEmpty(objForm.selDonorState))
		{
			doAssociateObjects( objForm.selDonorState, objForm.selBillingState, true);
			checkRequired ( objForm.selDonorState );
			checkRequired ( objForm.selBillingState );
		}
		
		if (!isEmpty(objForm.txtDonorCity))
		{
			doAssociateObjects( objForm.txtDonorCity, objForm.txtBillingCity, true );
			checkRequired ( objForm.txtDonorCity );
			checkRequired ( objForm.txtBillingCity );
		}
		
		if (!isEmpty(objForm.txtDonorZip))
		{
			doAssociateObjects( objForm.txtDonorZip, objForm.txtBillingZip, true );
			checkRequired ( objForm.txtDonorZip );
			checkRequired ( objForm.txtBillingZip );
		}
		
		if ((!isEmpty(objForm.txtDonorPhone1))&&(!isEmpty(objForm.txtDonorPhone2))&&(!isEmpty(objForm.txtDonorPhone3)))
		{
			doAssociateObjects( objForm.txtDonorPhone1, objForm.txtBillingPhone1, true );
			doAssociateObjects( objForm.txtDonorPhone2, objForm.txtBillingPhone2, true );
			doAssociateObjects( objForm.txtDonorPhone3, objForm.txtBillingPhone3, true );
			checkRequired ( objForm.txtDonorPhone1 );
			checkRequired ( objForm.txtBillingPhone1);
			checkRequired ( objForm.txtDonorPhone2 );
			checkRequired ( objForm.txtBillingPhone2);
			checkRequired ( objForm.txtDonorPhone3 );
			checkRequired ( objForm.txtBillingPhone3);
		}
	}
	else{
		/*doClearObject(objForm.txtBillingAddress1, "");
		doClearObject(objForm.txtBillingAddress2, "");
		doClearObject(objForm.selBillingState, 0);
		doClearObject(objForm.txtBillingCity, "");
		doClearObject(objForm.txtBillingZip, "");*/
	}
}

function doCheckCountry( oCountrySource, oStateTarget )
{
	if ( oCountrySource.value != "UNITED STATES" ) {
		oStateTarget.value = "N/A";
	}
	else
	{
		if (oStateTarget.value == "N/A")
			oStateTarget.value = "Texas";
	}
}

function doCheckUSState( oStateSource, oCountryTarget )
{
	if ( oStateSource.value != "N/A" ) {
		oCountryTarget.value = "UNITED STATES";
	}
}

function checkLimit(iLimit, LimitedAreaID, CounterID, showAlert) {
	var oCounter = document.getElementById(CounterID);
	var oText = document.getElementById(LimitedAreaID);
	var prevCounter = iLimit - oCounter.value;
	oCounter.value = iLimit - oText.value.length;
	if(oCounter.value < 0){
		oCounter.value=0;
		if(showAlert){
			alert('The limit of ' + iLimit + ' characters is exceeded!');
		}
		oText.value = oText.value.substring(0,iLimit);
		return false;
	}
	return true;
}

function checkRequired( objCurrent )
{
	if(!isEmpty(objCurrent.value))
	{
		changeClass(objCurrent.id,'formField');
	}
	else
	{
		changeClass(objCurrent.id,'errformField');
	}
}
function checkRequiredSelect( objCurrent )
{
	if(objCurrent.value != "0")
	{
		changeClass(objCurrent.id,'formField');
	}
	else
	{
		changeClass(objCurrent.id,'errformField');
	}
}
function doSincroRequired( objAssociated, isAssociated )
{
	if ( isAssociated )
	{
		checkRequired(objAssociated);
	}
}
function doSincroReset( objAssociated, isAssociated, isAssocieatedRequired )
{
	if ( isAssociated )
	{
		resetCSS ( objAssociated ) ;
		
		if ( isAssocieatedRequired ) 
			checkRequired ( objAssociated );
	}
}
function checkRequiredMoney( objCurrent )
{
	if((!isEmpty(objCurrent.value)) && (objCurrent.value!="$0.00"))
	{
		changeClass(objCurrent.id,'formField');
	}
	else
	{
		changeClass(objCurrent.id,'errformField');
	}
}
function resetCSS( objCurrent )
{
	changeClass(objCurrent.id,'formField');
}
function resetCSSObj( objCurrentID )
{
	if(document.getElementById(objCurrentID))
		changeClass(document.getElementById(objCurrentID).id,'formField');
}
function doValidateForm()
{
	
	var objForm = document.forms.frmOnlineDonation;
	var objCurrent;
	var isValid = true;
	var AlertMessage = "";
	var FirstErrField;
	
	/* AMOUNT */
	objCurrent = objForm.txtDonationAmount;
	if((isEmpty(objCurrent.value)) || (objCurrent.value=="$0.00"))
	{
		changeClass('txtDonationAmount','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donation amount.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	var amount = (objCurrent.value.indexOf('$')>-1)? objCurrent.value.substr(1,objCurrent.value.length-1):objCurrent.value ;
	amount = amount.replace(/,/g,'');
	var noPrizes = noPrizeSelected();
	if(checkIfPrizeSelected())
	{
		if (parseFloat(amount)<parseFloat(1))
		{
			changeClass('txtDonationAmount','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Smallest donation amount is $1.00!";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
		
		if (parseFloat(amount)<parseFloat(noPrizes*50))
		{
			changeClass('txtDonationAmount','errformField');
			if ( isValid ) 
			{
				AlertMessage = "You have selected " + noPrizes + " prizes!";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	else
	{
		if (parseFloat(amount)<parseFloat(1))
		{
			changeClass('txtDonationAmount','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Smallest donation amount is $1.00!";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	
	/* DONOR */
	objCurrent = objForm.txtDonorFirstName;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorFirstName','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor first name.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorLastName;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorLastName','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor last name.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorAddress1;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorAddress1','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor address.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorCity;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorCity','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor city.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorZip;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorZip','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor zip/postal code.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	else
	{
		if(!isZip(objCurrent.value))
		{
			changeClass('txtDonorZip','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter a valid zip code.";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	
	objCurrent = objForm.txtDonorEmail;
	objCurrent.value = StripSpaces(objCurrent.value);
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorEmail','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor email address.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	if(!isEmail(objCurrent.value)) 
	{
		changeClass('txtDonorEmail','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter a valid email address.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorPhone1;
	/*if((isEmpty(objCurrent.value))&&(isEmpty(objForm.txtDonorPhone2.value))&&(isEmpty(objForm.txtDonorPhone3.value)))
	{
	}
	else
	{
		if (!check3Phone( 'txtDonorPhone1', 'txtDonorPhone2', 'txtDonorPhone3', false, false )) 
		{
			changeClass('txtDonorPhone1','errformField');
			changeClass('txtDonorPhone2','errformField');
			changeClass('txtDonorPhone3','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter a valid phone number. (e.g. 555-555-5555)";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}*/
	
	if(((!isEmpty(objCurrent.value))&&(!isEmpty(objForm.txtDonorPhone2.value))&&(!isEmpty(objForm.txtDonorPhone3.value))))
	{
		if (!check3Phone( 'txtDonorPhone1', 'txtDonorPhone2', 'txtDonorPhone3', true, false )) 
		{
			changeClass('txtDonorPhone1','errformField');
			changeClass('txtDonorPhone2','errformField');
			changeClass('txtDonorPhone3','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter a valid phone number. (e.g. 555-555-5555)";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	else
	{
		changeClass('txtDonorPhone1','errformField');
		changeClass('txtDonorPhone2','errformField');
		changeClass('txtDonorPhone3','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor phone number.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	
	
	/* BILLING */
	objCurrent = objForm.txtBillingFirstName;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingFirstName','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing first name.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtBillingLastName;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingLastName','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing last name.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.selBillingCountry;
	if(objCurrent.value == "0")
	{
		changeClass('selBillingCountry','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing country.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtBillingAddress1;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingAddress1','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing address.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtBillingCity;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingCity','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing city.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtBillingZip;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingZip','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing zip/postal code.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	else
	{
		if((!isZip(objCurrent.value)) && (objForm.selBillingCountry.value == "UNITED STATES"))
		{
			changeClass('txtBillingZip','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter a valid zip code.";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	
	
	objCurrent = objForm.txtBillingPhone1;
	if(objForm.selBillingCountry.value == "UNITED STATES"){
		if(((!isEmpty(objCurrent.value))&&(!isEmpty(objForm.txtBillingPhone2.value))&&(!isEmpty(objForm.txtBillingPhone3.value))))
		{
			if (!check3Phone( 'txtBillingPhone1', 'txtBillingPhone2', 'txtBillingPhone3', true, false )) 
			{
				changeClass('txtBillingPhone1','errformField');
				changeClass('txtBillingPhone2','errformField');
				changeClass('txtBillingPhone3','errformField');
				if ( isValid ) 
				{
					AlertMessage = "Please, enter a valid phone number. (e.g. 555-555-5555)";
					FirstErrField = objCurrent;
				}
				isValid = false;
			}
		}
		else
		{
			changeClass('txtBillingPhone1','errformField');
			changeClass('txtBillingPhone2','errformField');
			changeClass('txtBillingPhone3','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter billing phone number.";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	
	// general err mgmt
	if ( !isValid ) 
	{
		objForm.hidAction.value = "";
		if(FirstErrField) FirstErrField.focus();
		alert('' + AlertMessage + '');
	}
	else
	{
		var message="";
		if (parseFloat(amount)>=parseFloat((noPrizes*50)+50))
		{
			message = "For this donation amount ($" + amount + ") you can choose to participate at " + ((parseInt((amount/50),10)>5)?5:parseInt((amount/50),10))  + " contests! \nClick \"Cancel\" and go select the prizes you like! Or click \"OK\" to continue the payment process!\n\n";
		}
		if(confirm(message + "This will start Secure Payment process. Please make sure that the billing information is accurate.\n\rContinue?")){
			objForm.btnSubmit.value = "Please Wait...";
			//objForm.btnSubmit.disabled = true;
			objForm.hidAction.value = "send";
		}
		else
		{
			isValid = false;
		}
	}
	return isValid; 	
}


function reqMediaAjax()
{	
	var sZIP = donFormAjax.Zip.value;
	
	if (isValidZIP(sZIP))
	{
		if(sZIP != tmpZIPAjax)
		{
			tmpZIPAjax = sZIP; 
			getDonorMedia(sZIP);
		}
	}
	else 
	{
		if(tmpZIPAjax != "") 
		{
			tmpZIPAjax = ""
			getDonorMedia(sZIP);
		}
	}
	
}


function setRecDonAmount()
{
	var objForm = document.forms.frmOnlineDonation;
	var amount;
	
	if(objForm.chkRecurringDonation.checked)
	{
		if((objForm.txtRecurringDonationAmount.value == '$0.00' 
			|| objForm.txtRecurringDonationAmount.value == '') 
			&& objForm.txtDonationAmount.value != '$0.00'
			&& objForm.txtDonationAmount.value != '' 
			)
		{
			amount = (objForm.txtDonationAmount.value.indexOf('$')>-1) ? objForm.txtDonationAmount.value.substr(1,objForm.txtDonationAmount.value.length-1) : objForm.txtDonationAmount.value ;
			amount = amount.replace(/,/g,'');
			if (parseFloat(amount) >= parseFloat(1))
					objForm.txtRecurringDonationAmount.value = objForm.txtDonationAmount.value;
		}
	}
	else
	{
		objForm.txtRecurringDonationAmount.value = '';
		objForm.txtRecurringDonationNumber.value = '';
	}
}


function doValidateMoneyForm()
{
	
	var objForm = document.forms.frmOnlineDonation;
	var objCurrent;
	var isValid = true;
	var AlertMessage = "";
	var FirstErrField;
	
	/* AMOUNT */
	objCurrent = objForm.txtDonationAmount;
	if((isEmpty(objCurrent.value)) || (objCurrent.value=="$0.00"))
	{
		changeClass('txtDonationAmount','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donation amount.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	var amount = (objCurrent.value.indexOf('$')>-1)? objCurrent.value.substr(1,objCurrent.value.length-1):objCurrent.value ;
	amount = amount.replace(/,/g,'');
	
	if (parseFloat(amount)<parseFloat(1))
	{
		changeClass('txtDonationAmount','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Smallest donation amount is $1.00!";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	
	/* RECURRING DONATION AMOUNT */
	objCurrent = objForm.txtRecurringDonationAmount;
	
	if((isEmpty(objCurrent.value) || objCurrent.value == "$0.00") && objForm.chkRecurringDonation.checked)
	{
		changeClass('txtRecurringDonationAmount','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter recurring donation amount!";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	else if(objForm.chkRecurringDonation.checked)
	{
		amount = (objCurrent.value.indexOf('$')>-1)? objCurrent.value.substr(1,objCurrent.value.length-1):objCurrent.value ;
		amount = amount.replace(/,/g,'');
		
		if (parseFloat(amount)<parseFloat(1))
		{
			changeClass('txtRecurringDonationAmount','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Smallest recurring donation amount is $1.00!";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
		else
		{
			changeClass('txtRecurringDonationAmount','formField');
		}
	}
	
	/* RECURRING DONATION NUMBER */
	objCurrent = objForm.txtRecurringDonationNumber;
	
	if((isEmpty(objCurrent.value) || objCurrent.value == "0") && objForm.chkRecurringDonation.checked)
	{
		changeClass('txtRecurringDonationNumber','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter number of transactions!";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	else if(objForm.chkRecurringDonation.checked)
	{
		amount = parseInt(objCurrent.value);

		if(isNaN(amount) || amount.toString() != objCurrent.value.toString() || amount < 1) 
		{
			changeClass('txtRecurringDonationNumber','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter positive numbers only!";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
		else
		{
			changeClass('txtRecurringDonationNumber','formField');
		}
	}
	
	
	/* RECURRING DONATION BUTTON */
	objCurrent = objForm.chkRecurringDonation;
	
	if(!objForm.chkRecurringDonation.checked && ((!isEmpty(objForm.txtRecurringDonationAmount.value) && objForm.txtRecurringDonationAmount.value != "$0.00") || (!isEmpty(objForm.txtRecurringDonationNumber.value) && objForm.txtRecurringDonationNumber.value != 0)))
	{
		if ( isValid ) 
		{
			AlertMessage = "Please, check recurring donation button!";
			FirstErrField = objCurrent;
			isValid = false;
		}
	}
	
	
	
	/* DONOR */
	objCurrent = objForm.txtDonorFirstName;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorFirstName','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor first name.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorLastName;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorLastName','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor last name.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorAddress1;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorAddress1','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor address.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorCity;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorCity','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor city.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorZip;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorZip','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor zip/postal code.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	else
	{
		if(!isZip(objCurrent.value))
		{
			changeClass('txtDonorZip','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter a valid zip code.";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	
	objCurrent = objForm.txtDonorEmail;
	objCurrent.value = StripSpaces(objCurrent.value);
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtDonorEmail','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor email address.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	if(!isEmail(objCurrent.value)) 
	{
		changeClass('txtDonorEmail','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter a valid email address.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtDonorPhone1;
	if(((!isEmpty(objCurrent.value))&&(!isEmpty(objForm.txtDonorPhone2.value))&&(!isEmpty(objForm.txtDonorPhone3.value))))
	{
		if (!check3Phone( 'txtDonorPhone1', 'txtDonorPhone2', 'txtDonorPhone3', true, false )) 
		{
			changeClass('txtDonorPhone1','errformField');
			changeClass('txtDonorPhone2','errformField');
			changeClass('txtDonorPhone3','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter a valid phone number. (e.g. 555-555-5555)";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	else
	{
		changeClass('txtDonorPhone1','errformField');
		changeClass('txtDonorPhone2','errformField');
		changeClass('txtDonorPhone3','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter donor phone number.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	
	
	/* BILLING */
	objCurrent = objForm.txtBillingFirstName;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingFirstName','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing first name.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtBillingLastName;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingLastName','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing last name.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.selBillingCountry;
	if(objCurrent.value == "0")
	{
		changeClass('selBillingCountry','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing country.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtBillingAddress1;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingAddress1','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing address.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtBillingCity;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingCity','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing city.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	objCurrent = objForm.txtBillingZip;
	if(isEmpty(objCurrent.value))
	{
		changeClass('txtBillingZip','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, enter billing zip/postal code.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	else
	{
		if((!isZip(objCurrent.value)) && (objForm.selBillingCountry.value == "UNITED STATES"))
		{
			changeClass('txtBillingZip','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter a valid zip code.";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	
	
	objCurrent = objForm.txtBillingPhone1;
	if(objForm.selBillingCountry.value == "UNITED STATES"){
		if(((!isEmpty(objCurrent.value))&&(!isEmpty(objForm.txtBillingPhone2.value))&&(!isEmpty(objForm.txtBillingPhone3.value))))
		{
			if (!check3Phone( 'txtBillingPhone1', 'txtBillingPhone2', 'txtBillingPhone3', true, false )) 
			{
				changeClass('txtBillingPhone1','errformField');
				changeClass('txtBillingPhone2','errformField');
				changeClass('txtBillingPhone3','errformField');
				if ( isValid ) 
				{
					AlertMessage = "Please, enter a valid phone number. (e.g. 555-555-5555)";
					FirstErrField = objCurrent;
				}
				isValid = false;
			}
		}
		else
		{
			changeClass('txtBillingPhone1','errformField');
			changeClass('txtBillingPhone2','errformField');
			changeClass('txtBillingPhone3','errformField');
			if ( isValid ) 
			{
				AlertMessage = "Please, enter billing phone number.";
				FirstErrField = objCurrent;
			}
			isValid = false;
		}
	}
	
	
	// Schools List drop down
	objCurrent = objForm.selDonationBenefit;
	if(isEmpty(objCurrent.value))
	{
		changeClass('selDonationBenefit','errformField');
		if ( isValid ) 
		{
			AlertMessage = "Please, select which campus/program\nwould you like your donation to benefit.";
			FirstErrField = objCurrent;
		}
		isValid = false;
	}
	
	
	// general err mgmt
	if ( !isValid ) 
	{
		objForm.hidAction.value = "";
		if(FirstErrField) FirstErrField.focus();
		if(AlertMessage) alert('' + AlertMessage + '');
	}
	else
	{
		var message="";
		if(confirm(message + "This will start Secure Payment process. Please make sure that the billing information is accurate.\n\rContinue?")){
			objForm.btnSubmit.value = "Please Wait...";
			objForm.hidAction.value = "send";
		}
		else
		{
			isValid = false;
		}
	}
	return isValid; 	
}


function autoNumber(CtrlID) 
{			
	var oCtrl = eval("document.forms.frmOnlineDonation." + CtrlID);
	if(oCtrl){
		if(oCtrl.value.length > 0){
			oCtrl.value = oCtrl.value.replace(/-/,"");
		}
		
		var num = new NumberFormat();
		num.setInputDecimal('.');
		num.setNumber(oCtrl.value);
		num.setPlaces('2', false);
		num.setCurrencyValue('$');
		num.setCurrency(true);
		num.setCurrencyPosition(num.LEFT_OUTSIDE);
		num.setNegativeFormat(num.LEFT_DASH);
		num.setNegativeRed(false);
		num.setSeparators(true, ',', ',');
		oCtrl.value = num.toFormatted();
	}
}

function autoInt(CtrlID) 
{			
	var oCtrl = eval("document.forms.frmOnlineDonation." + CtrlID);
	if(oCtrl){
		if(oCtrl.value.length > 0){
			oCtrl.value = oCtrl.value.replace(/-/,"");
		}
		
		var num = new NumberFormat();
		num.setInputDecimal('.');
		num.setNumber(oCtrl.value);
		num.setPlaces('0', true);
		num.setCurrencyValue('$');
		num.setCurrency(false);
		num.setCurrencyPosition(num.LEFT_OUTSIDE);
		num.setNegativeFormat(num.LEFT_DASH);
		num.setNegativeRed(false);
		num.setSeparators(false, ',', ',');
		oCtrl.value = num.toFormatted();
	}
}

function selectCheckBox(chkID, Value)
{
	if(document.getElementById(chkID))
		document.getElementById(chkID).checked = (Value=="1")?true :false;
}
function setInitialSum()
{
	if(document.getElementById('txtDonationAmount'))
	{
		objCurrent = document.getElementById('txtDonationAmount');
		var CurrentValue = (objCurrent.value.indexOf('$')>-1)? objCurrent.value.substr(1,objCurrent.value.length-1):objCurrent.value;
		CurrentValue = (isEmpty(CurrentValue))? "0": CurrentValue;
		var noPrizes = noPrizeSelected();
		
		if (parseFloat(CurrentValue) < parseFloat(noPrizes*50))
		{	
			var num = new NumberFormat();
			num.setInputDecimal('.');
			num.setNumber(noPrizes*50);
			num.setPlaces('2', false);
			num.setCurrencyValue('$');
			num.setCurrency(true);
			num.setCurrencyPosition(num.LEFT_OUTSIDE);
			num.setNegativeFormat(num.LEFT_DASH);
			num.setNegativeRed(false);
			num.setSeparators(true, ',', ',');
			document.getElementById('txtDonationAmount').value = num.toFormatted();
		}
		if (parseFloat(CurrentValue) == 0)
		{
		var num = new NumberFormat();
			num.setInputDecimal('.');
			num.setNumber(50);
			num.setPlaces('2', false);
			num.setCurrencyValue('$');
			num.setCurrency(true);
			num.setCurrencyPosition(num.LEFT_OUTSIDE);
			num.setNegativeFormat(num.LEFT_DASH);
			num.setNegativeRed(false);
			num.setSeparators(true, ',', ',');
			document.getElementById('txtDonationAmount').value = num.toFormatted();
		}
	}
}
function setInitialAmount(IniSum)
{
	if(document.getElementById('txtDonationAmount'))
	{
		objCurrent = document.getElementById('txtDonationAmount');
		var CurrentValue = (objCurrent.value.indexOf('$')>-1)? objCurrent.value.substr(1,objCurrent.value.length-1):objCurrent.value;
		CurrentValue = (isEmpty(CurrentValue))? "0": CurrentValue;
		var num = new NumberFormat();
			num.setInputDecimal('.');
			num.setNumber(IniSum);
			num.setPlaces('2', false);
			num.setCurrencyValue('$');
			num.setCurrency(true);
			num.setCurrencyPosition(num.LEFT_OUTSIDE);
			num.setNegativeFormat(num.LEFT_DASH);
			num.setNegativeRed(false);
			num.setSeparators(true, ',', ',');
			document.getElementById('txtDonationAmount').value = num.toFormatted();
	}
}

