//function to Check Empty
  function isEmpty(fld,mesg)
  {
  	reg = / /g;
  	str = fld.value;
  	res = str.replace(reg,"");
	reg = /\s/g;
	res = res.replace(reg,"");
  	if(res == "")
  	{
  		alert(mesg);
  		fld.value="";
  		fld.focus();
  		return false;
  	}		
  	return true;
  }

  //function to Check Empty without alert
  function isEmptyNoMsg(fld)
  {
  	reg = / /g;
  	str = fld.value;
  	res = str.replace(reg,"");
	reg = /\s/g;
	res = res.replace(reg,"");
  	if(res == "")
  	{
  		return true;
  	}		
  	return false;
  }


  
//function to Check email
// opt value 0 if mandatory and 1 if not
function checkEmail(fld,msg,opt)
{
	if(opt=="0" || fld.value!="")
	{
	
	var emailStr=fld.value;
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	var emailPat=/^(.+)@(.+)$/;

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	var validChars="\[^\\s" + specialChars + "\]";

	var quotedUser="(\"[^\"]*\")";

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	var atom=validChars + '+';

	var word="(" + atom + "|" + quotedUser + ")";

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null)
	{
		alert(msg);
		fld.focus();
		fld.select();
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {	
	alert(msg);
	fld.focus();
	fld.select();
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {	
	alert(msg);
	fld.focus();
	fld.select();
	return false;
	   }
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid	
	alert(msg);
	fld.focus();
	fld.select();
	return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {	
	alert(msg);
	fld.focus();
	fld.select();
	return false;
	   }
	}
	return true;
	}


	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {	
	alert(msg);
	fld.focus();
	fld.select();
	return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {	
	alert(msg);
	fld.focus();
	fld.select();
	return false;
	}

	if (len<2) {	
	alert(msg);
	fld.focus();
	fld.select();
	return false;
	}
	return true;
}
return true;
}

//function to Check Phone
function CheckPhone(fld1,fld2,fld3)
{
	if(fld1.value=='')
    {
		alert('Telephone number should be in xxx-xxx-xxxx format only.');
		fld1.focus();
		return false;
	}
    if(isNaN(fld1.value)==true)
    {
		alert('Telephone number could contain numeric values only.');
		fld1.focus();
		return false;
    }
    if(fld1.value.length!=3)
    {
		alert('Telephone number should be in xxx-xxx-xxxx format only.');
		fld1.focus();
		return false;
    }
    if(isNaN(fld2.value)==true)
    {
		alert('Telephone number could contain numeric values only.');
		fld2.focus();
		return false;
    }
	if(fld2.value.length!=3)
	{
		alert('Telephone number should be in xxx-xxx-xxxx format only.');
		fld2.focus();
		return false;
	}
	if(isNaN(fld3.value)==true)
	{
		alert('Telephone number could contain numeric values only.');
		fld3.focus();
		return false;
	}
	if(fld3.value.length!=4)
	{
		alert('Telephone number should be in xxx-xxx-xxxx format only.');
		fld3.focus();
		return false;
	}
	return true;
}

function checkjs()
{
	var js="yes";
	return js;
}


function CheckUrl(fld,mesg)
{
 	if(fld.value.indexOf("http://")==-1 || fld.value.indexOf(".")==-1)
 	{
		alert(mesg);
		fld.focus();
		fld.select();
 		return false;
	}
	return true;
}    


// validFileFormat=/(.gif|.GIF|.jpg|.JPG|.jpeg|.JPEG|.png|.PNG)$/;
function IsValidFileFormat(fld, validFileFormat, mesg)
{
	if(!validFileFormat.test(fld.value))
	{
		alert(mesg);
		fld.focus();
		fld.select();
		return false;
	}

	return true;
} 

/*
	This function get confirmation from user
*/
function be_confirm(warning)
{
	option=window.confirm(warning)
	if(option)
	{}
	else
	{
		window.event.returnValue=false
	}
}

/*
	This function to open popup window
*/
function openwin(url,w,h,scrollyes)
{
	if(w== "" && h== "")
	{
	   w = "120";
	   h = "120";
	}
	var top = (screen.height-h)/2;
	var left = (screen.width-w)/2;
	var customize = "toolbar=no,menubar=no,resizable=no,scrollbars="+scrollyes+",width="+w+",height="+h+",top="+top+",left="+left;
	return window.open(url,'_blank',customize)
}

//function to Check Number
  function isNumber(fld,mesg)
  {
	reg = / /g;
  	str = fld.value;
  	res = str.replace(reg,"");
	reg = /\s/g;
	res = res.replace(reg,"");

  	if(res == "" || isNaN(res))
  	{
  		alert(mesg);
  		fld.select();
  		fld.focus();
  		return false;
  	}		
  	return true;
  }
  
// function to chech for the special chars	
function isSpecialChar(fld,mesg)
{
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	for (var i = 0; i < fld.value.length; i++) {
		if (iChars.indexOf(fld.value.charAt(i)) != -1) {
			alert ("The "+mesg+" has special characters. \nThese are not allowed:\n"+iChars);
			fld.select();
			return false;
		}
	}
	return true;
}	

// function to chech first character for number
function isFirstCharNum(fld)
{
	
	var nonums 	= /^[0-9]*$/;
	var str		= removeSpaces(fld);
	str			= str.substring(0,1);
	if (nonums.test(str)) {
		 alert("First character should not be a number.");
		 fld.select();
		 return false;
	}
	return true;
}	

// function to remove spaces
function removeSpaces(fld)
{
  	reg = / /g;
  	str = fld.value;
  	res = str.replace(reg,"");
	reg = /\s/g;
	res = res.replace(reg,"");
  	return res;
}

function checkDate(dateVal,fld,mesg){
var checkstr = "0123456789";
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = dateVal;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      //DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert(mesg);
      fld.focus();
	  return false;
   }
   return true;
}

function create_Object()
{ 
	var xmlhttp;
	// This if condition for Firefox and Opera Browsers 
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{
		try 
		{
			xmlhttp = new XMLHttpRequest();
		} 
		catch (e) 
		{
			alert("Your browser is not supporting XMLHTTPRequest");
			xmlhttp = false;
		}
	}
	// else condition for ie
	else
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

function clearOption(fld)
{
	var len	= fld.length;
	for(var i=1;i<=len;i++)
	{
		fld.options[1]=null;
	}
}

function populateOption(fld,strText,strValue)
{
	clearOption(fld);

	var arrText	= strText.split(',');
	var arrValue= strValue.split(',');	
	var len	= arrText.length;
	for(var i=1;i<=len;i++)
	{
		var j = (i-1);
		fld.options[i]=new Option(arrText[j],arrValue[j]);
	}
}
