/********************************************************************* 
* ValidateData.js.                                                     *
* Form validation functions for validating entire forms (onSubmit)     *
* or on-the-fly validation. (onBlur / onChange)                        *
* Copyright 2004 SunArc Technologies Pvt.Ltd.                          *
*********************************************************************/

// Functions for onSubmit form validation.

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;
}


function BisAlpha(val, len, req) {
// Check for "a-z", "A-Z", " ", and optionally length.
   if ((val.value.length == 0) && (req == "R")) {
      alert("This field is required.");
      val.focus();
      val.select();
      return false;
   }
   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 >= "0" && ch <= "9")) {
            continue;
         } else {
            alert("Please enter only alphabets");
            val.focus();
            val.select();
            return false;
         }
      }
      if (len != "0") {
         if (val.value.length != len) {
            alert("This field must contain " + len + " alphabets characters.");
            val.focus();
            val.select();
            return false;
         }
      }
   }
   return true;
}

//function to trim a string
function Trimmer(controlName) { 
	pVal = controlName.value;
    TRs=0; 
    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;} 
    } 

    controlName.value=pVal.substr(TRs, TRe-TRs+1); 
} 
//end trim function

function BisURL(val, req) {
// Check for a properly formatted url.
   if ((val.value.length == 0) && (req == "R")) {
      alert("This field is required.");
      val.focus();
      val.select();
      return false;
   }
   var email = val.value.toLowerCase();
   var checkemail="";
    if (val.value.length >11) 
     {
	    	
		if(email.substring(0,11) == 'http://www.')
	   		checkemail = email.substring(11, email.length);
	

		var emailformat = /^(([-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(checkemail)) {
         alert("Please enter a valid URL.");
         val.focus();
         val.select();
         return false;
      }
   }
	val.value=email;
   return true;
}

// function for checking that field is number
function BisNumber(val,req) {
// Check for "0-9", ".", "-", and optionally length.
   if ((val.value.length == 0) && (req == "R")) {
      alert("This field is required.");
      val.focus();
      val.select();
      return false;
   }
   if (val.value.length != 0) {
      for (i = 0; i < val.value.length; i++) {
         var ch = val.value.charAt(i);
         if ((ch >= "0" && ch <= "9")) {
            continue;
         } else {
            alert("Please enter numeric characters [0-9] only.");
            val.focus();
            val.select();
            return false;
         }
      }
   }
   return true;
}

// function for checking that field is number with dot
function BisNumberDot(val,req) {
// Check for "0-9", ".", "-", and optionally length.
  var Dotcount=0;
   if ((val.value.length == 0) && (req == "R")) {
      alert("This field is required.");
      val.focus();
      val.select();
      return false;
   }
   if (val.value.length != 0) {
      for (i = 0; i < val.value.length; i++) {
         var ch = val.value.charAt(i);
		 if(ch == ".")
		 {
		   Dotcount=Dotcount +1;
		   if(Dotcount>1)
		     {
              alert("Please enter valid numeric value.");
				val.focus();
				val.select();
				return false;
			 }
		 continue;
		 }
         if ((ch >= "0" && ch <= "9"))
		  {
            continue;
         } else {
            alert("Please enter valid numeric value.");
            val.focus();
            val.select();
            return false;
         }
      }
      /*if (len != "0") {
         if (val.value.length != len) {
            alert("This field must contain " + len + " NUMERIC characters.");
            val.focus();
            val.select();
            return false;
         }
      }*/
   }
   return true;
}



//-----------------------------------------------------
//function for date
//compare date
function DateComparison(date1, date2)
{
   var d1,d2,m1,m2,y1,y2;
    var fromdate=date1.split('-');
   var todate=date2.split('-');   
   
   d1=eval(fromdate[0]);
   d2=eval(todate[0]);
   m1=eval(fromdate[1]);
   m2=eval(todate[1]);
   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)
		{
			return false;
		}
		else
		{
			if(m2>m1)
			{
				return true;
			}
			else
			{
				if(m1>m2)
				{
					return false;
				}
				else
				{
					if(d2>=d1)
					{
						return true;
					}
					else
					{
						return false;
					}
				}
			}
		}
	}   
 }
 
 //compare date
function CheckNewDate(thedate)
{
   var d1,d2,m1,m2,y1,y2;
   var newdate=new Date();
   
   d1=eval(thedate.substring(0,2));
   d2=eval(newdate.getDate());
   m1=eval(thedate.substring(3,5));
   m2=eval(newdate.getMonth())+1;
   y1=eval(thedate.substring(6,10));
   y2=eval(newdate.getYear());
   
  
   //return true if second is greater  or equal to first date
   	if (y1 > y2)
	{
   		return true;
	}
	else
	{
		if(y1 < y2)
		{
			return false;
		}
		else
		{
			if(m1 > m2)
			{
				return true;
			}
			else
			{
				if(m2 > m1)
				{
					return false;
				}
				else
				{
					if(d1 >= d2)
					{
						return true;
					}
					else
					{
						return false;
					}
				}
			}
		}
	}   
 }
   
function CheckDate(thedate,newdate)
{
   var d1,d2,m1,m2,y1,y2;
   
   d1=eval(thedate.substring(0,2));
   d2=eval(newdate.substring(0,2));
   m1=eval(thedate.substring(3,5));
   m2=eval(newdate.substring(3,5));
   y1=eval(thedate.substring(6,10));
   y2=eval(newdate.substring(6,10));
   
  
   //return true if second is greater  or equal to first date
   	if (y1 > y2)
	{
   		return true;
	}
	else
	{
		if(y1 < y2)
		{
			return false;
		}
		else
		{
			if(m1 > m2)
			{
				return true;
			}
			else
			{
				if(m2 > m1)
				{
					return false;
				}
				else
				{
					if(d1 >= d2)
					{
						return true;
					}
					else
					{
						return false;
					}
				}
			}
		}
	}   
 }
   

//============================================================   
//validate the Article form 
//============================================================
function Validate_ArticleForm(val)
{

var error=0;
var message='';

/*  if(val.authname.value=="")
    {
        if(error==0)
		 val.authname.focus();
       message=message+" Please enter your name. \n";
	   error=1;
	}
  
  if(val.email.value=="")
    {
        if(error==0)
	       val.email.focus();
       message=message+" Please enter your email id. \n";
	   error=1;
	}
  
  if(val.profession.value=="")
    {
        if(error==0)
	       val.profession.focus();
       message=message+" Please enter your profession. \n";
	   error=1;
	}
  */
  if(val.title.value=="")
    {
        if(error==0)
	       val.title.focus();
       message=message+" Please enter article title. \n";
	   error=1;
	}
  
  if(val.artcatid.value=="")
    {
        if(error==0)
	       val.artcatid.focus();
       message=message+" Please select article subject. \n";
	   error=1;
	}
  
if(val.name=='articlefrm' )
{
  if(val.article.value=="")
    {
        if(error==0)
	       val.article.focus();
       message=message+" Please upload article file. \n";
	   error=1;
	}
}	
	if(val.article.value!="")
	 { 
//check the extension of the uploaded file
     Ext=val.article.value.substring(val.article.value.lastIndexOf('.')+1);
	 Ext=Ext.toLowerCase();
		 if(Ext!='doc' && Ext!='pdf' && Ext!='txt' && Ext!='htm' && Ext!='html')
		  {
			error=1;
			message=message + "Please upload only doc,txt,pdf,html format file.\n";
		  }
	 }

 //display message on error

 if(error==1)
   {
    alert(message);
	return false;
   
   }

return true;
}   
//============================================================   
//============================================================
/*****************************************************************
		FUNCTIONFOR CHECKING THE EXTENTION
/*****************************************************************/
function checkExt(val,ext)
{
var error=0;
var message='';
	//	alert(document.newfrm.importlist.value + "asdasda");
	

	if(error==0)
	{
	if(document.newfrm.importlist.value=="")
	{
			error=1;
			message="Please choose a file to be uploaed.\n";
	}
	}
	if(document.newfrm.importlist.value!="")
	 { 

//check the extension of the uploaded file
	 Ext=document.newfrm.importlist.value.substring(document.newfrm.importlist.value.lastIndexOf('.')+1);
	 Ext=Ext.toLowerCase();
		 if(Ext!=ext)
		  {
			error=1;
			message="Please upload only "+ext+" format file.\n";
		  }
	 }
	 
 if(error==1)
   {
    alert(message);
	return false;
   }

return true;
}   
//============================================================   
//validate the BOOKS form 
//============================================================
function Validate_BookForm(val)
{

var error=0;
var message='';

  if(val.author.value=="")
    {
        if(error==0)
		 val.author.focus();
       message=message+" Please enter author name. \n";
	   error=1;
	}
  
  if(val.publisher.value=="")
    {
        if(error==0)
	       val.publisher.focus();
       message=message+" Please enter the publisher name. \n";
	   error=1;
	}
  
  if(val.price.value=="")
    {
        if(error==0)
	       val.price.focus();
       message=message+" Please enter the book price. \n";
	   error=1;
	}
  
  if(val.title.value=="")
    {
        if(error==0)
	       val.title.focus();
       message=message+" Please enter book title. \n";
	   error=1;
	}
  
  if(val.bookcatid.value=="")
    {
        if(error==0)
	       val.bookcatid.focus();
       message=message+" Please select book subject. \n";
	   error=1;
	}
  
if(val.name=='book' )
{
  if(val.book.value=="")
    {
        if(error==0)
	       val.book.focus();
       message=message+" Please upload book file. \n";
	   error=1;
	}
}	
  if(val.detail.value=="")
    {
        if(error==0)
	       val.detail.focus();
       message=message+" Please enter the book detail. \n";
	   error=1;
	}

	if(val.book.value!="")
	 { 
//check the extension of the uploaded file
     Ext=val.book.value.substring(val.book.value.lastIndexOf('.')+1);
	 Ext=Ext.toLowerCase();
		 if(Ext!='zip' && Ext!='pdf' && Ext!='htm' && Ext!='html' && Ext!='chm' && Ext!='doc')
		  {
			error=1;
			message=message + "Please upload only pdf,zip,html,chm,doc format file.\n";
		  }
	 }

 //display message on error

 if(error==1)
   {
    alert(message);
	return false;
   
   }

return true;
}   
//============================================================   
//validate the Glossary  form 
//============================================================
function Validate_GlossaryForm(val)
{

var error=0;
var message='';

  if(val.title.value=="")
    {
        if(error==0)
	       val.title.focus();
       message=message+" Please enter the word. \n";
	   error=1;
	}
  
  if(val.detail.value=="")
    {
        if(error==0)
	       val.detail.focus();
       message=message+" Please enter the detail. \n";
	   error=1;
	}
  
 if(error==1)
  {
    alert(message);
	 return false;
  }
 return true; 
}

//============================================================   
//validate the DOWNLOAD form 
//============================================================
function Validate_DownloadForm(val)
{

var error=0;
var message='';

  if(val.title.value=="")
    {
        if(error==0)
	       val.title.focus();
       message=message+" Please enter downloads title. \n";
	   error=1;
	}
  
  if(val.downloadcatid.value=="")
    {
        if(error==0)
	       val.downloadcatid.focus();
       message=message+" Please select download subject. \n";
	   error=1;
	}
  
if(val.name=='download' )
{
  if(val.download.value=="")
    {
        if(error==0)
	       val.download.focus();
       message=message+" Please upload download file. \n";
	   error=1;
	}
}	
  if(val.detail.value=="")
    {
        if(error==0)
	       val.detail.focus();
       message=message+" Please enter the downloads detail. \n";
	   error=1;
	}

	if(val.download.value!="")
	 { 
//check the extension of the uploaded file
     Ext=val.download.value.substring(val.download.value.lastIndexOf('.')+1);
	 Ext=Ext.toLowerCase();
		 if(Ext!='zip' && Ext!='pdf' && Ext!='chm' && Ext!='exe')
		  {
			error=1;
			message=message + "Please upload only pdf,zip,chm,exe format file.\n";
		  }
	 }

 //display message on error

 if(error==1)
   {
    alert(message);
	return false;
   
   }

return true;
}   
//============================================================   
//============================================================   
//validate the upload form (game,tutorial,hot topics) 
//============================================================
function Validate_UploadForm(val)
{

var error=0;
var message='';

  if(val.title.value=="")
    {
        if(error==0)
	       val.title.focus();
       message=message+" Please enter the title. \n";
	   error=1;
	}
  
  if(val.subcatid.value=="")
    {
        if(error==0)
	       val.subcatid.focus();
       message=message+" Please select the subject. \n";
	   error=1;
	}
  
if(val.name=='upload' )
{
  if(val.upfile.value=="")
    {
        if(error==0)
	       val.upfile.focus();
       message=message+" Please upload the file. \n";
	   error=1;
	}
}	
  if(val.detail.value=="")
    {
        if(error==0)
	       val.detail.focus();
       message=message+" Please enter the detail. \n";
	   error=1;
	}

	if(val.upfile.value!="")
	 { 
//check the extension of the uploaded file
     Ext=val.upfile.value.substring(val.upfile.value.lastIndexOf('.')+1);
	 Ext=Ext.toLowerCase();
		 if(Ext!='jar' && Ext!='html' && Ext!='pdf' && Ext!='htm' && Ext!='zip' &&  Ext!='exe' && Ext!='doc')
		  {
			error=1;
			message=message + "Please upload only pdf,zip,jar,html,exe format file.\n";
		  }
	 }

 //display message on error

 if(error==1)
   {
    alert(message);
	return false;
   
   }

return true;
}   
//============================================================   

//============================================================   
//validate the JOBFORM form 
//============================================================
function Validate_JobForm(val)
{

var error=0;
var message='';

  if(val.title.value=="")
    {
        if(error==0)
	       val.title.focus();
       message=message+" Please enter job title. \n";
	   error=1;
	}
  
  if(val.jobcatid.value=="")
    {
        if(error==0)
	       val.jobcatid.focus();
       message=message+" Please select job field. \n";
	   error=1;
	}
  if(val.expiredate.value=="")
    {
        if(error==0)
	       val.expiredate.focus();
       message=message+" Please enter/select the job close date . \n";
	   error=1;
	}
	
  if(val.summary.value=="")
    {
        if(error==0)
	       val.summary.focus();
       message=message+" Please enter the job summary. \n";
	   error=1;
	}
if(val.jobfile.value!="")
	 { 
//check the extension of the uploaded file
     Ext=val.download.value.substring(val.download.value.lastIndexOf('.')+1);
	 Ext=Ext.toLowerCase();
		 if(Ext!='txt' && Ext!='pdf' && Ext!='doc' )
		  {
			error=1;
			message=message + "Please upload only pdf,txt,doc format file.\n";
		  }
	 }
 //compare that
  if(CheckNewDate(val.expiredate.value)==false && val.expiredate.value!="")
  {
    message=message + "Close date must be greater than current date";
  } 

 //display message on error

 if(error==1)
   {
    alert(message);
	return false;
   
   }

return true;
}   
//============================================================   
/////////////////======PROJECT FORM============/////////////
function Validate_ProjectForm(val,type)
{	var error=0;
	var message='';

if(type=='')
	{
	
	if(val.projectname.value=="")
		{
			if(error==0)
			 val.projectname.focus();
		   message=message+" Please enter project name. \n";
		   error=1;
		}
	  
	  if(val.client.value=="")
		{
			if(error==0)
			   val.client.focus();
		   message=message+" Please enter client name. \n";
		   error=1;
		}
	  
	  if(val.company.value=="")
		{
			if(error==0)
			   val.company.focus();
		   message=message+" Please enter company name. \n";
		   error=1;
		}
	  if(val.schestadate.value=="")
		{
			if(error==0)
			   val.schestadate.focus();
		   message=message+" Please enter scheduled start date. \n";
		   error=1;
		}
	  
	
	
	  if(val.protype.value=="")
		{
			if(error==0)
			   val.protype.focus();
		   message=message+" Please select project type. \n";
		   error=1;
		}
		  if(val.proleader.value=="")
		{
			if(error==0)
			   val.proleader.focus();
		   message=message+" Please select project leader name. \n";
		   error=1;
		}
		
	  if(val.selected.options.length==0)
		{
			if(error==0)
			   val.selected.focus();
		   message=message+" Please select project team. \n";
		   error=1;
		}
	if(val.name=='projectfrm' )
	{
	  if(val.project.value=="")
		{
			if(error==0)
			   val.project.focus();
		   message=message+" Please upload project document file. \n";
		   error=1;
		}
	}	
		if(val.project.value!="")
		 { 
	//check the extension of the uploaded file
		 Ext=val.project.value.substring(val.project.value.lastIndexOf('.')+1);
		 Ext=Ext.toLowerCase();
			 if(Ext!='doc' && Ext!='pdf' && Ext!='txt' && Ext!='htm' && Ext!='html')
			  {
				error=1;
				message=message + "Please upload only doc,txt,pdf,html format file.\n";
			  }
		 }

}
else
{
  
  if(val.schestadate.value=="")
    {
        if(error==0)
	       val.schestadate.focus();
       message=message+" Please enter actual start date. \n";
	   error=1;
	}
	  if(val.proleader.value=="")
    {
        if(error==0)
	       val.proleader.focus();
       message=message+" Please select project leader name. \n";
	   error=1;
	}
	
  if(val.selected.options.length==0)
    {
        if(error==0)
	       val.selected.focus();
       message=message+" Please select project team. \n";
	   error=1;
	}
if(val.name=='projectfrm' )
{
  if(val.project.value=="")
    {
        if(error==0)
	       val.project.focus();
       message=message+" Please upload project document file. \n";
	   error=1;
	}
}	
	if(val.project.value!="")
	 { 
//check the extension of the uploaded file
     Ext=val.project.value.substring(val.project.value.lastIndexOf('.')+1);
	 Ext=Ext.toLowerCase();
		 if(Ext!='doc' && Ext!='pdf' && Ext!='txt' && Ext!='htm' && Ext!='html')
		  {
			error=1;
			message=message + "Please upload only doc,txt,pdf,html format file.\n";
		  }
	 }
} //display message on error
//alert(val.selected.options.length);

 //temp=document.getElementById("teammembers");
//  temp=val.teammembers;
 //alert(temp);
 var temp=new Array();
for (var i = 0; i < val.selected.options.length; i++)
{
  temp[i]=val.selected.options[i].value;
}
document.getElementById("teammembers").value=temp;
 if(error==1)
   {
    alert(message);
	return false;
   }
	   
return true;


}   
//============================================================   
/////////////////======DAILY REPORT FORM============/////////////
function Validate_ReportForm(val,Index)
{
var error=0;
var message='';

//return false;
if(Index==1)
{	
	  if(val.projectid.value=="")
		{ 	
			if(error==0)
			   val.projectid.focus();
		   message=message+" Please select project name. \n";
		   error=1;
		}
	  if(val.priority.value=="")
		{
			if(error==0)
			   val.priority.focus();
		   message=message+" Please select priority. \n";
		   error=1;
		}
	  
	  if(val.fromtime.value=="")
		{
			if(error==0)
			   val.fromtime.focus();
		   message=message+" Please specify start time. \n";
		   error=1;
		}
	  
	  if(val.totime.value=="")
		{
			if(error==0)
			   val.totime.focus();
		   message=message+" Please specify end time. \n";
		   error=1;
		}
		if(val.description.value=="")
		{
	  if(error==0)
			 val.description.focus();
		   message=message+" Please enter work description. \n";
		   error=1;
		}
}
else
{
	for(i=0;i<Index;i++)
	{
	  if(val.priority[i].value=="")
		{
			if(error==0)
			   val.priority[i].focus();
		   message=message+" Please select priority for detail "+(i+1)+".\n";
		   error=1;
		}
	  
	  if(val.projectid[i].value=="")
		{      alert();
	
			if(error==0)
			   val.projectid[i].focus();
		   message=message+" Please select project name for detail "+(i+1)+".\n";
		   error=1;
		}
	  if(val.fromtime[i].value=="")
		{
			if(error==0)
			   val.fromtime[i].focus();
		   message=message+" Please specify start time for detail "+(i+1)+".\n";
		   error=1;
		}
	  
	  if(val.totime[i].value=="")
		{
			if(error==0)
			   val.totime[i].focus();
		   message=message+" Please specify end time for detail "+(i+1)+".\n";
		   error=1;
		}
		if(val.description[i].value=="")
		{
	  if(error==0)
			 val.description[i].focus();
		   message=message+" Please enter work description for detail "+(i+1)+".\n";
		   error=1;
		}
	  

		if(message!='')
			break;
	}
}
	 //display message on error
	val.totalRec.value=Index;

 if(error==1)
   {
    alert(message);
	return false;
   
   }

return true;
}   


function Validate_FutureReportForm(val)
{
var error=0;
var message='';


if(val.projectid.value=="")
{ 

	if(error==0)
	   val.projectid.focus();
   message=message+" Please select project name. \n";
   error=1;
}
if(val.priority.value=="")
{
	if(error==0)
	   val.priority.focus();
   message=message+" Please select priority. \n";
   error=1;
}
if(val.schestadate.value=="")
{
	if(error==0)
	   val.schestadate.focus();
	 
   message=message+" Please select schedule date. \n";
   error=1;
}
else if(CheckDate(val.enterdate.value,val.schestadate.value))
{
   message=message+" Please select schedule date greater than current date. \n";
   error=1;
}
if(val.fromtime.value=="")
{
	if(error==0)
	   val.fromtime.focus();
   message=message+" Please specify start time. \n";
   error=1;
}

if(val.totime.value=="")
{
	if(error==0)
	   val.totime.focus();
   message=message+" Please specify end time. \n";
   error=1;
}
if(val.description.value=="")
{
if(error==0)
	 val.description.focus();
   message=message+" Please enter work description. \n";
   error=1;
}


 if(error==1)
   {
    alert(message);
	return false;
   
   }

return true;

}

function Validate_AddMOMForm(val)
{
var error=0;
var message='';


if(val.schestadate.value=="")
{
	if(error==0)
	   val.schestadate.focus();
	 
   message=message+" Please select date. \n";
   error=1;
}
else if(CheckDate(val.schestadate.value,val.enterdate.value))
{
   message=message+" Please select date less than current date. \n";
   error=1;
}
if(val.projectid.value=="")
{      alert();

	if(error==0)
	   val.projectid.focus();
   message=message+" Please select project name. \n";
   error=1;
}
if(val.members.value=="")
{
if(error==0)
	 val.members.focus();
   message=message+" Please enter members in meeting. \n";
   error=1;
}

if(val.description.value=="")
{
if(error==0)
	 val.description.focus();
   message=message+" Please enter work description. \n";
   error=1;
}


 if(error==1)
   {
    alert(message);
	return false;
   
   }

return true;

}
//============================================================      
//=======FUNCTION FOR VALIDATE CHAGEPASSWORD FORM=============      
function Validate_Changepass_Form(val)
{
  var error=0;
  var message='';
  if(val.oldpassword.value=="")
    {
       val.oldpassword.focus();
       message=message+" Please enter the password. \n";
	   error=1;
	}
  if(val.newpassword.value=="")
    {
        if(error==0)
		 val.newpassword.focus();
       message=message+" Please enter the newpassword. \n";
	   error=1;
	}
  if(val.confirmpassword.value=="")
    {
        if(error==0)
		 val.confirmpassword.focus();
       message=message+" Please confirm the new password. \n";
	   error=1;
	}
	//check that newpassword and confirm password values are same or not
	if(val.confirmpassword.value!="" && val.confirmpassword.value!=val.newpassword.value)
	 {
		if(error==0)
			 val.confirmpassword.focus();
		   message=message+" Confirm password not match with new password.\n";
		   error=1;
		 
	 }
	 


	if(error==1)
	{
	 alert(message);
	 return false;
	}
	return true;

}
//=======FUNCTION FOR VALIDATE CHAGEPASSWORD FORM=============     
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

function Validate_Changepass_Form_UserInfo(val)
{
  var error=0;
//  var str= new String();
  var message='';
  var found = 0;
  	if(val.password.value!="" && val.cpassword.value=="")
    	{
        if(error==0)
		 val.cpassword.focus();
       message=message+" Please confirm the new password. \n";
	   error=1;
	}

	//check that newpassword and confirm password values are same or not
	if(val.cpassword.value!="" && val.cpassword.value!=val.password.value)
	 {
		if(error==0)
			 val.cpassword.focus();
		   message=message+" Confirm password not match with new password.\n";
		   error=1;
		 
	 }
	 
	 if(val.mobile.value!="" )
	 {
		if(! alphanumeric(val.mobile.value))
		{
			val.mobile.focus();
			message=message+" You can enter only characters and numbers (12 characters max).\n";
		   error=1;
		}
		if(val.mobile.value.length > 12)
		{	 
		   val.mobile.focus();
		   message=message+" You can enter 12 characters max.\n";
		   error=1;
		}
		 
	 }

	if(error==1)
	{
	 alert(message);
	 return false;
	}
	return true;

}
	
//============================================================         
 //function for redirecting the page   

function valid_login_admin(val)
{
  var error=0;
  var message='';
  if(val.loginid.value=="")
    {
       val.loginid.focus();
       message=message+" Please enter the loginid. \n";
	   error=1;
	}
  if(val.password.value=="")
    {
        if(error==0)
		 val.password.focus();
       message=message+" Please enter the password. \n";
	   error=1;
	}
if(error==1)
 {
  alert(message);
   return false;
 }	
   return true;

}


//============================================================         
   
//function for redirecting the page   

function CallPage(PageName)
{
	
	location.href = PageName;
}
//============================================================    
//function for pagination
//============================================================  

//THIS IS SetPageCounter() FUNCTION TO INCREASE VALUE OF PAGE COUNTER
function SetPageCounterInc()
{
	//document.enableurl.PageCounter.value = document.enableurl.PageCounter.value +1;
	document.FormPage.PageCounter.value = eval(document.FormPage.PageCounter.value) + 1  ;
	document.FormPage.submit();
}
			
	//function to send form to the next page
function NextPageLink(val)
{
		document.FormPage.PageCounter.value = eval(val)  ;
		document.FormPage.submit();
}
		
//THIS IS SetPageCounter() FUNCTION TO DECREASE VALUE OF PAGE COUNTER
function SetPageCounterDec()
{
	document.FormPage.PageCounter.value = eval(document.FormPage.PageCounter.value) - 1  ;
	document.FormPage.submit();
}

 
//============================================================    
/*function DomainCheck(val)
{
 
// Check for a properly formatted url.
   
   var email = val.value.toLowerCase();
   var checkemail="";
    if (val.value.length >0) 
     {
	    if(val.value.substr(0,4)=='www.')
		 {
		   alert("Please don't prefix * www * in domain name ");
		    val.focus();
            val.select();
		    return false;
		 }
		
		var emailformat = /^(([-a-z0-9])+(.com|.net|.edu|.org|.gov|.mil|.int|.biz|.pro|.info|.arpa|.aero|.coop|.name|.museum|(\.{1}+[a-z]{2})+((\.{1}+[a-z]{2,3})))+(|(\.{1}+[a-z]{2,3})))$/;
		//var emailformat = /^(([-a-z0-9])+(|(\.{1}+[a-z]{2})|.com|.net|.edu|.org|.gov|.mil|.int|.biz|.pro|.info|.arpa|.aero|.coop|.name|.museum)+(|(\.{1}+[a-z]{2,3})))$/;
		//var emailformat = /^(([-a-z0-9])+(|.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 domain name.");
         val.focus();
         val.select();
         return false;
      }
   }
	val.value=email;
   return true;


}*/

//=====================================================================================

//this is CheckSubmit() function to check whether any record is selected or not
function CheckSubmit(RecordCount, theField, OldStatusValue, ChangedStatus)
{
	
	var statusFlag = 0; //keeps track that atleast one record is selected to change the status
	
	if(RecordCount.value == 1)
	{ 
		if(theField.checked == true && OldStatusValue.value != ChangedStatus)
				statusFlag = 1;
			else
				theField.checked = false;
	}
	else
	{
		for (i=0; i < RecordCount.value; i++) 
		{
			alert(OldStatusValue[i].value);
			if(theField[i].checked == true && OldStatusValue[i].value != ChangedStatus)
				statusFlag = 1;
			else
				theField[i].checked = false;
		}
	}
				return false;	

	if(statusFlag == 0)
	{
		alert("Please select atleast one record to change status.");
		return false;
	}
//on delete button click confirm for deletion
	if(ChangedStatus=='D')
	 {
	  result=confirm('Are u sure? \n It will delete all  its related entries.');
	  if(!result)
	   return false;
	 
	 }


	return true;
}

// function for ordering 
function OrderFunction(orderstr,type)
{
	//alert(orderstr + type);
    document.FormPage.order.value = "order by " + orderstr +" " + type ;
	document.FormPage.submit();
}
/***************************************************************/
//THIS IS CheckAll() FUNCTION TO MARK ALL CHECK BOXES AS CHECKED---USED IN FORM ENABLE URL
function CheckAll(count,val)
{
	
	
	if(count == 1)
	{ 
		val.checked = true;
	}
	else
	{
		for (i=0; i < count; i++) 
		{
			val[i].checked = true;
		}
	}
}
//THIS IS UnCheckAll() FUNCTION TO MARK ALL CHECK BOXES AS  UNCHECKED--USED IN FORM ENABLE URL
function UnCheckAll(count,val)
{

	if(count == 1)
	{ 
		val.checked = false;
	}
	else
	{
		for (i=0; i < count; i++) 
		{
			val[i].checked = false;
		}
	}
}
// function for ordering 

///function for both check uncheclk
//THIS IS CheckAll() FUNCTION TO MARK ALL CHECK BOXES AS CHECKED---USED IN FORM ENABLE URL
function CheckUncheckAll(count,val)
{
	

var cuflag=false;
	if(count == 1)
	{ 
		if(val.checked)
		  val.checked =false;
		 else 
		    val.checked = true;
	}
	else
	{
		
		for (i=0; i < count; i++) 
		{//	alert(count);

		   
		   if(val[i].checked)
		      cuflag=true;
		}
		//UPDATE THE STATUS
		for (i=0; i < count; i++) 
		{
		   if(cuflag)
		      val[i].checked=false;
		   else
		      val[i].checked=true;
		}
	}
}



//=============================================================================

//validate config settings
function valid_configsetting(form)
{
   var message="", error=0;
	var FocusField = '';

   if (form.title.value=='') { message+="Please enter title.\n"; error=1;   if(FocusField == '')FocusField =form.title;}
   if (form.mailfooter.value=='') { message+="Please enter mail footer.\n"; error=1;   if(FocusField == '')FocusField =form.mailfooter;}

  if (form.emailadv.value=='') { message+="Please enter advertisement email account.\n"; error=1;   if(FocusField == '')FocusField =form.emailadv;}
  if (form.subjectadv.value=='') { message+="Please enter advertisement email subject.\n"; error=1;   if(FocusField == '')FocusField =form.subjectadv;}
  if (form.messageadv.value=='') { message+="Please enter advertisement email message.\n"; error=1;   if(FocusField == '')FocusField =form.messageadv;}

   if (form.emailtellfriend.value=='') { message+="Please enter tell a friend email account.\n"; error=1;   if(FocusField == '')FocusField =form.emailtellfriend;}
   if (form.subjecttellfriend.value=='') { message+="Please enter tell a friend email subject.\n"; error=1;   if(FocusField == '')FocusField =form.subjecttellfriend;}
   if (form.messagetellfriend.value=='') { message+="Please enter tell a friend email message.\n"; error=1;   if(FocusField == '')FocusField =form.messagetellfriend;}

   if (form.emailmember.value=='') { message+="Please enter confirm member Id email account.\n"; error=1;   if(FocusField == '')FocusField =form.emailmember;}
   if (form.subjectmember.value=='') { message+="Please enter comfirm member Id email subject.\n"; error=1;   if(FocusField == '')FocusField =form.subjectmember;}
   if (form.messagemember.value=='') { message+="Please enter confirm member Id email message.\n"; error=1;   if(FocusField == '')FocusField =form.messagemember;}

   if (form.emailmemenable.value=='') { message+="Please enter member enable email account.\n"; error=1;   if(FocusField == '')FocusField =form.emailmemenable;}
   if (form.subjectmemenable.value=='') { message+="Please enter member enable email subject.\n"; error=1;   if(FocusField == '')FocusField =form.subjectmemenable;}
   if (form.messagememenable.value=='') { message+="Please enter member enable email message.\n"; error=1;   if(FocusField == '')FocusField =form.messagememenable;}

   if (form.emailfeedback.value=='') { message+="Please enter feedback email account.\n"; error=1;   if(FocusField == '')FocusField =form.emailfeedback;}
   if (form.subjectfeedback.value=='') { message+="Please enter feedback email subject.\n"; error=1;   if(FocusField == '')FocusField =form.subjectfeedback;}
   if (form.messagefeedback.value=='') { message+="Please enter feedback email message.\n"; error=1;   if(FocusField == '')FocusField =form.messagefeedback;}
   if (form.emailalertvisitor.value=='') { message+="Please enter alert visitor email account.\n"; error=1;   if(FocusField == '')FocusField =form.emailalertvisitor;}
   if (form.subjectalertvisitor.value=='') { message+="Please enter alert visitor email subject.\n"; error=1;   if(FocusField == '')FocusField =form.subjectalertvisitor;}
   if (form.messagealertvisitor.value=='') { message+="Please enter alert visitor email message.\n"; error=1;   if(FocusField == '')FocusField =form.messagealertvisitor;}

   if (form.footer.value=='') { message+="Please enter footer.\n"; error=1;   if(FocusField == '')FocusField =form.footer;}
//   if (form.disclaimer.value=='') { message+="Please enter disclaimer.\n"; error=1;   if(FocusField == '')FocusField =form.disclaimer;}

   if (error==1) { FocusField.focus(); alert(message); return false; }
   return true;
}
//=========================================================================================

/********************************************************************************************
	THIS IS SetSelectedValue() FUNCTION, TO PUT VALUE OF SELECTED FIELD INTO ANOTHER FIELD
*********************************************************************************************/
function SetSelectedValue(SelectedField, AnotherField)
{
	alert("sfddsf"+SelectedField.options[SelectedField.selectedIndex].text);
	AnotherField.value = SelectedField.options[SelectedField.selectedIndex].text;
	alert(AnotherField.value);
}
/************************************************************
end function
************************************************************/
/********************************************************************************************
	THIS IS SetFieldLabel() FUNCTION, TO PUT VALUE OF SELECTED FIELD INTO FIELD LABEL
*********************************************************************************************/
function SetFieldLabel(SelectedField, FieldLabel1, FieldLabel2)
{
	var FieldValue = SelectedField.options[SelectedField.selectedIndex].text.toLowerCase() + " : ";

	if(FieldValue == '--Please select--')
	{
		FieldLabel1.value = 'value(s) : ';
		FieldLabel2.value = 'value : ';
	}
	else
	{
		FieldLabel1.value = FieldValue;
		FieldLabel2.value = FieldValue;
	}
}
/************************************************************
end function
************************************************************/
//THIS IS AddCategoryType() FUNCTION, TO ADD CATEGORY TYPE
function AddCategoryType(CatgType,  VarType)
{

			//remove all types from type select control
			VarType.length = 0;
			//select all type from array, related with  category
			var thecount = 0;
			var optcount = 0;

			if(CatgType != '')//if any hotel selected, then selected type  
			{
					
					while(thecount < CountArr)
					{
						if(TypeArray[thecount] == CatgType)
						{
							var option = new Option(NameArray[thecount], IdArray[thecount]);
							VarType.options[optcount] = option;
							optcount = optcount + 1;
						}
						thecount = thecount + 1;
					}//end while
					if(optcount ==0)
					{
						var option = new Option();
						VarType.options[0] = option;
						VarType.options[0].text='Value does not exist';
						VarType.options[0].value='0';
					}
			}//end if
			else
			{
					var option = new Option();
					VarType.options[0] = option;
					VarType.options[0].text='Please select';
					VarType.options[0].value='0';
			}
}
//END FUNCTION 

//============================================
//==FUNCTION TO CHECK MAILING FORM
//============================================
function CheckWebMail(theForm)
{
	var Err = 0;
	var Msg = '';
	var FocusField = '';
	
	if(theForm.to.value == '')
	{
		Err = 1;
		Msg+= "Please enter recipient's email address.\n";
		if(FocusField == ''){FocusField = theForm.to;}
	}
	if(theForm.subject.value == '')
	{
		Err = 1;
		Msg+= "Please enter subject of email.\n";
		if(FocusField == ''){FocusField = theForm.subject;}
	}
	if(theForm.message.value == '')
	{
		Err = 1;
		Msg+= "Please enter email message.\n";
		if(FocusField == ''){FocusField = theForm.message;}
	}
	
	if(Err == 1)
	{
		alert(Msg);
		FocusField.focus();
		return false;
	}
	return true;
}
//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR NEXT PAGE ....
//THIS FUNCTION POSTS FORM FOR NEXT PAGE ....
//=============================================================================================================================

/*function NextPage()
{
	document.frmlist.PageCounter.value = eval(document.frmlist.PageCounter.value) + 1  ;
	
	document.frmlist.submit();
}
//=============================================================================================================================


//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR PREVIOUS PAGE ....
//THIS FUNCTION POSTS FORM FOR PREVIOUS PAGE ....
//=============================================================================================================================

function PrePage()
{
	document.frmlist.PageCounter.value = eval(document.frmlist.PageCounter.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.PageCounter.value = eval(val);
	document.frmlist.submit();
}
//=============================================================================================================================

//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR ORDER BY....
//THIS FUNCTION POSTS FORM FOR ORDER BY....
//=============================================================================================================================
*/function OrderPage(OrderBy)
{
	document.FormPage.PageCounter.value = eval(document.FormPage.PageCounter.value);
	if(document.FormPage.orderby.value.search(OrderBy)<0)
		document.FormPage.orderby.value = OrderBy;
	else
	{
		if(document.FormPage.orderby.value.search(' desc')<0)
			document.FormPage.orderby.value = OrderBy+' desc';
		else
			document.FormPage.orderby.value = OrderBy;
	}
	//alert(document.frmlist.orderby.value );
	document.FormPage.submit();
}
//=============================================================================================================================


//=============================================================================================================================
//THIS FUNCTION POSTS FORM FOR VIEW/EDIT/BLOCK....
//THIS FUNCTION POSTS FORM FOR VIEW/EDIT/BLOCK....
//=============================================================================================================================


//FUNCTION DisplayCategory(), PUT ALL CATEGORIES IN CATEGORY OPTION LIST 
function DisplayCategory(Category1)
{	
			//select all category from array
		
			var thecount = 0;
			var optcount = 1;
			
			if(CountCatg ==0)
			{
				Category1.options[0] = new Option('No category found', '0');
				//Category3.options[0] = new Option('No category found', '0');
			}
			else
			{
				Category1.options[0] = new Option('--Search In All Lists--', '');
				//Category3.options[0] = new Option('Please select', '');
			}
			while(thecount < CountCatg)
			{
					Category1.options[optcount] = new Option(ArrCatg[thecount], ArrCatgId[thecount]);
					//Category3.options[optcount] = new Option(ArrCatg[thecount], ArrCatgId[thecount]);
					optcount = optcount + 1;
					thecount = thecount + 1;
			}
}
//END FUNCTION 
//THIS IS AddSubCategory() FUNCTION, TO ADD SUBCATEGORY ACCORDING TO SELECTED CATEGORY
function AddSubCategory(CategoryID,  VarSubcatg)
{
			//remove all subcategory from subcategory select control
			VarSubcatg.length = 0;
			//select all subcategory from array, related with categoryid
			var thecount = 0;
			var optcount = 0;
			//VarSubcatg.options[0].text='Please select';
			//VarSubcatg.options[0].value='';
			if(CategoryID != '')//if any category selected, then selected related subcategory 
			{
				while(thecount < CountArr)
				{
					if(CatgIdArray[thecount] == CategoryID)
					{
						var option = new Option(SubCatgArray[thecount], SubCatgIdArray[thecount]);
						VarSubcatg.options[optcount] = option;
						optcount = optcount + 1;
					}
					thecount = thecount + 1;
				}//end while
				if(optcount ==0)
				{
					var option = new Option();
					VarSubcatg.options[0] = option;
					VarSubcatg.options[0].text='Sub category does not exist';
					VarSubcatg.options[0].value='0';
				}
			}//end if
			else
			{
					var option = new Option();
					VarSubcatg.options[0] = option;
					VarSubcatg.options[0].text='Please select';
					VarSubcatg.options[0].value='0';
			}
}
//END FUNCTION 

//THIS IS AddSubCategorySelect() FUNCTION, TO ADD SUBCATEGORY ACCORDING TO SELECTED CATEGORY (IT ALSO INCLUDE AN OPTION AS  - PLEASE SELECT - FOR SUBCATEGORY
function AddSubCategorySelect(CategoryID,  VarSubcatg)
{
			//remove all subcategory from subcategory select control
			VarSubcatg.length = 0;
			//select all subcategory from array, related with categoryid
			var thecount = 0;
			var optcount = 1;
			//VarSubcatg.options[0].text='Please select';
			//VarSubcatg.options[0].value='';
			if(CategoryID != '')//if any category selected, then selected related subcategory 
			{
					var option = new Option();
					VarSubcatg.options[0] = option;
					VarSubcatg.options[0].text='Any subcategory';
					VarSubcatg.options[0].value='';
				while(thecount < CountArr)
				{
					if(CatgIdArray[thecount] == CategoryID)
					{
						var option = new Option(SubCatgArray[thecount], SubCatgIdArray[thecount]);
						VarSubcatg.options[optcount] = option;
						optcount = optcount + 1;
					}
					thecount = thecount + 1;
				}//end while
				if(optcount ==0)
				{
					var option = new Option();
					VarSubcatg.options[0] = option;
					VarSubcatg.options[0].text='Sub category does not exist';
					VarSubcatg.options[0].value='';
				}
			}//end if
			else
			{
					var option = new Option();
					VarSubcatg.options[0] = option;
					VarSubcatg.options[0].text='Please select';
					VarSubcatg.options[0].value='';
			}
}
//END FUNCTION