   //---------------------Code written & Tested by Nitin Asnani----------------
   //----------------------------All Rights Reserved --------------------------
   /***************************************************************************
   '* Javascript Utilities & Validations                                      *
   '*                                                                         *
   '* Do not remove this notice.                                              *
   '*                                                                         *
   '* Copyright 2005-2008 by Nitin Asnani.                                    *
   '***************************************************************************

   '- Customization of these JS Utilities / Validations is required ----------*/



//---------------------------- Assigning Co-ordinates to objects based on co-ordinates of other object --------//
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function nitinasnani(obj,g) // obj - Source object ; g - Target object
{
var coors = findPos(obj);

var x = document.getElementById(g);
	//x.style.top = coors[1] + 'px';
	x.style.left = coors[0] +0 + 'px';
	x.style.top = coors[1] +30 + 'px';
}




//---------------------------- Check length of characters in the textfield / textarea / form objects --------//
function chklen(d,a)
		{	
		s=d.value;
		aa=a+1;
		if (s.length>aa)
		{
		
		alert ("maximum character limit is " + aa)
		d.value=s.substring(0,aa);				
		}
		}
		


//-----------Common functions ------
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}


function setFieldsToUpperCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toUpperCase();
		}
	}


function setFieldsToLowerCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toLowerCase();
		}
	}

function checkUrl(theUrl){
//alert(theUrl);
  if(theUrl.value.match(/^(http|ftp|https)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i) ||
     theUrl.value.match(/^mailto\:\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w{2,4}$/i)){
    return true;
  } else {
    alert("Wrong address.");
    theUrl.select();
    theUrl.focus();
    return false;
  }
}



//--------Counting No. of words --------------
function count_words(tbox_input)
   {
   var msg = "";
   var c = 0;
   var er = 0;
   w = tbox_input.value.split(" ");
   no_words = w.length;
   //alert(no_words+" Word(s)");
   for (x = 0; x < no_words; x++)
      {
      if (c >= 120)
         {
         alert("Maximum 120 words!");
         tbox_input.value = msg;
         er = 1;
         break;
         }
      msg = msg + w[x] + " ";
      c++;
      }
   if (er)
      {
      return false;
      }
   return true;
   }



//=====================================New Section======================================//








//---------------------------- Common Validations --------//

function validate()
	{
		if(document.getElementById('custname').value=="")
		{
			alert("Please Enter Your Name");
			document.getElementById('custname').focus();
			return false;
		}
		
		//-------------- Validating blank field -------i.e if whitespace, newlines or tabs-----
		if(isBlank(document.getElementById('custname').value))
		{
			alert("Please Enter Your Name");
			document.getElementById('custname').focus();
			document.getElementById('custname').value="";
			return false;
		}
		
		//--------------- Validating Minimum length -----------
		
		if(document.getElementById('custname').value.length<4)
		{
			alert("Name Should be Minimum 4 Characters!");
			document.getElementById('custname').focus();
			return false;
		}		
		if(document.getElementById('phone').value=="")
		{
			alert("Please Enter Your Phone");
			document.getElementById('phone').focus();
			return false;
		}
		
		//--------------------  Validating Numeric-------------
		
		if(isNaN(document.getElementById('phone').value))
		{
			alert("Please Enter Phone in Numeric Figures! E.g. 0091986000022");
			document.getElementById('phone').focus();
			return false;
		}
		
		
		
		//---------- Validating email----------------
		
		if(document.getElementById('email').value=="")
		{
			alert("Please Enter Your Email");
			document.getElementById('email').focus();
			return false;
		}
			if ((document.getElementById('email').value.indexOf('@') < 0) || ((document.getElementById('email').value.charAt(document.getElementById('email').value.length-4) != '.') && (!(document.getElementById('email').value.charAt(document.getElementById('email').value.length-3) == '.') || (document.getElementById('email').value.charAt(document.getElementById('email').value.length-2) == '.')))) 
			{
				alert("Please Enter Valid Email Address. Please try again.");
				document.getElementById('email').focus();
				return false;
			} 
			  if ((document.getElementById('email').value.substring(document.getElementById('email').value.indexOf('@')+1,document.getElementById('email').value.length)).indexOf('@')>-1) 
			{
    		alert( "Please Enter Valid Email Address. Please try again. Double '@' not allowed ");
    		document.getElementById('email').focus();
    		return false ;
  			}
			
		if(document.getElementById('city').value=="")
		{
			alert("Please Enter City");
			document.getElementById('city').focus();
			return false;
		}
		if(document.getElementById('country').value=="")
		{
			alert("Please Enter Country");
			document.getElementById('Country').focus();
			return false;
		}	
		
		
		//---------Comparing two text fields ----------
		/*if(document.getElementById('field1').value!=document.getElementById('field2').value)
		{
			alert("Field1 is not equal to Field2");
			document.getElementById('field1').focus();
			return false;
		}*/
		
		//-------- Setting field to lower case --------
		
		setFieldsToLowerCase(document.getElementById('email'));
		
		
		
		//------------ Count no. of words ---------
		count_words(document.getElementById('comm'));
		
		//------------- Restrict file type --------
		
		 /*var str=document.getElementById('xfile').value;
  		 str1=str.substring(str.lastIndexOf(".")+1,str.length);
		 str1=str1.toLowerCase();
 		 if(str1!="xls"&&str1!="xlt")
  		 {
  		 alert("Invalid File -- please only select .xls format files");
 		 document.getElementById('xfile').focus();
 		 document.getElementById('xfile').value=="";
 		 return false
 		 }*/
		
		
		//--------- Validating URL -------------
		
		/*checkUrl(document.getElementById('urlfield'))*/
		
		
		
		//--------- Validating Radio button selection --------
		// require at least one radio button be selected
		
		/*var radioSelected = false;
	
		for (i = 0;  i < document.form1.radiofield.length;  i++)
		{
		if (document.form1.radiofield[i].checked)
		radioSelected = true;
		}
		if (!radioSelected)
		{
		alert("Please select one of the Radio options.");
		return (false);
		}*/



		//--------------- Validating multi choice list box  -------
		// check if more than 5 options are selected
		// check if less than 1 options are selected
		
		/*var numSelected = 0;
		var i;
		for (i = 0;  i < document.form1.listboxname.length;  i++)
		{
		if (document.form1.listboxname.options[i].selected)
		numSelected++;
		}
		if (numSelected > 5)
		{
		alert("Please select at most 5 of the \"province\" options.");
		document.form1.listboxname.focus();
		return (false);
		}
		if (numSelected < 1)
		{
		alert("Please select at least 1 of the \"province\" options.");
		document.form1.listboxname.focus();
		return (false);
		}
		*/
		
		
		
		//---------------- Validating agree to terms checkbox --------------
		/*if(document.getElementById('checkbox').checked!=true)
		{
			alert("Please agree to the Terms and Conditions!");
			document.getElementById('checkbox').focus();
			return false;
		} */
		
		
		
		//-------------------Date bound validations & addons -------------
		
		//To add 30 years to entered date (assuming crdate & expdate are form fields & atype is combo box)
		
		/*if(document.getElementById('atype').value=="add30years")
		{
		document.getElementById('price').value="0";
		var myDate=new Date(document.getElementById('crdate').value);
		//myDate.setDate(myDate.getDate()+5);
		
		curr_month=myDate.getMonth()+1;
		curr_date=myDate.getDate();
		curr_year=myDate.getFullYear()+30;
		myDate2=(curr_month + "/" + curr_date + "/" + curr_year);

		document.getElementById('expdate').value=myDate2;
		}
	
	//To add one month to the entered date (assumptions as in above eg)	
	if(document.getElementById('atype').value=="addonemonth")
	{
		document.getElementById('price').value="5000";
		var myDate=new Date(document.getElementById('crdate').value);
		//myDate.setDate(myDate.getDate()+5);
		
		
		curr_date=myDate.getDate();
		c=myDate.getMonth()+2
		if(c>12)
		{
		curr_month=1;
		curr_year=myDate.getFullYear()+1;
		}
		else
		{
		curr_month=myDate.getMonth()+2;
		curr_year=myDate.getFullYear();
		}
		myDate2=(curr_month + "/" + curr_date + "/" + curr_year);

		document.getElementById('expdate').value=myDate2;
	}
	
	//To add 10 days to entered date (Assumptions as in above eg)
	if(document.getElementById('atype').value=="lifetime")
	{
		document.getElementById('price').value="1000";
		var myDate=new Date(document.getElementById('crdate').value);
		//myDate.setDate(myDate.getDate()+5);
		
		curr_month=myDate.getMonth()+1;
		curr_date=myDate.getDate()+10;
		curr_year=myDate.getFullYear();
		myDate2=(curr_month + "/" + curr_date + "/" + curr_year);

		document.getElementById('expdate').value=myDate2;
	}
	*/
		
		
		
		
		 // This script checks and unchecks boxes on a form
// Checks and unchecks unlimited number in the group...
// Pass the Checkbox group name...
// call buttons as so:
// <input type=button name="CheckAll"   value="Check All"
	//onClick="checkAll(document.myform.list)">
// <input type=button name="UnCheckAll" value="Uncheck All"
	//onClick="uncheckAll(document.myform.list)">
// -->

/*
function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}
*/

			
	}
	
	
