/////////////////////////////////////////////////////////////////////

// 

// Function discriptions

// fieldname(name) - field name is function used for the name of the field which goes to 

// validation should be respectd name which is used in html page or these separte page  their used javascript

//

/////////////////////////////////////////////////////////////////////////



function Mod10(ccNumb) {  // v2.0

var valid = "0123456789"  // Valid digits in a credit card number

var len = ccNumb.length;  // The length of the submitted cc number

var iCCN = parseInt(ccNumb);  // integer of ccNumb

var sCCN = ccNumb.toString();  // string of ccNumb

sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces

var iTotal = 0;  // integer total set at zero

var bNum = true;  // by default assume it is a number

var bResult = false;  // by default assume it is NOT a valid cc

var temp;  // temp variable for parsing string

var calc;  // used for calculation of each digit



// Determine if the ccNumb is in fact all numbers

for (var j=0; j<len; j++) {

  temp = "" + sCCN.substring(j, j+1);

  if (valid.indexOf(temp) == "-1"){bNum = false;}

}



// if it is NOT a number, you can either alert to the fact, or just pass a failure

if(!bNum){

  /*alert("Not a Number");*/bResult = false;

}



// Determine if it is the proper length 

if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check

  bResult = false;

} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number

  if(len >= 15){  // 15 or 16 for Amex or V/MC

    for(var i=len;i>0;i--){  // LOOP throught the digits of the card

      calc = parseInt(iCCN) % 10;  // right most digit

      calc = parseInt(calc);  // assure it is an integer

      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit

      i--;  // decrement the count - move to the next digit in the card

      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb

      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit

      calc = calc *2;                                 // multiply the digit by two

      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,

      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.

      switch(calc){

        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1

        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3

        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5

        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7

        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9

        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers

      }                                               

    iCCN = iCCN / 10;  // subtracts right most digit from ccNum

    iTotal += calc;  // running total of the card number as we loop

  }  // END OF LOOP

  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero

    bResult = true;  // This IS (or could be) a valid credit card number.

  } else {

    bResult = false;  // This could NOT be a valid credit card number

    }

  }

}

// change alert to on-page display or other indication as needed.

return bResult;

}





function isEmpty( str)

{

    strRE = new RegExp( );

    strRE.compile( '^[\s ]*$', 'gi' );

    return strRE.test( str.value );

}

function findfield(field){

	

	switch(field)

	{

		case "txt_news":

		return "News Title";

		break;

		

		case "txt_newsdetails":

		return "News Details";

		break;



		case "txt_subject":

		return "Subject of New registration";

		break;		

		

		case "txt_plandetails":

		return "Plan Details";

		break;



		case "txt_plan":

		return "Plan";

		break;



		case "txt_message":

		return "Message";

		break;



		case "txt_fname":

		case "txt_cfname":

		return "First name";

		break;



		case "txt_lname":

		case "txt_clname":

		return "Last name";

		break;

		

		case "txt_cno":

		return "Credit Card";

		break;



		case "txt_SecurityCode":

		return "Security Code";

		break;

		

		case "txt_initial":

		return "Initial";

		break;





		case "txt_company":

		return "Company name";

		break;



		case "txt_address":

		return "Address";

		break;



		case "txt_address1":

		return "Address 1";

		break;



		case "txt_family":

		return "Family name";

		break;



		case "txt_init_invest":

		return "Initial Investiment";

		break;



		case "txt_project_ern":

		return "Project earning";

		break;



		case "txt_clientnote":

		return "Client Note";

		break;



		case "txt_suburb":

		return "Suburb";

		break;



		case "txt_city":

		return "City";

		break;



		case "txt_state":

		return "State";

		break;



		case "txt_postcode":

		return "Post code";

		break;



		

		case "txt_telephone":

		return "TelePhone Number";

		break;



		case "txt_mobile":

		case "txt_mobno":

		return "Mobile Number";

		break;



		case "txt_dorm":

		return "Dorm";

		break;





		case "txt_fax":

		return "Fax Number";

		break;



		case "txt_uname":

		return "User name";

		break;



		case "txt_password":

		return "Password";

		break;

		case "txt_cpassword":

		return "Confirm Password";

		break;



		case "txt_zipcode":

		return "Zip Code";

		break;



		case "txt_email":

		return "Email id";

		break;		



		case "email_address":

		return "Email Address";

		break;



		default:

		return field;

		break;

	}

}



function isLetter(c)

  {

	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")));

  }



function ValidateEmail(val)

	{

    var id=val;

	var at=id.indexOf('@');

	var lastat=id.lastIndexOf('@');

	var dot=id.indexOf('.');

	lastdot=id.lastIndexOf('.')

	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.length-1)) && (at == lastat) ) )

	{

	  error = 1;

	  return (false);

	}

	var str_referral=id.length;

	var ch_referral=id;

	for(i=0;i<str_referral;i++)

	{

		ch_referral1=ch_referral.substring(i,i+1);



		if(ch_referral1==" ")

		{			

			return (false);

		}

	}

}





function isValidFile(file) 

{



	var extArray = new Array(".gif", ".jpg",".jpeg");

	var allowSubmit = false;

	var ext 

	while (file.indexOf("\\") != -1)

	{

		file = file.slice(file.indexOf("\\") + 1);

	}

	ext = file.slice(file.indexOf(".")).toLowerCase();

	for (var i = 0; i < extArray.length; i++) 

	{

		if (extArray[i] == ext) 

		{ 

			allowSubmit = true; 

			break; 

		}

	}



	if (allowSubmit)

	{ 

		return true;

	}

	else

	{

		return false;

	}

}



function isValidFileXls(file) 

{



	var extArray = new Array(".xls",".doc",".csv");

	var allowSubmit = false;

	var ext 

	while (file.indexOf("\\") != -1)

	{

		file = file.slice(file.indexOf("\\") + 1);

	}

	ext = file.slice(file.indexOf(".")).toLowerCase();

	for (var i = 0; i < extArray.length; i++) 

	{

		if (extArray[i] == ext) 

		{ 

			allowSubmit = true; 

			break; 

		}

	}



	if (allowSubmit)

	{ 

		return true;

	}

	else

	{

		return false;

	}

}





function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}





function MM_validateForm() { //v4.0

  var i,p,q,nm,test,num,min,max,errors='',args = MM_validateForm.arguments;

  for (i=0; i<(args.length-1); i+=2) { test=args[i+1];

  val=MM_findObj(args[i]); 



	if (val) { nm=findfield(val.name); if ((v =val.value)!="") {

	//email validation

      if (test.indexOf('isEmail')!=-1)

	  {

		  if(ValidateEmail(v)==false) 

		  {

			errors ='- '+nm+' must contain an e-mail address.\n';			

		  }

      }

	  else if (test.indexOf('isImage')!=-1)//image validation

	  {

		  if (!isValidFile(v))	  

		  {

			 errors='- '+nm+' type must be gif, jpg or jpeg.\n';

			 

		  }

	  }

	  else if (test.indexOf('isXls')!=-1)//image validation

	  {

		  if (!isValidFileXls(v)) 

			{

				errors ='- '+nm+' type must be xls.\n';			

			} 

	 }



	   else if (test.indexOf('isAlpha')!=-1)//alphabate validation

		{

		  if (!isLetter(v)) 

		  {

			errors='- '+nm+' must contain a alphabate.\n';			

		  }

		}



	  else if (test!='R') 

	  {

		num = parseFloat(v);

        if (isNaN(v))

		{

			errors='- '+nm+' must contain a number.\n';

			

		}

        if (test.indexOf('inRange') != -1) 

		{

			p=test.indexOf(':');

			min=test.substring(8,p); max=test.substring(p+1);

			 if (num<min || max<num)

			 {

				errors = '- '+nm+' must contain a number between '+min+' and '+max+'.\n';				

			}

    } } } 

		else if (test.charAt(0) == 'R') 

		{

			errors += '- '+nm+' is required.\n';			

		}

	}

  } 

  if (errors) alert('The following error(s) occurred:\n'+errors);

  document.MM_returnValue = (errors == '');

}





//validation - Email - isEmail

//validation - Image - isImage

//validation - alphabate - isAlpha

//validation - Range - inRange

//validation - Numeric - RisNum

//validation - Required - R

//validation - Excle file - RisXls

//validation - Not Required but Numeric - N





function CallPrice(id,actionpage)

{

	if (id == "")

	{	document.forms[0].SchoolCombo.value = 0;

		return false;}	

	if (id !="0" && actionpage !="")

	{

		document.getElementById('loading').style.display="block";

		document.getElementById('school_price').style.display="none";

		$('btn_registrationId').disabled = true;

		urlstr = '&id='+id;	

		var url = actionpage+'?request=Ajax'+urlstr;	

		var pars = '';

		var target = 'school_price';

		var myAjax = new Ajax.Updater(target, url, {method: 'get',parameters: pars,onComplete:showResponse});				

	}

	else

	{	document.getElementById('loading').style.display="none";

		document.getElementById('school_price').style.display="none";

		$('btn_registrationId').disabled = false;

		return false;}

}

function showResponse()

{	document.getElementById('school_price').style.display="block";

	document.getElementById('loading').style.display="none";

	$('btn_registrationId').disabled = false;

}







function CallActionPage(id,actionpage)

{

	window.location = actionpage+"?schid="+id;

}



function Ups_CheckShipping(frm,actionpage)

{

		zip  = frm.txt_zipcode.value;			

		city = frm.txt_city.value;

		state = frm.CmboHomeState.value;

		if (zip =="" || city =="" || state == 0 || state == "0" )

		{

			alert("City, State,Zip should not blank");

			frm.txt_city.focus();

			return false;

		}else

		{		

		$('upsChecked').style.display="block";

		$('btn_registrationId').disabled = true;

		$('upsChecked').innerHTML = "<span style='color:#000000;font-weight:bold' >Please Wait, UPS is verify the address...</span>";		

		urlstr = 'city='+city;	

		urlstr += '&StateCombo='+state;	

		urlstr += '&zip='+zip;

		

		var url = actionpage;	

		var pars = urlstr;				

		var target = 'upsChecked';		

		var myAjax = new Ajax.Updater(target, url, {method: 'get',parameters: pars,onComplete:showUpsResponse,onFailure: reportError});		

		}

}

function trim(str) { if(!str || typeof str != 'string')         return null;     return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); }

	function reportError(request)

	{

		alert('Sorry. There was an error.');

	}

function showUpsResponse(originalRequest)

{

	$('ups').value = trim(originalRequest.responseText);		

	if	($('ups').value != 0 || $('ups').value != "0")

	{

		$('upsChecked').innerHTML = "<span style='color:#FF0000;font-weight:bold' >Error : UPS is not able to verified the address.</span>";

		$('btn_registrationId').disabled = false;	

		return false;

	}else 

	{$('upsChecked').innerHTML = "<span style='color:#FF0000;font-weight:bold' >UPS is verified the address.</span>";

	}

	$('btn_registrationId').disabled = false;	

}







function CheckConfirmFormData(frm)

{

	school = frm.SchoolCombo.value;

	fname  = frm.txt_fname.value;

	lname  = frm.txt_lname.value;

	email = frm.txt_email.value;

	mobno  = frm.txt_mobno.value;

//parent section

pfname  = frm.txt_parentfname.value;

plname  = frm.txt_parentlname.value;

pemail  = frm.txt_parentemail.value;

phphone  = frm.txt_parenthomephone.value;

pcphone  = frm.txt_parentcellphone.value;



//school address



	schooladdress1 = frm.txt_schaddress1.value;

	dorm  = frm.txt_dorm.value;

	dormRoom  = frm.txt_dormRoom.value;

	schoolcity = frm.txt_schcity.value;

	schoolstate = frm.CmboSchState.value;

	schoolzip = frm.txt_schzipcode.value;

	

//home address

	

	homeaddress1  = frm.txt_address1.value;

	homestate = frm.CmboHomeState.value;	

	city = frm.txt_city.value;

	zip  = frm.txt_zipcode.value;

	homenote  = frm.txt_homenote.value;

//	Ups  = frm.txt_Ups.value;



	if (school == "0" || school == 0)

	{

		alert("School Details : Please Select School");

		frm.SchoolCombo.focus();

		return false;

	}

	frm.txt_amt.value = frm.txt_tot.value;

	amt  = frm.txt_amt.value;

	if (amt == "0.00" || amt == "" || amt == "NaN")

	{

		alert("School Details : Please select school Prices");

		frm.txt_additional.focus();

		return false;

	}

	//parent section

if (pfname =="")

	{

		alert("Parent Details: First name should not blank");

		frm.txt_parentfname.focus();

		return false;

	}

	if (plname =="")

	{

		alert("Parent Details: Last name should not blank");

		frm.txt_parentlname.focus();

		return false;

	}

	if (ValidateEmail(pemail) == false)

	{

		alert("Parent Details: Email id must contain an e-mail address");

		frm.txt_parentemail.focus();

		return false;

	}	

	if (pcphone == "")

	{

		alert("Parent Details: Please Corrected the Cell phone number\n");

		frm.txt_parentcellphone.focus();

		return false;

	}

	if (phphone=="")

	{

		alert("Parent Details: Please Corrected the Home phone number\n");

		frm.txt_parenthomephone.focus();

		return false;

	}

	if (fname =="")

	{

		alert("First name should not blank");

		frm.txt_fname.focus();

		return false;

	}

	if (lname =="")

	{

		alert("Last name should not blank");

		frm.txt_lname.focus();

		return false;

	}

	if (ValidateEmail(email) == false)

	{

		alert("Email must contain an e-mail address.");

		frm.txt_email.focus();

		return false;

	}

	if (mobno=="")

	{

		alert("Please Corrected the Mobile number\n");

		frm.txt_mobno.focus();

		return false;

	}

	if (schooladdress1 == "")

	{

		alert("School Details: Address 1 should not blank\n");

		frm.txt_schaddress1.focus();

		return false;

	}

	

	if (schoolcity == "")

	{

		alert("School Details: City should not blank\n");

		frm.txt_schcity.focus();

		return false;

	}

	if (schoolstate == "0" || schoolstate==0)

	{

		alert("School Details: Please Select State .\n");

		frm.CmboSchState.focus();

		return false;

	}

	if (schoolzip == "" )

	{

		alert("School Details: Zip code should not blank\n");

		frm.txt_schzipcode.focus();

		return false;

	}



	if (homeaddress1=="")

	{

		alert("Home Details: First Address should not blank.\n");

		frm.txt_address1.focus();

		return false;

	}

	if (homestate =="0" || homestate == 0)

	{

		alert("Home Details: Please Select State");

		frm.CmboHomeState.focus();

		return false;

	}

	if (city =="")

	{

		alert("Home Details: City should not blank\n");

		frm.txt_city.focus();

		return false;

	}	

	if (zip =="")

	{

		alert("Home Details: Zip Code should not blank\n");

		frm.txt_zipcode.focus();

		return false;

	}

	/*if ($('ups').value !=0 || $('ups').value != "0" )

	{

		alert("UPS is not able to verify the address, please correct the address.\n");	

		return false;

	}	*/

	

}



function CheckPaymentFormData(frm)

{

	cfname = frm.txt_cfname.value;

	clname = frm.txt_clname.value;

	cno  = frm.txt_cno.value;

	SecurityCode = frm.txt_SecurityCode.value;

	Month = frm.MonthCombo.value;

	Year = frm.YearCombo.value;

	shipAddress  = frm.chk_shipAddress.value;

	address  = frm.txt_address.value;

	city  = frm.txt_city.value;

	state = frm.StateCombo.value;	

	Country = frm.CountryCombo.value;	

	zipcode = frm.txt_zipcode.value;

	termCondition = frm.chk_termCondition.value;

	initial = frm.txt_initial.value;

	

	if (cfname =="")

	{

		alert("Cardholder's First name should not blank");

		frm.txt_cfname.focus();

		return false;

	}

	if (clname =="")

	{

		alert("Cardholder's Last name: should not blank");

		frm.txt_clname.focus();

		return false;

	}

	if (Mod10(cno) == false)

	{

		alert("Please Enter the valid Credit Card Number!");

		frm.txt_cno.focus();

		return false;

	}

	if (SecurityCode == "")

	{

		alert("Security Code should not blank");

		frm.txt_SecurityCode.focus();

		return false;

	}

	if (Month == 0 || Month =="0")

	{

		alert("Please Select Months");

		frm.MonthCombo.focus();

		return false;

	}

	if (Year == 0 || Year =="0")

	{

		alert("Please Select Year");

		frm.YearCombo.focus();

		return false;

	}

	if (address =="")

	{

		alert("Address should not blank");

		frm.txt_address.focus();

		return false;

	}

	if (city =="")

	{

		alert("City should not blank");

		frm.txt_city.focus();

		return false;

	}

	if (state == 0 || state =="0")

	{

		alert("Please Select State");

		frm.StateCombo.focus();

		return false;

	}

	if (Country == 0 || Country =="0")

	{

		alert("Please Select Country");

		frm.CountryCombo.focus();

		return false;

	}

	if (zipcode=="")

	{

		alert("Zip code Should not blank");

		frm.txt_zipcode.focus();

		return false;

	}

	if(!frm.chk_termCondition.checked)

	{

		alert("Please Read the guidelines and checked the Terms & Conditions"); 

		frm.chk_termCondition.focus();

		return false;

	}

	if (initial == "")

	{

		alert("Initial should not blank");

		frm.txt_initial.focus();

		return false;

	}

}



function CalculateTotal()

	{

		var Total= 0;

		if (document.getElementById("rd1").checked)

		Total = parseInt(document.getElementById("rd1").value);		

		else if (document.getElementById("rd2").checked)

		Total = parseInt(document.getElementById("rd2").value);		

		

		var boxqty = 0;

		var wardrobqty = 0;

		discount = document.getElementById("discountId").value; 

		boxqty = document.getElementById("txt_additional").value * document.getElementById("hdadditional").value;

		wardrobqty = document.getElementById("txt_wardrobe").value * document.getElementById("hdwardrobe").value;

		

		Total = Total + boxqty + wardrobqty;		

		if ($("discountId").checked)

		{

			AddDiscount = discount/100 ;

			Total = Total*2 - (Total*2)*AddDiscount;

		}

		document.getElementById("tot").value = Total;

	}



function ShippingAddress(frm)

{

		if (frm.chk_shipAddress.checked)

		{

			frm.txt_address.value = frm.hiddenaddress1.value;

			frm.txt_city.value = frm.hiddencity.value;

			frm.StateCombo.value = frm.hiddenstate.value;

			frm.txt_zipcode.value = frm.hiddenzipcode.value;

		}

		else

		{

				frm.txt_address.value = '';

				frm.txt_city.value = '';

				frm.StateCombo.value = 0;

				frm.txt_zipcode.value = '';

		}

		

		return false;

}