// Registration form:

function validatebysani(frm)

{ 

	if(validateemptybysani(frm.txtstuname, 'Student Name', 'text') == false)

	   return false;

	else if(validateemptybysani(frm.txtparentname, 'Parent Name', 'text') == false)

	   		return false;

	else if(validateemptybysani(frm.txtemail, 'Email Address', 'email') == false)

	   		return false;		

    else if(validateemptybysani(frm.txtcountry, 'Country/State', 'number') == false)

	   		return false;   

	else if(validateemptybysani(frm.txtphoneno, 'Phone Number', 'number') == false)

	   		return false;

	else if(validateemptybysani(frm.txtSkype, 'Enter Skype Id', 'text') == false)

	   		return false;

	/*else if(validateemptybysani(frm.txttimetocontact, 'Time to Contact', 'time') == false)

	   		return false;*/

			

	else if(validateemptybysani(frm.txthearabout, 'How did you hear about us?', 'text') == false)

	   		return false;		

	else if(frm.txtcode.value == 'Enter Verification Code' || frm.txtcode.value == '')

		 {

			errorbysani(frm.txtcode);

			return false;

		 }else if(frm.txtcode.value != frm.txtcapcode.value)

				 {

					checkcodebysani(frm.txtcode);

					return false;

				 }

	

}





//Tell a friend

function validatetellafriend(tellfrndfrm)

{

	if(validateemptybysani(tellfrndfrm.txtname, 'name', 'text') == false)

	   		return false;

	else if(validateemptybysani(tellfrndfrm.txtemail, 'email', 'email') == false)

	   		return false;

	

}



//contact us

function validatebyhyne(frm)

{

	if(validateemptybysani(frm.txtname, 'Name', 'text') == false)

	   return false;

	else if(validateemptybysani(frm.txtemail, 'Email Address', 'email') == false)

	   		return false;		

    else if(validateemptybysani(frm.txtsubject, 'Subject', 'text') == false)

	   		return false;   

	else if(validateemptybysani(frm.txtmessage, 'Message', 'text') == false)

	   		return false;

	

	

}

/*****************************************************************************************************/

function validateemptybysani(feild, feildvalue, feildtype)

{ 

	if(feild.value == feildvalue || feild.value == '')

	{

		errorbysani(feild);

		return false;

	}else if(feildtype == 'text')

	        {

				if(textvalidatebysani(feild)==false)

	       		   return false;

			}else if(feildtype == 'number')

					{

						if(numbervalidatebysani(feild)==false)

	       		  		  return false;	

					}else if(feildtype == 'email')

							{

								if(emailbysani(feild)==false)

								  return false;	

							}else if(feildtype == 'time')

									{

										if(validatetime(feild)==false)

										  return false;	

									}

	

}



function textvalidatebysani(feildname)

{ 

	var numericExpression = /^[0-9]+$/;

	if(feildname.value.match(numericExpression))

	{

		feildname.style.background = '#ffc2c2';

		feildname.style.color	   = '#000000';

		feildname.style.fontSize   = '10px';

		feildname.value			   = 'Please Enter String Only';

		return false;

	}

}



function numbervalidatebysani(feildname)

{ 

	var numericExpression = /^[0-9]+$/;

	if(!(feildname.value.match(numericExpression)))

	{

		feildname.style.background = '#ffc2c2';

		feildname.style.color	   = '#000000';

		feildname.style.fontSize   = '10px';

		feildname.value			   = 'Please Enter Digits Only';

		return false;

	}

}



function errorbysani(feildname)

{ 

	feildname.style.background = '#ffc2c2';

	feildname.style.color	   = '#000000';

	feildname.style.fontSize   = '10px';

	feildname.value			   = 'Please Enter '+feildname.value+'...';

}



function checkcodebysani(code)

{

	code.style.background  									= '#ffc2c2';

	code.style.color	   									= '#000000';

	code.style.fontSize    									= '10px';

	code.value			   									= 'Please Enter Correct Code';

	

}



function emailbysani(field)

{

	with (field)

	  {

		  apos=value.indexOf("@");

		  dotpos=value.lastIndexOf(".");

		  if (apos<1||dotpos-apos<2)

		  {

			    style.background = '#ffc2c2';

				style.color	   = '#000000';

				style.fontSize   = '10px';

				value			   = 'Please Enter Valid Email Address';

				return false;

		  }

	  }

}





function returnbysani(actual, actbg)

{ 

	actual.style.background 	= 'url(images/'+actbg+')'; 

	actual.style.backgroundRepeat 	= 'no-repeat';

	actual.style.color	   		= '#acaeaf';

	actual.style.fontSize   	= '12px';

	actual.value			  	= '';

  

    feildtext = Array('Student Name', 'Parent Name', 'E-mail', 'Phone Number', 'Enter Verification Code', 'How did you hear about us?', 'Enter Skype Id');

	

	for(i=1; i<=8; i++)

	{ 

		if(document.getElementById('sanibox'+i).value == '')

		{

			if(document.getElementById('sanibox'+i).id != actual.id)

			{

				document.getElementById('sanibox'+i).value = feildtext[i-1];

			}

		}

	}

}



function returnselectbysani(actual, actbg)

{

	actual.style.background 	= 'url(images/'+actbg+')'; 

	actual.style.backgroundRepeat 	= 'no-repeat';

	actual.style.color	   		= '#acaeaf';

	actual.style.fontSize   	= '12px';

  

    feildtext = Array('Student Name', 'Parent Name', 'E-mail', 'Phone Number',  'Enter Verification Code', 'How did you hear about us?', 'Enter Skype Id');

	

	for(i=1; i<=8; i++)

	{ 

		if(document.getElementById('sanibox'+i).value == '')

		{

			if(document.getElementById('sanibox'+i).id != actual.id)

			{

				document.getElementById('sanibox'+i).value = feildtext[i-1];

			}

		}

	}

}



/******************************** Tell a friend *******************************/

function returnbysanileft(actual, actbg)

{  

	actual.style.background 	= 'url(images/'+actbg+')'; 

	actual.style.backgroundPosition 	= 'top';

	actual.style.backgroundRepeat 	= 'no-repeat';

	actual.style.color	   		= '#acaeaf';

	actual.style.fontSize   	= '10px';

	actual.value			  	= '';

	feildtext = Array('Name', 'email');

	

	for(i=1; i<=2; i++)

	{  

		if(document.getElementById('hyneboxs'+i).value == '')

		{

			if(document.getElementById('hyneboxs'+i).id != actual.id)

			{

				document.getElementById('hyneboxs'+i).value = feildtext[i-1];

			}

		}

	}

}





/**************************** left sign up box *************************************/

function returnloginbysani(actual, actbg)

{  

	actual.style.background 	= 'url(images/'+actbg+')'; 

	actual.style.backgroundPosition 	= 'top';

	actual.style.backgroundRepeat 	= 'no-repeat';

	actual.style.color	   		= '#acaeaf';

	actual.style.fontSize   	= '10px';

	actual.value			  	= '';

	feildtext = Array('User name/E-mail', 'Password');

	

	for(i=1; i<=2; i++)

	{  

		if(document.getElementById('hynebox'+i).value == '')

		{

			if(document.getElementById('hynebox'+i).id != actual.id)

			{

				document.getElementById('hynebox'+i).value = feildtext[i-1];

			}

		}

	}

}



function returnbyhyne(actual)

{ 

	actual.style.background 	= '#ffffff'; 

	actual.style.color	   		= '#000000';

	actual.style.fontSize   	= '12px';

	actual.value			  	= '';

  

   

}





function validatetime(str)

{

	if(!(str.value.match(/^\d{1,2}:\d{2}([ap]m)?$/)) == true) 

	{

		str.style.background = '#ffc2c2';

		str.style.color	   	 = '#000000';

		str.style.fontSize   = '10px';

		str.value			 =  '(eg. 04:04 or 4:04am)';

		return false;

	}

}



/*function  validatetime(txtbx)

{

  var strval = txtbx.value;

  var strval1;

   alert(strval.length); */

  

 /* if(strval.length < 6)

  {

   		feildname.style.background = '#ffc2c2';

		feildname.style.color	   = '#000000';

		feildname.style.fontSize   = '10px';

		feildname.value			   = 'format should be HH:MM AM/PM';

		return false;

 }*/

  /*

   if(strval.length < 6)

  //Maximum length is 8. example 10:45 AM

  if(strval.lenght > 8)

  {

   alert("invalid time. Time format should be HH:MM AM/PM.");

   return false;

  }

  

  //Removing all space

  strval = trimAllSpace(strval); 

  

  //Checking AM/PM

  if(strval.charAt(strval.length - 1) != "M" && strval.charAt(

      strval.length - 1) != "m")

  {

   alert("Invalid time. Time shoule be end with AM or PM.");

   return false;

   

  }

  else if(strval.charAt(strval.length - 2) != 'A' && strval.charAt(

      strval.length - 2) != 'a' && strval.charAt(

      strval.length - 2) != 'p' && strval.charAt(strval.length - 2) != 'P')

  {

   alert("Invalid time. Time shoule be end with AM or PM.");

   return false;

   

  }

  

  //Give one space before AM/PM

  

  strval1 =  strval.substring(0,strval.length - 2);

  strval1 = strval1 + ' ' + strval.substring(strval.length - 2,strval.length)

  

  strval = strval1;

      

  var pos1 = strval.indexOf(':');

  document.Form1.TextBox1.value = strval;

  

  if(pos1 < 0 )

  {

   alert("invlalid time. A color(:) is missing between hour and minute.");

   return false;

  }

  else if(pos1 > 2 || pos1 < 1)

  {

   alert("invalid time. Time format should be HH:MM AM/PM.");

   return false;

  }

  

  //Checking hours

  var horval =  trimString(strval.substring(0,pos1));

   

  if(horval == -100)

  {

   alert("Invalid time. Hour should contain only integer value (0-11).");

   return false;

  }

      

  if(horval > 12)

  {

   alert("invalid time. Hour can not be greater that 12.");

   return false;

  }

  else if(horval < 0)

  {

   alert("Invalid time. Hour can not be hours less than 0.");

   return false;

  }

  //Completes checking hours.

  

  //Checking minutes.

  var minval =  trimString(strval.substring(pos1+1,pos1 + 3));

  

  if(minval == -100)

  {

   alert("Invalid time. Minute should have only integer value (0-59).");

   return false;

  }

    

  if(minval > 59)

  {

     alert("Invalid time. Minute can not be more than 59.");

     return false;

  }   

  else if(minval < 0)

  {

   alert("Invalid time. Minute can not be less than 0.");

   return false;

  }

   

  //Checking minutes completed.

  

  //Checking one space after the mintues 

  minpos = pos1 + minval.length + 1;

  if(strval.charAt(minpos) != ' ')

  {

   alert("Invalid time. Space missing after minute. 

       Time should have HH:MM AM/PM format.");

   return false;

  }

 

  return true;*/

/*}*/





function trimAllSpace(str) 

{ 

    var str1 = ''; 

    var i = 0; 

    while(i != str.length) 

    { 

        if(str.charAt(i) != ' ') 

            str1 = str1 + str.charAt(i); i ++; 

    } 

    return str1; 

}





function trimString(str) 

{ 

     var str1 = ''; 

     var i = 0; 

     while ( i != str.length) 

     { 

         if(str.charAt(i) != ' ') str1 = str1 + str.charAt(i); i++; 

     }

     var retval = IsNumeric(str1); 

     if(retval == false) 

         return -100; 

     else 

         return str1; 

}



function IsNumeric(strString) 

{ 

    var strValidChars = "0123456789"; 

    var strChar; 

    var blnResult = true; 

    //var strSequence = document.frmQuestionDetail.txtSequence.value; 

    //test strString consists of valid characters listed above 

    if (strString.length == 0) 

        return false; 

    for (i = 0; i < strString.length && blnResult == true; i++) 

    { 

        strChar = strString.charAt(i); 

        if (strValidChars.indexOf(strChar) == -1) 

        { 

            blnResult = false; 

        } 

     }

     return blnResult; 

}



/************************************************************** stop mouse wheel scroll *********************************************/

/*document.onmousewheel = function(){ stopWheel(); } 

if(document.addEventListener){ 

    document.addEventListener('DOMMouseScroll', stopWheel, false);

}

 

function stopWheel(e){

    if(!e){ e = window.event; } 

    if(e.preventDefault) { e.preventDefault(); } 

    e.returnValue = false; 

}*/


