//This is GotoPage() function to open given page
function GotoPage(Pagename) 
{
	location.href=Pagename;
}
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR NEXT PAGE ....
//THIS FUNCTION POSTS FORM FOR NEXT PAGE ....
//=============================================================================================================================
function NextPage()
{
   document.frmlist.pageNumber.value = eval(document.frmlist.pageNumber.value) + 1;
   document.frmlist.submit();
}
//===========================================================================================================================
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR PREVIOUS PAGE ....
//THIS FUNCTION POSTS FORM FOR PREVIOUS PAGE ....
//=============================================================================================================================
function PrePage()
{
   
	document.frmlist.pageNumber.value = eval(document.frmlist.pageNumber.value) - 1  ;
	document.frmlist.submit();
}

//=============================================================================================================================
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR SPECIFIED PAGE NUMBER....
//THIS FUNCTION POSTS FORM FOR SPECIFIED PAGE NUMBER....
//=============================================================================================================================
function NextPageLink(val)
{
    
	document.frmlist.pageNumber.value = eval(val)-1  ;
	document.frmlist.submit();
}
//=============================================================================================================================
//========function SubmitForPage used to submit form ==========================================================================
//=============================================================================================================================
function SubmitForPage(FormName, ControlName, ControlValue, FormAction)
{
	ControlName.value = ControlValue;
	FormName.action = FormAction;
	FormName.submit();
}
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR ORDER BY....
//THIS FUNCTION POSTS FORM FOR ORDER BY....
//=============================================================================================================================
function OrderPage(OrderBy)
{
	
	document.frmlist.pageNumber.value = eval(document.frmlist.pageNumber.value);
	
	if(document.frmlist.orderby.value.search(OrderBy)<0)
		document.frmlist.orderby.value = OrderBy;
	else
	{
		if(document.frmlist.orderby.value.search(' desc')<0)
			document.frmlist.orderby.value = OrderBy +' desc';
		else
			document.frmlist.orderby.value = OrderBy;
	}
	//alert(OrderBy);
	document.frmlist.submit();
}



function OrderFunction(orderstr,type)
{
	//alert(orderstr + type);
    document.frmlist.orderby.value = "order by " + orderstr +" " + type ;
	document.frmlist.submit();
}


function setvalue(tar,con,val)
{
	con.value=val;
	tar.submit();
}
/**************************************************************************************/
//====================================================================
//REPLACEMENT FUNCTION FOR trim() FUNCTION.....
//REPLACEMENT FUNCTION FOR trim() FUNCTION.....
//====================================================================
//====================================================================
function Trimmer(pVal) { 
    TRs=0; 
    var i;
	for (i=0; i<pVal.length; i++) 
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRs++;
		} 
		else 
			{break;} 
    } 

    TRe=pVal.length-1; 
    for (i=TRe; i>TRs-1;i--)
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRe--;
		}
		else 
			{break;} 
    } 

    return (pVal.substr(TRs, TRe-TRs+1)); 
} 

//====================================================================
//====================================================================
//====================================================================
//Trim by Object name.....
//====================================================================
//====================================================================
function TrimObj(theObj) 
{ 
	var pVal = theObj.value;

    var TRs=0; 
    for (var i=0; i<pVal.length; i++) 
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRs++;
		} 
		else 
			{break;} 
    } 

   	var TRe=pVal.length-1; 
    for (i=TRe; i>TRs-1;i--)
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRe--;
		}
		else 
			{break;} 
    } 

    theObj.value = pVal.substr(TRs, TRe-TRs+1); 
} 
//==================== trimmer() ends ============================
//===============================================================================================================================
//======================================== FUNCTION dateConversion() start =========================================
//=============================================================================================================================
//function for date
//compare date
function DateComparison(val,date1,date2)
{
    //alert("assaasss");
    if(date1=='')
	{
		alert("Please select news date.");
		//val.ndate.focus();
		return false;
	}
    var error=0;
    var d1,d2,m1,m2,y1,y2;
    var fromdate=date1.split('-');
    var todate=date2.split('-'); 
	var ARR_MONTH = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN","JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
	var FromMonth='';
	var ToMonth='';
    var mon=fromdate[1];
	mon=mon.toUpperCase();
    var mon1=todate[1];
	mon1=mon1.toUpperCase(mon1);

	for(i=0;i<ARR_MONTH.length;i++)
	 {
	   if(mon==ARR_MONTH[i])
	   {
	     FromMonth=i+1;
	   }
	   if(mon1==ARR_MONTH[i])
	   {
	     ToMonth=i+1;
	   }
	 
	 }
	 
   d1=eval(fromdate[0]);
   d2=eval(todate[0]);
   m1=eval(FromMonth);
   m2=eval(ToMonth);
   y1=eval(fromdate[2]);
   y2=eval(todate[2]);

   //return true if second is greater  or equal to first date
   	if (y2 > y1)
	{
   		return true;
	}
	else
	{
		if(y1 > y2)
		{
		 // alert("please enter date less than current date");
		 // document.articlefrm.ndate.focus();
		  //alert(error);
		  error=1;
		//  return false;
			
		}
		else
		{
			if(m2>m1)
			{
				return true;
			}
			else
			{	
				if(m1>m2)
				{
				   // alert("please enter date less than current date");
		           // document.articlefrm.ndate.focus();
					error=1;
					//return false;
				}
				else
				{
					if(d2>=d1)
					{
						return true;
					}
					else
					{
					   // alert("please enter date less than current date");
		                //document.articlefrm.ndate.focus();
					    error=1;
						//return false;
					}

				}

			}

		}

	}  
	if(error==1)
	{
	    alert("Please enter date less than current date.");
		val.focus();
		return false;
	}					
 }
 
//=============================================================================================================================
//=====================================================
//THE FOLLOWING FUNCTION WILL CHECK THE EMAIL ID
//=====================================================
function CheckEmailId(val) {
// Check for a properly formatted email address.
  if ((val.value.length == 0)) {
      return false;
   }

   if (val.value.length != 0) {
     // var emailformat = /^.+@.+\..{2,3}$/;
      var emailformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum|nic|in|co.in|co|inc)$/;
      if (!emailformat.test(val.value))
	   {
	     alert("Please enter valid email.");
		 val.value="";
		 val.focus();
		 return false;
      }
   }
   return true;
}
//========================================================

		//=======================================================================\\
		
		//=======CHECK THAT FIELD IS A VALID NUMBER FIELD========================\\
		
		//=======================================================================\\
		
		function isNumberField(theField)
		
		{
		
		  var numFlag=true;
		
		  var countDot=0;
		
		  var ch="";
		
		  var newValue="";
		
		  theField.value=Trimmer(theField.value);
		
		  for(i=0;i<theField.value.length;i++)
		
		   {
		
			 ch=theField.value.charAt(i);
		
			 if(ch==".")
		
			  countDot+=1;
		
			 if ((ch >= "0" && ch <= "9") || (ch == "."))
		
			  {
		
				  if(countDot>1)
		
				  {
		
					//CODE TO ALERT THE USER
		
					//alert("Enter a valid number value");
		
				  //  theField.value="";
		
				  //  return false; 
		
				   //CODE TO REMOVE THE OTHER VALUES EXCEPT NUMBER
		
				   continue;
		
				  }
		
				  else
		
				  {
		
				   newValue+=ch;  //NEW VALUE OF THE NUMBER
		
				  }	
		
			  }
		
			 else
		
			 {
		
					//CODE TO ALERT THE USER
		
				//alert("Enter a valid numeric value");
		
				//theField.value="";
		
				//return false; 
		
				continue;
		
			 } 
		
		   } 
		   //====for correct new value==\
		
		   theField.value=newValue;
		
		}

///////////////////=========================================
		function validDate(dateComponent, displayStr)
		{
			if(dateComponent.value!='')
			{
					
			//========================= validation code =======================================\\
					var Arr_Kishor = ["01", "02", "03", "04", "05", "06","07", "08", "09", "10", "11", "12"];
					var d1, flag=0;
					d1 = dateComponent.value.split("-");	
					if(d1.length < 2)
						flag=1;
					else if(d1[0].length!=2 || d1[1].length!=2  || d1[2].length!=4)
					{
						flag=1;
					}
					else
					{
						
						 flag=1;
						for(i=0;i<Arr_Kishor.length;i++)
						 {
						   if(d1[1]==Arr_Kishor[i])
								 flag=0; 		
						}
						if(d1[0] > 31 || d1[0] < 0)
							flag=1;
						if(d1[2] > 2200 || d1[2] < 1950)
							flag=1;
					}	
					if(flag==1)
						{
							alert("Please enter a valid "  + displayStr + " date  ");
							//dateComponent.value='';
							dateComponent.focus();
							return false;
						}
					return true;
			//========================= END.... validation code =======================================\\		
			}
			return true;
			
		}	

 function BisEmail(val, req) {
// Check for a properly formatted email address.
   if ((val.value.length == 0) && (req == "R")) {
      alert("This field is required.");
      val.focus();
      val.select();
      return false;
   }
   var email = val.value.toLowerCase();
   if (val.value.length != 0) 
   {
		  var emailformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/;
		//var emailformat = /^.+@.+\..{2,3}$/;
	  	if (!emailformat.test(email)) {
         alert("Please enter a valid email Id.");
         val.focus();
         val.select();
         return false;
      }
   }
	val.value=email;
   return true;
}
//=====================================================================================================//
//............................for date validation......................................................
function isDate(val) 
{
	var IsValid = 0;
	 if (val.value.length != 0) 
     {
		 // var longform = (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2};
		//var longform = ^(([0]?[1-9]|1[0-2])/([0-2]?[0-9]|3[0-1])/[1-2]\d{3})? ?((([0-1]?\d)|(2[0-3])):[0-5]\d)?(:[0-5]\d)? ?(AM|am|PM|pm)?$
        var longform =  /^[0-1][0-9]-[0-9]{2}-[1-9][0-9]{3}$/;
        if(longform.test(val.value))
		  {
		  		var DateArr = val.value.split("-");
				if(DateArr[1]> 31 || DateArr[0] >12)
					IsValid = 0;
				else
					IsValid = 1;
          }
		
				  if(IsValid == 0)
				  {
				  	
					  val.value='';
					  alert("Please enter date in mm-dd-yyyy format");
					 val.focus();
					 return false;
				  }
   }
   
   return true;
}
//==============================================================================================
//..........................function for validation for only alphabetic values..................
function IsAlpha(val) 
{
	if (val.value.length != 0)
    {
		if (val.value.length >= 3)
    	{  
			   for (i = 0; i < val.value.length; i++)
			   {
				   var ch = val.value.charAt(i);
				   if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") ||  (ch == ".") || (ch == "&")|| (ch == "/")|| (ch == "|")|| (ch == "\\")|| (ch == " ")) 
				  // if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == " ") || (ch == "&")) 
				   {
					  continue;
					} 
				   else
				   {
					val.value='';
					alert("Please enter only character information.");
					val.focus();
					return false;
				   }
			   }
		}
		else
		{
			val.value='';
			alert("Please enter atleast 3 characters.");
			val.focus();
			return false;
		}
    }

   return true;
}



function Is(val) 
{
	if (val.value.length != 0)
    {
		if (val.value.length >= 3)
    	{  
			   for (i = 0; i < val.value.length; i++)
			   {
				   var ch = val.value.charAt(i);
				   if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") ||  (ch == ".") || (ch == "&")|| (ch == "/")|| (ch == "|")|| (ch == "\\")) 
				  // if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == " ") || (ch == "&")) 
				   {
					  continue;
					} 
				   else
				   {
					val.value='';
					alert("Please enter only character information.");
					val.focus();
					return false;
				   }
			   }
		}
		else
		{
			val.value='';
			alert("Please enter atleast 3 characters.");
			val.focus();
			return false;
		}
    }

   return true;
}

//...............................validation function for only numeric values..............................

function IsNum(val)
 {
   if (val.value.length != 0) 
    {
		if (val.value.length >= 3) 
    	{	
			  for (i = 0; i < val.value.length; i++) 
				  {
					  var ch = val.value.charAt(i);
					  if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == "-")) 
					//   if ((ch >= "0" && ch <= "9")) 
					  {
						continue;
					  } 
					  else
					  { 
					  val.value='';
					  alert("Please enter numeric values.");
					  val.focus();
					  return false;
					 }
				 }
		 }
		 else
		 {
			val.value='';
			alert("Please enter atleast 3 digits.");
			val.focus();
			return false;
		 }
   }
 
}

//...............................validation function for only numeric values..............................

function IsTenNum(val)
 {
   if (val.value.length != 0) 
    {
		if (val.value.length == 10) 
    	{	
			  for (i = 0; i < val.value.length; i++) 
				  {
					  var ch = val.value.charAt(i);
					  //if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == "-")) 
					   if ((ch >= "0" && ch <= "9")) 
					  {
						continue;
					  } 
					  else
					  { 
					  val.value='';
					  alert("Please enter numeric values.");
					  val.focus();
					  return false;
					 }
				 }
		 }
		 else
		 {
			val.value='';
			alert("Please enter atleast 10 digits.");
			val.focus();
			return false;
		 }
   }
 
}

//============This function is used for deleting any record=======================================
function ifdelete(val)
{
  if(confirm("Delete message?"))
	{
		document.getElementById('messageid').value=val;
		document.forms[0].submit();
	}
}

//=======================================================================================
//..................used for mandatory fields validation.................................

 var PLSCAP = "Please ";
 var FULLSTOP = ".";
 var ENTER = "Enter ";

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

function IsNotEmpty(FormName, FieldNameArr, FieldCaptionArr, FieldActionArr)
{
	//alert(FieldCaptionArr);
	//alert(FieldActionArr);
	var Message = '';
	var FocusField = '';
	var Error = 0;
	var TotalFields = eval(FieldNameArr.length);
	//alert(TotalFields);
	//..........check for all mandatory fields....................
	for(var Counter = 0; Counter < TotalFields; Counter++)
	{
		if(document.getElementById(FieldNameArr[Counter]).value == '' || document.getElementById(FieldNameArr[Counter]).value === 0 || document.getElementById(FieldNameArr[Counter]).value =='null')
		{
			Message+= PLSCAP + FieldActionArr[Counter] + " "+ FieldCaptionArr[Counter] + FULLSTOP +"\n";
			
			Error = 1;
			if(FocusField == '') 
			  {
			    FocusField = document.getElementById(FieldNameArr[Counter]);
			  }
	   }
  }
	if(Error == 1)
	{
	    alert(Message);
		FocusField.focus();
		return false;
	}
	 else
	 {  
	   return true;
	 }
}


//=======================================================================================================
//=========================================================================================

//......function is used for checking all check boxes of status............................
function CheckAll(target,val,get_div)
{

 	if(get_div==undefined)
	{
		var div=document.getElementById('chk');
    }
	else
	{
		var div=document.getElementById(get_div);
		
	}
	if(div.innerHTML=='Select All')
	{
		div.innerHTML='Unselect All';
		value=true;
	}
	else
	{
		div.innerHTML='Select All';
		value=false;
	}
	if(val == 1)
	{ 
        //alert(target[0].checked);
		target[0].checked = value;
	}
	else
	 {
		for(i=0; i < val; i++) 
		   {
			 target[i].checked = value;
		   }
	 }
}
//==============================================================================================================================
//=====================================Validation for alphanumeric values=======================================================
//==============================================================================================
//..........................function for validation for only alphabetic values..................
function IsAlphaNum(val) 
{
  if (val.value.length != 0)
   {
		if (val.value.length >= 2)
    	{
			   for (i = 0; i < val.value.length; i++)
			   {
				   var ch = val.value.charAt(i);
				  // if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9")  || (ch == " ") || (ch == ".") || (ch == ",") || (ch == "-") (ch == "|")|| 
				   if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9")  || (ch == " ") || (ch == ".") || (ch == ",") || (ch == "-") ||(ch == "'") || (ch == "!") || (ch == "@") || (ch == "#") || (ch == "$") || (ch == "%") || (ch == "^") || (ch == "&") || (ch == "*") || 
				   (ch == "_") || (ch == "/")||(ch == "\\"))
				   {
					  continue;
					} 
				   else
				   {
					val.value='';
					alert("Please enter valid value.");
					val.focus();
					return false;
				   }
			  }
		}
		else
		{
			val.value='';
			alert("Please enter atleast 2 characters.");
			val.focus();
			return false;
		}
  }

   return true;
}
function IsAlphaNumforName(val) 
{
  if (val.value.length != 0)
   {
		if (val.value.length >= 2)
    	{
			   for (i = 0; i < val.value.length; i++)
			   {
				   var ch = val.value.charAt(i);
				  // if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9")  || (ch == " ") || (ch == ".") || (ch == ",") || (ch == "-") (ch == "|")|| 
				   if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9")  || (ch == " ") || (ch == ".") || (ch == ",") || (ch == "-") ||(ch == "'") || (ch == "!") || (ch == "@") || (ch == "#") || (ch == "$") || (ch == "%") || (ch == "^") || (ch == "&") || (ch == "*") || 
				   (ch == "_") || (ch == "/")||(ch == "\\"))
				   {
					  continue;
					} 
				   else
				   {
					val.value='';
					alert("Please enter valid value.");
					val.focus();
					return false;
				   }
			  }
		}
		else
		{
			val.value='';
			alert("Please enter atleast 2 characters.");
			val.focus();
			return false;
		}
  }

   return true;
}
//======================================================================================================


//==============================For opening new window for viewing invoice==============================
function openwindow(val)
 {
   urlstring='invoiceview.php?invid='+ val;
   //alert(urlstring);
   window.open(urlstring,'mywin',"height='100%',width='100%',status=no,toolbar=no,resizable=1");
 }
//=====================================================================================================
//===================for uploading file related to proper extensions for contacts====================== 

function UploadValidFile(val)
{
   var error = 0;
   var message =''; 
   alert(val);
 if(val.photopath.value!="")
	 { 
       //check the extension of the uploaded file
       Ext=val.photopath.value.substring(val.photopath.value.lastIndexOf('.')+1);
	   Ext=Ext.toLowerCase();
	  
		 if(Ext!='jpg' && Ext!='gif' && Ext!='png' && Ext!='jpeg' && Ext!='pjpeg')
		  {
		    error=1;
			message=message + "Please upload only jpg,gif,png,jpeg,pjpeg format file.\n";
		    
		  }
	 }
     
	 if(error==1)
       {
	     alert(message);
		 return false;
	   }
	else
	  {
	     return true;
	   } 
 }
 
  //================================================================================================  
function UploadValidRegFile(val)
{
   var error = 0;
   var message =''; 
  //================================================================================================ 
    if(val.value!="") // For invoice uploading
	 { 
       //check the extension of the uploaded file
       Ext=val.value.substring(val.value.lastIndexOf('.')+1);
	   Ext=Ext.toLowerCase();
	   
		 if(Ext!='doc' && Ext!='txt' && Ext!='xls' && Ext!='pdf')
		  {
		    error=1;
			message=message + "Please upload files only in doc, xls, txt and pdf format.\n";
		  }
	 }
 
	 if(error==1)
       {
	     val.value='';
		 alert(message);
		 val.focus();
		 return false;
	   }
	else
	  {
	     return true;
	   } 
 }

//#######################################################################################
//....function to insert array values into a string for registration form...........
/*function RegArrayToString(val)
{
	//================================================================================================= 
	//====store education information from temporary array to hidden field...  ##dsales## is used to differentiate information added into various text boxes....
	val.education.value = val.educationtemp.value;
	if(val.edu1.value !="") 
		val.education.value+= "##dsales##" + val.edu1.value;
	if(val.edu2.value !="") 
		val.education.value+= "##dsales##" + val.edu2.value;
	
	//====store experience information from temporary array to hidden field...  ##dsales## is used to differentiate information added into various text boxes....
	val.experience.value = val.experiencetemp[0].value;
	if(val.experiencetemp[1].value !="") 
		val.experience.value+= "##dsales##" + val.experiencetemp[1].value;
	if(val.exp2.value !="") 
		val.experience.value+= "##dsales##" + val.exp2.value;
 //=====================================================================================================  

}*/

function RegArrayToString(val)
{

	//================================================================================================= 
	//====store education information from temporary array to hidden field...  ##dsales## is used to differentiate information added into various text boxes....
	val.education.value = val.educationtemp.value;
	if(val.edu1.value !="") 
		val.education.value+= "##dsales##" + val.edu1.value;
	if(val.edu2.value !="") 
		val.education.value+= "##dsales##" + val.edu2.value;
	if(val.edu3.value !="")	
	   val.education.value+= "##dsales##" + val.edu3.value;
	if(val.edu4.value !="")	
	   val.education.value+= "##dsales##" + val.edu4.value;	
	if(val.edu5.value !="")	
	   val.education.value+= "##dsales##" + val.edu5.value;		//====store experience information from temporary array to hidden field...  ##dsales## is used to differentiate information added into various text boxes....
	val.experience.value = val.experiencetemp.value;
	//=====================================================
	if(val.exp1.value !="") 
		val.experience.value+= "##dsales##" + val.exp1.value;
	if(val.exp2.value !="") 
		val.experience.value+= "##dsales##" + val.exp2.value;
	if(val.exp3.value !="") 
		val.experience.value+= "##dsales##" + val.exp3.value;
	if(val.exp4.value !="") 
		val.experience.value+= "##dsales##" + val.exp4.value;
	if(val.exp5.value !="") 
		val.experience.value+= "##dsales##" + val.exp5.value;	
	//==========================================================
	val.priorjobs.value = val.prjtemp.value;
	if(val.prju1.value !="") 
		val.priorjobs.value+= "##dsales##" + val.prju1.value;
	if(val.prju2.value !="") 
		val.priorjobs.value+= "##dsales##" + val.prju2.value;
	if(val.prju3.value !="") 
		val.priorjobs.value+= "##dsales##" + val.prju3.value;
	if(val.prju4.value !="") 
		val.priorjobs.value+= "##dsales##" + val.prju4.value;
	if(val.prju5.value !="") 
		val.priorjobs.value+= "##dsales##" + val.prju5.value;
	
	
		
 //=====================================================================================================  

}

//===========================================================================================================
//############################Used for navigation of values for fname,lname,email for "invitation"=========== 
 function CheckValue(event,con,val,fun)
  {
     //alert(event.type);
	 var imagesPath="images/";
	 if(con.value=='')
	   {
		  if(event.type=='blur')
		  {
		    con.value=val;
			//this.className = "textinput";
			//this.previousSibling.src = imagesPath + "input_left.gif";
			//this.nextSibling.src = imagesPath + "input_right.gif";
			//con.className="InputCol";	 
		  }
		  else
		   {
		    // con.className="TextCol"; 
			// this.className = "textinputHovered";
			//this.previousSibling.src = imagesPath + "input_left_xon.gif";
			//this.nextSibling.src = imagesPath + "input_right_xon.gif";
		   }
	    }
	 else
	  {
	 	 if(con.value!=val)
		 {
			 fun(con);
		  }
		else
		  {
			con.value='';	
			//con.className="TextCol";
		  }
	  }
	
	
 }
 
 //######################################################################################################################
  //======================To check the check box whether it is checked or not============================================	
function CheckSubmit(RecordCount,Field,Type,Mod)
   	{
		 
		 var Flag = 0; //keeps track that atleast one record is selected to change the status
		 var Counter = 0; 
		 if(RecordCount == 1)
		 { 
		     if(Field.checked==true)
			 {
			    Flag = 1;
			  }
			 else
			 {
			    Flag = 0;
			  } 
		 }	  	
		 else
		 {
		  	for (Counter=0; Counter < RecordCount; Counter++) 
			{
			  if(Field[Counter].checked == true)
				{
				   Flag = 1;
				   break;
				 }    
			  else
			   {
				 Flag = 0;
				}
			}  
			
		}
			
	     if(Flag == 0)
		 {
			if(Type == "delete")
			{
				alert("Please select at least one record to delete.");
			}
						
			return false;
		 }
		 else
		 {
		 	if (Mod!=undefined)
			{
		 		confMess="Do you really want to delete this "+Mod+" record?";
			}
			else
			{
				confMess="Do you really want to delete this record?";
			}	
		 	if(confirm(confMess))
			{
		 		return true;	
			}
			else
			{
				return false;
			}	
		 }	
  }	 
//============================================================================================================================
function CheckSubmitUser(RecordCount,Field,Type)
   	{
		 
		 var Flag = 0; //keeps track that atleast one record is selected to change the status
		 var Counter = 0; 
		 if(RecordCount == 1)
		 { 
		     if(Field.checked==true)
			 {
			    Flag = 1;
			  }
			 else
			 {
			    Flag = 0;
			  } 
		 }	  	
		 else
		 {
		  	for (Counter=0; Counter < RecordCount; Counter++) 
			{
			  if(Field[Counter].checked == true)
				{
				   Flag = 1;
				   break;
				 }    
			  else
			   {
				 Flag = 0;
				}
			}  
			
		}
			
	     if(Flag == 0)
		 {
			if(Type == "delete")
			{
				alert("Please select at least one user to delete.");
			}
			if(Type == "enable")
			{
				alert("Please select at least one user to enable.");
			}
			if(Type == "disable")
			{
				alert("Please select at least one user to disable.");
			}
			
						
			return false;
		 }
	  else
	  		 return true; 	
  }	 



//================================================================================================================================
//===========================To check whether "new password" and "retype new password" are same or not============================
/* function MatchPass(param)
 {
   
   var message = '';
   var error = 0;
   var focuse = '';
   if(param.newpass.value!='' && param.renewpass.value!='' )
     {
	    
		if(param.newpass.value!=param.renewpass.value)
		  {
		     message = message+"New password and 'retype new password' are not same."; 
			 error = 1;
		     if(focuse=='')
			   {
			     focuse = param.newpass;
			   }
		  }
	 }
	 
	 if(error == 1)
	   {
	     alert(message);
		 param.newpass.value='';
		 param.renewpass.value='';
		 focuse.focus();
		 return false;
	   }
	   else
	   {
	     return true;
	   }
  }	*/   	 	
  
function MatchPass(pass,newpass,captionarr)
 {
   var message = '';
   var error = 0;
   var focuse = '';
  
   if(document.getElementById(pass).value!='' && document.getElementById(newpass).value!='' )
     {
		if(document.getElementById(newpass).value!=document.getElementById(pass).value!='')
		  {
		     message = message+ ' '+captionarr[0] +' and '+captionarr[1]+' are not same.'; 
			 error = 1;
		     if(focuse=='')
			   {
			     focuse = document.getElementById(pass);
			   }
		  }
	 }
	 
	 if(error == 1)
	   {
	     alert(message);
		 document.getElementById(pass).value='';
		 document.getElementById(newpass).value='';
		 focuse.focus();
		 return false;
	   }
	   else
	   {
	     return true;
	   }
  }	   	 	

//============================================================================================================================
function MessageCheck(frmaname)
{
	with (frmaname)
	{
		
		var len=fname.length;
		var i;
		var check=0;
		for(i=0;i<len;i++)
		{
			
			if((Trimmer(fname[i].value)!='First Name') && (Trimmer(fname[i].value)!='') && (Trimmer(lname[i].value)!='Last Name') && (Trimmer(lname[i].value)!='') && (Trimmer(email[i].value)!='email') && (Trimmer(email[i].value)!=''))	
			{
						check=1;
			}
			
		}
		
		if(check==0)
		{
			alert('Atleast one information set should be correct.');	
			return false;
		}
		else
		{
			
			if(Trimmer(mailtext.value)=='')
			{
				alert('Please enter message.')	
				return false;
			}
			return true;	
		}
		
	}
}
//========================================================================================================================
function IsNotEmptyOfAddUser(FormName, FieldNameArr, FieldCaptionArr, FieldActionArr)
{
	
	var Message = '';
	var FocusField = '';
	var Error = 0;
	var TotalFields = eval(FieldNameArr.length);
	    for(var Counter = 0; Counter < TotalFields; Counter++)
	    {
		//document.getElementById(FieldNameArr[Counter]).value=document.getElementById(FieldNameArr[Counter]).value.trim();
		    if(document.getElementById(FieldNameArr[Counter]).value.trim() == '')
		    {
	        Error++;
			}
		}
	
	if(TotalFields== Error)
	{
		if(TotalFields==1)
		{
			//alert('Please enter at least one search criteria..');
			 alert(message);
		}
		else
		{
			//alert('Please enter atleast one search criteria.');
			 alert(message);
		}
		return false;
	}
	else
	{
		//setvalue(document.frmlist,document.frmlist.searchoption,'true');
		//alert("Every Thing ok ");
			return true;
	}
	
}


//.............................used function for search field validation..................................................

function ValidateSearch(FormName, FieldNameArr, FieldCaptionArr, FieldActionArr)
{
	
	var Message = '';
	var FocusField = '';
	var Error = 0;
	var TotalFields = eval(FieldNameArr.length);
	//document.write(TotalFields);
	    for(var Counter = 0; Counter < TotalFields; Counter++)
	    {
		//document.getElementById(FieldNameArr[Counter]).value=document.getElementById(FieldNameArr[Counter]).value.trim();
		    if(document.getElementById(FieldNameArr[Counter]).value.trim() == '')
		    {
	        Error++;
			}
		}
	
	if(TotalFields== Error)
	{
		if(TotalFields==1)
		{
			alert('Please enter at least one search criteria..');
		}
		else
		{
			alert('Please enter at least one search criteria.');
		}
		return false;
	}
	else
	{
		
		//setvalue(document.frmlist,document.frmlist.searchoption,'true');
		//alert("Every Thing ok ");
			return true;
	}
	
}
//..........................Password validation for only alphanumeric values not for special characters..................
function IsPass(val) 
{
  if(val.value.length!= 0)
    {
      if(val.value.length>=5)
		 {
	       for(i = 0; i < val.value.length; i++)
	        {
		       var ch = val.value.charAt(i);
		       if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9"))
		          {
                    continue;
                   } 
		       else
		          {
		            val.value='';
                    alert("Please enter valid password.");
		            val.focus();
                    return false;
                 }
            }
         }
      else
        {
          val.value='';
          alert("Please enter atleast 5 characters for password.");
		  val.focus();
          return false; 
	    }
     }
  return true; 
 }
//======================================================================================================
//**********************Impose maximum length for textarea**********************************************
function ImposeMaxLength(Object, MaxLen)
 {
    return(Object.value.length<MaxLen);
 }

//=============================User name validation===================================================
//=============Edited by Himanshu Mahatma on 29 May 2007 to enaable users to use numeric chars in usernames
//=====Original check  if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == " ") || (ch == ".") || (ch == "&"))
function IsUserName(val) 
{
  if(val.value.length != 0)
   {
     if(val.value.length>=5) 
	 { 
	   for(i = 0; i < val.value.length; i++)
	      {
		    var ch = val.value.charAt(i);
		  if((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9") || (ch == ".") || (ch == ",") || (ch == "-"))
		   {
              continue;
            } 
		   else
		   {
		    val.value='';
            alert("Please enter only character information.");
		    val.focus();
            return false;
           }
        }
    }
	else
	  {
	    val.value='';
        alert("Please enter atleast 5 characters for Login ID.");
		val.focus();
        return false;
	   }
   }
   return true;
}
//##################################################################################################################################
//===============================For deleting any contact person====================================================================
/*function ifdel(val)
{
  if(confirm("Delete this contact?"))
	{
		document.getElementById('contactid').value=val;
		alert(document.getElementById('contactid').value);
		alert(document.forms[0].name);
		//document.forms[0].submit();
	}
}*/

function ifdel(val,formName)
{
  if(confirm("Delete this contact?"))
	{
		document.getElementById('contactid').value=val;
		document.getElementById('contactlistfrm').submit();
		//document.formName.submit();
	}
}
//==============================================================================================================
function ShowNext(FormName, FieldNameArr, FieldCaptionArr, FieldActionArr,buttonnam)
{   
  
    if(IsNotEmpty(FormName, FieldNameArr, FieldCaptionArr, FieldActionArr)==true && buttonnam!='registration')
	{  
	    if(UploadValidRegFile(document.registerform))
		{
		document.getElementById('firstform').style.display='none';
		document.getElementById('nextform').style.display='block';
		}
	}

}
//===================================================================================================================
function AddTextBox(id1,id2,id3,id4,id5,buttonnam)
{
	if(document.getElementById(id1).style.display=='none')
	{
		document.getElementById(id1).style.display='block';
	}
	else if(document.getElementById(id2).style.display=='none')
	 {
		 document.getElementById(id2).style.display='block';
	 }
   else if(document.getElementById(id3).style.display=='none')
   {
	   document.getElementById(id3).style.display='block';
   }
   else if(document.getElementById(id4).style.display=='none')
   {
	   document.getElementById(id4).style.display='block';
   }
			
	else if(document.getElementById(id5).style.display=='none')
	{
		document.getElementById(buttonnam).style.display='none';
		document.getElementById(id5).style.display='block';
		
	}
	//document.getElementById(id1).style.display='block';
	
}

/*function AddTextBox(id1,id2,buttonnam)
{
	if(document.getElementById(id1).style.display=='block')
	{
		document.getElementById(buttonnam).style.display='none';
		document.getElementById(id2).style.display='block';
		
	}
	document.getElementById(id1).style.display='block';
	
}*/


function IsEmpty(doc,fname,countryName,email,userType,accountType,disabled)
{
	var Flag=0;
	var ArayLen=fname.length;
	for($Counter=0;$Counter<ArayLen;$Counter++)
	if(doc.fname[$Counter]!='First name' || doc.countryName[$Counter]!='country name' || doc.email[$Counter]!='email' || doc.userType[$Counter]!='userType' || doc.accountType[$Counter]!='accountType' || doc.disabled[$Counter]!='disabled')
	{
	   Flag=1;	
	}
	if(Flag!=1)
	{
		alert("Please enter complete details");	
		return false;
	}
	else 
		return true;
	
}


function Fetch(query,divId)
{
			
			
			/*var query="manufacturer.php?menufact="+document.ThisForm.devicetype.value;*/
		 	var chk;	
			
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			
			if(!xmlhttp && typeof ActiveXObject!="undefined")
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			//var url="check.php?username="+document.myform.username.value+"&password="+document.myform.password.value;
			xmlhttp.open('GET',query,false); 
			xmlhttp.setRequestHeader("Cache-Control","no-cache" );
			
			xmlhttp.onreadystatechange=function()
			{
				//alert(xmlhttp.readystate);
				if(xmlhttp.readystate==4 && xmlhttp.status==200)
				{
			 		 	
						if(xmlhttp.responseText!="")
			 			{
			 	
							
							var div=document.getElementById(divId);
							
							div.innerHTML=xmlhttp.responseText;
									
			 			}
						else
							Chk=0;
			 			
				}
			}
			
			xmlhttp.send(null);
			
}

function ClearSearchFields(FromTar)
{ 

	
	if(document.getElementById('fname'))
	{
		FromTar.fname.value='';
		FromTar.lname.value='';
		FromTar.company.value='';
		FromTar.job.value='';
	}

}

function CheckMesaageBox(val)
{
	if(Trimmer(val.value)=='')
	{
		alert("Please enter message.")
		return false;
	}
	else
		return true;
}

//=====================================================================
// ======Fuction to add dynamic rows in add invoice page===============
//=====================================================================
function AddInvRow()
 {
 	
	//var err=0;
			//alert(itemid);
			
			TC=document.getElementById('moreInvCount').value;
			//alert(TC);
			if(TC < 10)
			{
				document.getElementById('moreInvCount').value++;
			}
			if(TC > 9)
			{
				alert("Sorry, no more rows can be added.");
				return false;
			}
					document.getElementById('addmoreinvid').style.display='inline';
					TR=mainTable.insertRow();
					//alert(TR.rowIndex);
					TD=TR.insertCell();
					TD.colSpan=6;
				 sHTML=
					  '<table width="100%" border="0" cellspacing="0" cellpadding="0" align=center>'+
							'<tr>'+
							  '<td width="13%" align="center">'+
								  '<input name="stock[]" type="text" size="15" class="input" id="stock" maxlength="15" onBlur="return IsAlphaNum(this)">'+
								'</td>'+
							  '<td width="13%" align="center">'+
								  '<input name="year[]" type="text" size="15" class="input" id="year" maxlength="4" onBlur="return IsNum(this)">'+
								'</td>'+
							  '<td width="13%" align="center">'+
								  '<input name="make[]" type="text" size="15" class="input" id="make" maxlength="15" onBlur="return IsAlphaNum(this)">'+
								'</td>'+
							  '<td width="13%" align="center">'+
								  '<input name="model[]" type="text" size="15" class="input" id="model" maxlength="15" onBlur="return IsAlphaNum(this)">'+
								'</td>'+
							  '<td width="13%" align="center">'+
								  '<input name="vin[]" type="text" size="15" class="input" id="vin" maxlength="5" onBlur="return IsAlphaNum(this)">'+
								'</td>'+
							  '<td  align="center">'+
								  '<input type="file" name="invfilepath[]" id="invfilepath" class="input"><a style="cursor:hand" onClick="deleterecord(this)">&nbsp;Remove&nbsp;</a>'+
								'</td>'+
							
							'</tr>'+
					  '</table>';
				
				TD.insertAdjacentHTML("afterBegin",sHTML);  
	
 }

//===========================================================================================


 //===========================================================================================

function Checkall(frmvalue,val)
{
		//alert(frmvalue);
		//alert(val);
		//alert(frmvalue.getElementsByTagName('userchk').length);
			for(var nfi = 0; nfi < frmvalue.getElementsByTagName('input').length; nfi++) 
			{
				if(frmvalue.getElementsByTagName('input')[nfi].type=='checkbox')
				{
					frmvalue.getElementsByTagName('input')[nfi].checked=val;
				}
			}
		
}

// Function for validating fields in form of array





function Checkedall(frmvalue,val)
{
		//alert(frmvalue);
		//alert(val);
		//alert(frmvalue.getElementsByTagName('userchk').length);
			for(var nfi = 0; nfi < frmvalue.getElementsByTagName('input').length; nfi++) 
			{
				if(frmvalue.getElementsByTagName('input')[nfi].type=='checkbox')
				{
					frmvalue.getElementsByTagName('input')[nfi].checked=val;
					document.getElementById('disabled').checked= false
				}
			}
		
}







function CheckSubmitEntity(RecordCount,Field,Type)
   	{
		 
		 var Flag = 0; //keeps track that atleast one record is selected to change the status
		 var Counter = 0; 
		 if(RecordCount == 1)
		 { 
		     if(Field.checked==true)
			 {
			    Flag = 1;
			  }
			 else
			 {
			    Flag = 0;
			  } 
		 }	  	
		 else
		 {
		  	for (Counter=0; Counter < RecordCount; Counter++) 
			{
			  if(Field[Counter].checked == true)
				{
				   Flag = 1;
				   break;
				 }    
			  else
			   {
				 Flag = 0;
				}
			}  
			
		}
			
	     if(Flag == 0)
		 {
			 	
			if(Type == "delete")
			{
				alert("Please select at least one buyer to delete.");

			}
			if(Type == "enable")
			{
				alert("Please select at least one blacklist record to delete.");
			}
			if(Type == "disable")
			{
				alert("Please select at least one entity to disable.");
			}
			if (Type == 'approve')
			{
				alert("Please select at least one buyer to approve.");
			}			
		
			return false;
		 }
	else  
	return true;
  }	 

function ifapprove(val)
{

	 if(confirm("Do you really want to approve buyer?"))
	{
		//document.getElementById('entityID').value=val;
		document.forms[0].submit();
		return true;
	}
	else
	{
		return false;
	}
}

function ifdeleteentity(val)
{

	 if(confirm("Do you really want to delete buyer?"))
	{
		//document.getElementById('entityID').value=val;
		document.forms[0].submit();
		return true;
	}
	else
	{
		return false;
	}
}
function ifdeleteblacklist(val)
{

	 if(confirm("Do you really want to delete blacklist record?"))
	{
		//document.getElementById('entityID').value=val;
		document.forms[0].submit();
		return true;
	}
	else
	{
		return false;
	}
}

function UploadValidFiles(val)
{
	
   var error = 0;
   var message =''; 
  //================================================================================================ 
    if(val.value!="") // For invoice uploading
	 { 
       //check the extension of the uploaded file
       Ext=val.value.substring(val.value.lastIndexOf('.')+1);
	   Ext=Ext.toLowerCase();
	   
		 if(Ext =='pdf' || Ext=='doc' || Ext=='txt' || Ext=='htm' || Ext=='xls' || Ext=='ppt' || Ext=='html' || Ext=='msg' || Ext=='zip' || Ext=='rar')
		  {
		    
		  }
		  else
		  {
		  	error=1;
			message=message + "Please upload files in pdf,doc,txt,xls,ppt,html or msg format.\n";
		  }
	 }
 
	 if(error==1)
       {
	    val.value='';
		 alert(message);
		 val.focus();
		 return false;
	   }
	else
	  {
	     return true;
	   } 
 }
 


function search_content(val)
{
	if (val=='')
	{
		alert("please enter search criteria.");
		return false;
	}
	else
	{
		return true;
	}
}

function file_del_confirm()
{
	if (confirm("Do you really want to delete this file?"))
	{
		return true;
	}
	else
	{
		return false;
	}
}

