
//==============================================================================================================================
//=====================================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;
}
//======================================================================================================

//=============================================================================================================================
//=====================================================
//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;
}
//========================================================

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
{
	obj.value=obj.value.substring(0,mlength);
	alert("you can not enter more then "+ mlength +" characters");
}
}


function otherRegion(val)
{
	
	//document.write(val);
	if(val=='other')
	{
		document.getElementById('regionName').disabled=false;				
	}
	else
	{
		document.getElementById('regionName').disabled=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;
}
//==============================================================================================
//=============================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;
}

function IsWhiteSpaces(val) 
{
  if (val.value.length != 0)
   {
       for (i = 0; i < val.value.length; i++)
	   {
		   var ch = val.value.charAt(i);
		   if ((ch == " "))
		   {
              val.value='';
            alert("White spaces are not allowed.");
		    val.focus();
            return false;
            } 
		   else
		   {
		    continue;
           }
      }
  }

   return true;
}

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';
		}
	}

}

//Following variable are to be placed in mandatory variables javascript file


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




//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;
	}
	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-9]{2}-[0-1][0-9]-[1-9][0-9]{3}$/;
        if(longform.test(val.value))
		  {
		  		var DateArr = val.value.split("-");
				if(DateArr[0]> 31 || DateArr[1] >12)
					IsValid = 0;
				else
					IsValid = 1;
          }
		
				  if(IsValid == 0)
				  {
				  	
					  val.value='';
					  alert("Please Enter Date in a Valid Format");
					 val.focus();
					 return false;
				  }
   }
   
   return true;
}
//==============================================================================================
//..........................function for validation for only alphabetic values..................
function IsAlpha(val) 
{
  if (val.value.length != 0)
   {
       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;
           }
      }
  }

   return true;
}

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

function IsNum(val)
 {
   if (val.value.length != 0) 
    {
      for (i = 0; i < val.value.length; i++) 
	      {
              var ch = val.value.charAt(i);
              if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == "-")) 
		      {
                continue;
              } 
		      else
		      { 
		      val.value='';
              alert("Please enter numeric values.");
			  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)
{ 
	var Message = '';
	var FocusField = '';
	var Error = 0;
	var TotalFields = eval(FieldNameArr.length);
	//..........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;
	  
	 }
}
//********************************************************************************************************************//
var AddUsersFields  =  new Array("fname","lname","email","address","city","company","countryID","stateID","name","pass","repass");
var AddUsersAction  =  new Array("enter","enter","enter","enter","enter","enter","select","select","enter","enter","enter");
var AddUsersCaption =  new Array("first name","last name","email","address","city","company","countryName","state name","user name","password","retype password");
//********************************************************************************************************************//

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

//......function is used for checking all check boxes of status............................
function CheckAll(target,val,get_div)
{
 //alert(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)
   {
       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 == "/")|| (ch == "|")|| (ch == "\\"))
		   {
              continue;
            } 
		   else
		   {
		    val.value='';
            alert("Please enter valid value.");
		    val.focus();
            return false;
           }
      }
  }

   return true;
}
//======================================================================================================
//==============================For opening new window for viewing resume===============================
function openwindow(val)
 {
   urlstring='resumeview.php?id='+ val;
   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 =''; 
   
 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;
	   } 
 }
//=====================================================================================================
//===================for uploading file related to proper extensions for registration====================== 
/*function UploadValidRegFile(val)
{
   var error = 0;
   var message =''; 
  //================================================================================================ 
    if(val.resumepath.value!="") // For resume uploading
	 { 
       //check the extension of the uploaded file
       Ext=val.resumepath.value.substring(val.resumepath.value.lastIndexOf('.')+1);
	   Ext=Ext.toLowerCase();
	   
		 if(Ext!='doc' && Ext!='txt' && Ext!='xls' && Ext!='pdf')
		  {
		    error=1;
			message=message + "Please upload only doc,txt,xls format file for resume uploading.\n";
		  }
	 }
 
 //================================================================================================
 if(val.photopath.value!="") // For photo uploading
	 { 
      //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 for image uploading.\n";
		    
		  }
	 }
 
//================================================================================================= 
 if(val.logopath.value!="") // For logo image uploading
   {	   
	  Ext=val.logopath.value.substring(val.logopath.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 for logo image uploading.\n";
		  }
	}
		//..........reset values of education and experience..........................
			if(val.edu2.value!='' && val.edu1.value == ''){
				val.edu1.value = val.edu2.value;
				val.edu2.value = '';
			}
			if(val.edu1.value!='' && val.educationtemp.value == ''){
				val.educationtemp.value = val.edu1.value;
				val.edu1.value = '';
			}
			//....
			if(val.exp2.value!='' && val.experiencetemp[1].value == ''){
				val.experiencetemp[1].value = val.exp2.value;
				val.exp2.value = '';
			}
			if(val.experiencetemp[1].value!='' && val.experiencetemp[0].value == ''){
				val.experiencetemp[0].value = val.experiencetemp[1].value;
				val.experiencetemp[1].value = '';
			}
		//============================================================================
	    //....call RegArrayToString function to generate string....
		RegArrayToString(val);
	 if(error==1)
       {
	     alert(message);
		 return false;
	   }
	else
	  {
	     return true;
	   } 
 }*/
 
 
 function UploadValidRegFile(val)
{
   var error = 0;
   var message =''; 
  //================================================================================================ 
    if(val.resumepath.value!="") // For resume uploading
	 { 
       //check the extension of the uploaded file
       Ext=val.resumepath.value.substring(val.resumepath.value.lastIndexOf('.')+1);
	   Ext=Ext.toLowerCase();
	   
		 if(Ext!='doc' && Ext!='txt' && Ext!='xls' && Ext!='pdf')
		  {
		    error=1;
			message=message + "Please upload only doc,txt,xls format file for resume uploading.\n";
		  }
	 }
 
 //================================================================================================
 if(val.photopath.value!="") // For photo uploading
	 { 
      //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 for image uploading.\n";
		    
		  }
	 }
 
//================================================================================================= 
 if(val.logopath.value!="") // For logo image uploading
   {	   
	  Ext=val.logopath.value.substring(val.logopath.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 for logo image uploading.\n";
		  }
	}
		//..........reset values of education and experience..........................
			if(val.edu2.value!='' && val.edu1.value == '')
			{
				val.edu1.value = val.edu2.value;
				val.edu2.value = '';
			}
			if(val.edu1.value!='' && val.educationtemp.value == '')
			{
				val.educationtemp.value = val.edu1.value;
				val.edu1.value = '';
			}
			//....
			if(val.exp2.value!='' && val.exp1.value == '')
			{
				val.exp1.value = val.exp2.value;
				val.exp2.value = '';
			}
			if(val.exp1.value!='' && val.experiencetemp.value == ''){
				val.experiencetemp.value = val.exp1.value;
				val.exp1.value = '';
			}
		//============================================================================
	    //....call RegArrayToString function to generate string....
		RegArrayToString(val);
	 if(error==1)
       {
	     alert(message);
		 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";
		  }
	  }
	
	
 }
 
/* 
  function CheckValue(event,con,val,fun)
  {
     alert("ok");
    var imagesPath="images/";
	 if(con.value=='')
	   {
		  if(event.type=='blur')
		  {
		    con.value=val;
			con.className="InputCol";
			if(con.value == '')
				con.value = val;
			
		  }
		  else
		   {
			if(con.value == val)
				con.value = '';
		     con.className="TextCol"; 
		   }
	    }
	 else
	  {
		  //alert(event.type);
		  if(event.type=='blur')
		  {
		    con.value=val;
			con.className="InputCol";
			if(con.value == '')
				con.value = val;
			
		  }
		  else
		   {
			if(con.value == val)
				con.value = '';
		     con.className="TextCol"; 
		   }
	 	 if(con.value!=val)
		 {
			 fun(con);
		  }
		else
		  {
			con.value='';	
		  }
	  }
	
	
 }*/
 //######################################################################################################################
  //======================To check the check box whether it is checked or not============================================	
	function CheckSubmit(RecordCount,Field)
   	{
		 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)
		 {
			alert("Please select atleast one record to change the status.");
			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;	
		}
		
	}
}
//========================================================================================================================

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

function ValidateSearch(FormName, FieldNameArr, FieldCaptionArr, FieldActionArr)
{
	var Message = '';
	var FocusField = '';
	var Error = 0;
	var TotalFields = eval(FieldNameArr.length);
	    for(var Counter = 0; Counter < TotalFields; Counter++)
	    {
		
		    if(document.getElementById(FieldNameArr[Counter]).value == '')
		    {
	        Error++;
			}
		}
	
	if(TotalFields== Error)
	{
		alert('Please select atleast one search criteria.');
		return false;
	}
	else
	{
		setvalue(document.frmlist,document.frmlist.searchoption,'true');
			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 == ",") || (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 user name.");
		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 AddTextBoxAgain()
{
	document.getElementById('moreedu').style.display='none';	
	document.getElementById('education').style.display='block';	
}*/

/*var TextValue;
function NewreplaceTexts() 
{

	for(var q = 0; q < texts.length; q++) {
		texts[q].style.width = texts[q].size * 10 + 'px';
		txtLeft = document.createElement('img'); txtLeft.src = imagesPath + "input_left.gif"; txtLeft.className = "inputCorner";
		txtRight = document.createElement('img'); txtRight.src = imagesPath + "input_right.gif"; txtRight.className = "inputCorner";
		texts[q].parentNode.insertBefore(txtLeft, texts[q]);
		texts[q].parentNode.insertBefore(txtRight, texts[q].nextSibling);
		texts[q].className = "textinput";

		//create hovers
		texts[q].onfocus = function() {
			this.className = "textinputHovered";
			this.previousSibling.src = imagesPath + "input_left_xon.gif";
			this.nextSibling.src = imagesPath + "input_right_xon.gif";
			
		    TextValue=this.value;
			if(this.title == this.value)		    
				this.value='';		
			}
		texts[q].onblur = function() {
			this.className = "textinput";
			this.previousSibling.src = imagesPath + "input_left.gif";
			this.nextSibling.src = imagesPath + "input_right.gif";
			
			if(this.value=='')
				if(TextValue!=this.title)
					this.value=this.title;
		}
	}
}*/

function IsEmpty(doc,fname,lname,email)
{
	var Flag=0;
	var ArayLen=fname.length;
	for($Counter=0;$Counter<ArayLen;$Counter++)
	if(doc.fname[$Counter]!='First name' && doc.lname[$Counter]!='Last name' && doc.email[$Counter]!='email')
	{
	   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);
			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><div align="center">'+
						  '<input name="stock1[]" type="text" size="15" maxlength="15">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input name="year1[]" type="text" size="15" maxlength="4">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input name="make1[]" type="text" size="15" maxlength="15">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input name="model1[]" type="text" size="15" maxlength="15">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input name="vin1[]" type="text" size="15" maxlength="5">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input type="file" name="invfilepath1[]">'+
						'</div></td>'+
					'</tr>'+
			  '</table>';
			  
		 
		
		TD.insertAdjacentHTML("afterBegin",sHTML);  
	
 }

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

function deleterecord(tr)
 {
	//alert(tr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex);
	
	tr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.deleteRow(tr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex);
	    //TR=mainTable.deleteRow(tr);
 		//TD=TR.deleteCell()
 		//TD.colSpan=7;
 }



/****************************************Pradeep Singh**************************************/
var uploadvideosField = new Array("title","description","channel_id[]","keyword","videopath");
var uploadvideosAction = new Array("enter","enter","select","enter","select");
var uploadvideosCaption = new Array("title","description","video channel","tags","file");
/*******************************************************************************************/
/****************************************Pradeep Singh**************************************/
function UploadValidFiles(val)
{ 

   var error = 0;
   var message =''; 
   var j='';
  
 if(val.videopath.value!="")
	 { 
       //check the extension of the uploaded file
       Ext=val.videopath.value.substring(val.videopath.value.lastIndexOf('.')+1);
	   Ext=Ext.toLowerCase();
	   

	  
		 if(Ext!='flv' && Ext!='wmv' && Ext!='mov' && Ext!='mpg' && Ext!='avi' && Ext!='m4v')
		  {
		    error=1;
			message=message + "Please upload only flv,wmv,mov,mpg,avi,m4v format file.\n";
		     
		  }
	 }
     
	 if(error==1)
       {
	   val.videopath.focus();
		   
	     alert(message);
		 return false;
	   }
	else
	  {
	     return true;
	   } 
 }

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