/*

 ValidateMain(form_object)

 USAGE:

 <input type="hidden" name="_^[A][--+B]" value="[C]"/>



 [A]: A valid javascript condition where 'f' is predefined to be the field object

 preceeding the hidden condition field, ge('name or id') returns given field object,

 and rc('name or id') returns string of 1s and 0s representing the checked or

 unchecked state of a group of fields with the given name or id

 

 [--+B]: Optional.  Defines the field name or id that should receive the focus

 after the pop up message.  By default, the field preceeding the hidden

 condition field receives the focus, however this may not be desirable

 

 [C]: Pop up message

 

 ValidateShort(form_object) and BufferFields()

 USAGE:

 Use this pair of functions to eliminate default text in a field upon submission.

 ValidateShort replaces ValidateMain for this purpose. It additionally 

 predefines 'iv' as the initial value of the field preceeding the hidden condition

 field for use in the condition 

 

 NOTE: iv is defined only for the field preceeding the hidden condition field,

 therefore, consecutive condition fields aren't supported for use with this var

 

 Buffer fields should be placed on the page after all forms that use ValidateShort

 

*/



var arrFormFields, iOffset=0;



//Buffer up to one hundred fields from forms on page

var arrFormFields=Array(100);

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

	arrFormFields[i]=Array(2);



//Validation code-------------------------------------------

function ValidateMain(frm){  

	var i, k=0, f, iv, focus_value, value_pair, condition_value;

	e=frm.elements;

	

	for(i=0;i<e.length;i++){

		iv=getFieldByIndex(frm, i-1); 

		

		if(e[i].name.substring(0,2)=='_^'){

			f=e[k];

		

			value_pair = e[i].name.split('--+');

			

			focus_value='';

			if(value_pair.length>1){

				focus_value=value_pair[1];		

				condition_value = value_pair[0].substring(2,value_pair[0].length);

			}

			else

				condition_value=e[i].name.substring(2,e[i].name.length);

			

			//alert(condition_value);

			

			if(eval(condition_value)){

				alert(e[i].value);

				

				if(focus_value!=''){

					focus_value = ge(focus_value);		

					focus_value.focus();

					if(focus_value.type!='select-one')		

						focus_value.select();

				}

				else{

					e[k].focus();

					if(e[k].type!='select-one')

						e[k].select();

				}				

				

				return false;

			} 

		}

		else

			k=i;     

	}

	

	return true;

}

 

function ge(sIdName){

 var j=0;

 for(j=0;j<e.length;j++)

  if(e[j].id==sIdName||e[j].name==sIdName)

   return e[j];

 

 alert('ge: No name or id "'+sIdName+'"');

 return e[0]; 

}

 

function rc(sIdName){

 var j=0,sBString='';

 for(j=0;j<e.length;j++)

  if(e[j].id==sIdName||e[j].name==sIdName)

   sBString+=(e[j].checked)?'1':'0';   

  

  if(sBString=='')

   alert('rc: No name or id "'+sIdName+'"');

  return sBString;

  

}

//Validation code-----------------------------------	







//Buffer form index, field name, and field value into arrFormFields for all forms in document

function bufferFields(){

	var i,j;

	for(i=0;i<document.forms.length;i++){			

		for(j=0;j<document.forms[i].elements.length;j++){									

			arrFormFields[iOffset][0]=i;

			arrFormFields[iOffset][1]=document.forms[i].elements[j].name;

			arrFormFields[iOffset][2]='';

			

			if(document.forms[i].elements[j].type=='text' || document.forms[i].elements[j].type=='textarea'){

				arrFormFields[iOffset][2]=document.forms[i].elements[j].value;				

			}	

	

			//alert(arrFormFields[iOffset][0] + ', ' + arrFormFields[iOffset][1] + ', ' + arrFormFields[iOffset][2] + ', ' + iOffset);

			iOffset++;

		}		

	}

	return 0;

}

//Get field value from form object and field name in the arrFormFields array

function getFieldByName(frm, fieldName){

	var i,formIndex = getFormIndex(frm);

	

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

		if(arrFormFields[i][0]==formIndex&&arrFormFields[i][1]==fieldName){

			return arrFormFields[i][2];

		}

			

	return 0;

}

//Get field value from form object and element index in the arrFormFields array

function getFieldByIndex(frm, index){

	var i,j=-1,formIndex = getFormIndex(frm);



	for(i=0;i<iOffset;i++){

		if(arrFormFields[i][0]==formIndex&&j==-1)		

			j=i;

		

		if(i-j==index&&j!=-1)

			return arrFormFields[i][2];

	}

			

	return 0;

}



//Set value of all fileds that still have default values to null string in a given form

function clearDefaultValues(frm){

	var i;

	for(i=0;i<frm.elements.length;i++)

		if(frm.elements[i].value==getFieldByIndex(frm,i))

			frm.elements[i].value='';



	return true;

}



//Use this to validate short forms and clear default values

function ValidateShort(frm){

	

	if(ValidateMain(frm))

		return clearDefaultValues(frm);

	

	return false;



}



//Get form index for given form

function getFormIndex(frm){

	var i;

	for(i=0;i<document.forms.length;i++)

		if(document.forms[i]==frm)

			return i;

	

	return 0;

}



function sendmail()

{

	var loc=location.href;

	window.location.href="sendme.php?url="+loc;

}



function checkspchar(f1)

{

}



function checkspchar1(f1)

{

  var n = window.event.keyCode;

  if(!((n>=65 && n<=90) || (n>=97 && n<=122) || (n>=48 && n<=57) || (n==32)))

  {

     alert("Please do not write any special character");

	 window.event.keyCode = ""; 

  }

}

function checkchar(f1)

{

}



function checkchar1(f1)

{

  var n = window.event.keyCode;

  if(!((n>=65 && n<=90) || (n>=97 && n<=122)))

  {

     alert("Please enter alphabetic character");

	 window.event.keyCode = ""; 

  }

}

function checknum(f1)

{

}



function checknum1(f1)

{

  var n = window.event.keyCode;

  if(!(n>=48 && n<=57))

  {

     alert("Please enter Digits");

	 window.event.keyCode = "";

  }

}

function checkform(f1)



{

  if ((f1.en.value == "") || (f1.en.value == "Enter name"))

  {

    alert("Please enter a name.");

    f1.en.focus();

    return (false);

  }  

  

     if ((f1.ep.value == "") || (f1.ep.value == "Enter phone"))

  {

    alert("Please enter Your Phone Number.");

    f1.ep.focus();

    return (false);

  }  

  if ((f1.ee.value == "") || (f1.ee.value == "Enter email"))

  {

    alert("Please enter your Email Id.");

    f1.ee.focus();

    return (false);

  }





  if (f1.ee.value.indexOf ('@',0) == -1 || f1.ee.value.indexOf ('.',0) == -1)

   {

    alert("Please enter valid Email Id.");

    f1.ee.focus();

    return (false);

  }

  

  if ((f1.enter.value == "") || (f1.enter.value == "Enter a brief description of your case"))

  {

    alert("Enter a brief description of your case");

    f1.enter.focus();

    return (false);

  } 



 if ((f1.type.value == "") || (f1.type.value == "type the characters above"))

  {

    alert("Please type the characters.");

    f1.type.focus();

    return (false);

  }



 if( !((f1.type.value == "hwk9p4")|| (f1.type.value == "HWK9P4")))

  {

    alert("Please Type The Correct Characters");

    f1.type.focus();

    return (false);

  }



   return (true);

}

function checkform1(f2)



{

  if (f2.fnm.value == "")

  {

    alert("Please enter First Name.");

    f2.fnm.focus();

    return (false);

  }  

  

  if (f2.lnm.value == "")

  {

    alert("Please enter Last Name.");

    f2.lnm.focus();

    return (false);

  }  

  if (f2.ph1.value == "")

  {

    alert("Please enter Daytime Phone.");

    f2.ph1.focus();

    return (false);

  }  

  



  if (f2.email.value == "")

  {

    alert("Please enter your Email Id.");

    f2.email.focus();

    return (false);

  }  





  if (f2.email.value.indexOf ('@',0) == -1 || f2.email.value.indexOf ('.',0) == -1)

   {

    alert("Please enter valid Email Id.");

    f2.email.focus();

    return (false);

  }

  

  if (f2.street.value == "")

  {

    alert("Please Enter Street Address");

    f2.street.focus();

    return (false);

  } 

  if (f2.apt.value == "")

  {

    alert("Please Enter Apt. #");

    f2.apt.focus();

    return (false);

  } 

  if (f2.citystatezip.value == "")

  {

    alert("Please Enter city, state, zip");

    f2.citystatezip.focus();

    return (false);

  } 





   return (true);

}



function checkform2(f3)



{

  if (f3.First.value == "")

  {

    alert("Please enter a name.");

    f3.First.focus();

    return (false);

  }  

  

  if (f3.Email.value == "")

  {

    alert("Please enter your Email Id.");

    f3.Email.focus();

    return (false);

  }  



  if (f3.Email.value.indexOf ('@',0) == -1 || f3.Email.value.indexOf ('.',0) == -1)

   {

    alert("Please enter valid Email Id.");

    f3.Email.focus();

    return (false);

  }

 /*if ((f3.type.value == "") || (f3.type.value == "type the characters above"))

  {

    alert("Please type the characters.");

    f3.type.focus();

    return (false);

  }



 if( !((f3.type.value == "bar30mv")|| (f3.type.value == "BAR30MV")))

  {

    alert("Please Type The Correct Characters");

    f3.type.focus();

    return (false);

  }
*/
   return (true);

}



function checkform3(f4)



{

  if (f4.name.value == "")

  {

    alert("Please enter a name.");

    f4.name.focus();

    return (false);

  }  

  

  if (f4.email.value == "")

  {

    alert("Please enter your Email Id.");

    f4.email.focus();

    return (false);

  }  



  if (f4.email.value.indexOf ('@',0) == -1 || f4.email.value.indexOf ('.',0) == -1)

   {

    alert("Please enter valid Email Id.");

    f4.email.focus();

    return (false);

  }



   return (true);

}



function checkform4(f5)

{

  if (f5.t1.value == "")

  {

    alert("Please enter a name.");

    f5.t1.focus();

    return (false);

  }  

  

  if (f5.t2.value == "")

  {

    alert("Please enter your Email Id.");

    f5.t2.focus();

    return (false);

  }  



  if (f5.t2.value.indexOf ('@',0) == -1 || f5.t2.value.indexOf ('.',0) == -1)

   {

    alert("Please enter valid Email Id.");

    f5.t2.focus();

    return (false);

  }

    if (f5.t9.value == "")

  {

    alert("Please enter Phone Number.");

    f5.t9.focus();

    return (false);

  }  

 if ((f5.type.value == "") || (f5.type.value == "type the characters above"))

  {

    alert("Please type the characters.");

    f5.type.focus();

    return (false);

  }



 if( !((f5.type.value == "thgf76d")|| (f5.type.value == "THGF76D")))

  {

    alert("Please Type The Correct Characters");

    f5.type.focus();

    return (false);

  }

  



   return (true);

}

