whitespace = "\t \n\r";
function isEmptyString(s)
{
    var i;
	if((s == null) || (s.length == 0)) return true;
	for(i=0;i < s.length;i++)
	{
		var currchar = s.charAt(i);
		if(whitespace.indexOf(currchar) == -1) return false;
	}
	return true;
}

function newLineCount(s)
{
	var stval = s.value;
	var len = s.value.length;
	if(s.value.length > 80)
	{
		alert("Exceeds maximum line limit.");
		s.value = s.value.substring( 0, 80);
		return false;
	}

	var st = s.value.split("\r\n");
	var val = s.value;
	

	if(st.length>=5) // count for 4 lines
	{
		alert("Exceeds maximum line limit.");
		s.value = s.value.substring( 0, len-2);
		return false;
	}
	else
	{
		return true;
	}

}
//------------------
function getcurrentdate()
  {
	var myDate1=new Date();
	
	year = myDate1.getYear();
	mon = myDate1.getMonth();
	mon=mon+1;
	date = myDate1.getDate();
	if(date<10)
	date="0"+date;
	else
	date=date;
	 
		document.getElementById("div_last_update").innerHTML=date+'/'+mon+'/'+year;
		document.getElementById("last_update").value=date+'/'+mon+'/'+year;
  }
//------------------
function newLineCount1(s)
{
	
	var st = s.value.split("\r\n");
	
	var val = s.value;
	var len = s.value.length;

	if(st.length >= 4) // count for 3 lines
	{
		alert("Exceeds maximum line limit.");
		s.value = s.value.substring( 0, len-2);
		return false;
	}
	else
	{
		return true;
	}
}
//----------------

All_numbers = "1234567890";
function isAnyNumber_Check(s)
{
    var i;
	for(i=0;i < s.length;i++)
	{
		var currchar = s.charAt(i);
		if(All_numbers.indexOf(currchar) != -1) return true;
	}
	return false;
}

All_char = "1234567890$";
function isAnyChar_Check(s)
{
    var i;
	for(i=0;i < s.length;i++)
	{
		var currchar = s.charAt(i);
		if(All_char.indexOf(currchar) != -1) return true;
	}
	return false;
}
//----------

function dollar_Check(s)
{
     var i;
	 var t_len=s.length;
	 for(i=0;i < s.length;i++)
	  {
	      var  f1='no';
		  var  f2='no';
	    var currchar1 = s.charAt(i);
		if(currchar1==".")
	       	 f1='yes'; 
		else 
		     f1='no'; 
			 
		var j=i+1;
		if(j==t_len)
		  j=i;
	    var currchar2 = s.charAt(j);
		
		if(All_numbers.indexOf(currchar2) != -1)
	        f2='yes'; 
		   else
		   f2='no';
		   
		 if(f1=='yes' && f2=='yes')
	      {  return true;  }   
	
	  } 
	return false;
}

//----------

function isNotNumeric(s)
{
	if(isNaN(s))
	{
		return(true);
	}
	return(false);
}

function isEmail(n)
{
		if ((n==null) || (n.length==0))
		{
			return true;
		}
		if (isEmptyString(n)) return false;
		var i=1;
		count = 0;
		var nLength=n.length;
		/*Count @***************/
		while((parseInt(i) < parseInt(nLength)))
		{
			if(n.charAt(parseInt(i)) == '@')
				count++;
			i++;
		}
		if(count>1)
			return false;
		/************************************/
		i=1;
		count = 0;
		/*Count ,***************/
		while((parseInt(i) < parseInt(nLength)))
		{
			if(n.charAt(parseInt(i)) == ',')
				count++;
			i++;
		}
		if(count>=1)
			return false;
		/************************************/
		/*Count . ***************/
		i=1;
		count = 1;
		while((parseInt(i) < parseInt(nLength)))
		{
			if(n.charAt(parseInt(i)) == '.' && n.charAt(parseInt(i+1)) == '.')
				count++;
			i++;
		}
		if(count>1)
			return false;
		/************************************/

		i=1;
		while((parseInt(i) < parseInt(nLength)) && (n.charAt(parseInt(i)) != '@'))
		{
			i++;
		}
		if ((parseInt(i) >= parseInt(nLength)) || (n.charAt(i)!="@"))
		{
			return false;	
		}	
		else i+=2;
		while((i<nLength) && (n.charAt(i)!="."))
		{
			i++;
		}
		/*Check for dot in the email address*/
		if ((i>=nLength-1) || (n.charAt(i)!="."))
		{
			return false;	
		}
	 return true;		
}

extArray = new Array(".gif",".jpg",".jpeg",".jpe");
function Allowed_Uploaded_Files(File_Value)
{
	allowSubmit = false;
	if (!File_Value)
	{
		return true;
	}
	while (File_Value.indexOf("\\") != -1)
	{
		File_Value = File_Value.slice(File_Value.indexOf("\\") + 1);
	}
	ext = File_Value.slice(File_Value.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++)
	{
		if (extArray[i] == ext)
		{
			allowSubmit = true;
			break;
		}
	}
	if (allowSubmit)
	{
		return true;
	}
	else
	{
		return false;
	}
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 2 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function checkDomain(nname)
{
var arr = new Array(
'.com','.net','.org','.biz','.coop','.info','.museum','.name',
'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
'.wf','.ye','.yt','.yu','.za','.zm','.zw');

var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 alert("Your email address extension "+ext+" is not correct");
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 alert("email address should not begin or end with '-'");
			      return false;
		 	 }
		  }
		else	{
		  	 alert("Your email address should not have special characters");
			 return false;
		  }
		}
	}
}
else
{

 alert("Not a valid email address");
 return false;
}	

return true;
}
function confdel()
{
	var fl = 0;
	for(i = 0; i < (document.frm_1.elements.length); i++)
	{
		if((document.frm_1.elements[i].type=="checkbox") && (document.frm_1.elements[i].checked==true))
		{
			fl = 1;
			break;
		}
	}
	if(fl == 1)
	{
		if(confirm("Are you sure you want to Delete ?"))
		{
			fl = 1;
		}
		else
		{
			fl = 0;
		}
	}
	else
	{
		alert("Nothing to Delete.");
		fl = 0;
	}
	if(fl == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function ValidateWebSite(objName)
{
 	/*
	if(!sec_lev_web(objName))
 	{
 	 alert("Please enter the Website in proper format")
 	 objName.focus();
 	 return false;
 	}
	*/
 	var sobjValue;
 	var iobjLength;
 	var i;
 	var www;
 	var fourthchar;
 	var lastchar;
 
 	sobjValue=objName.value;
 	iobjLength=sobjValue.length;
 
 
 	if (iobjLength!=0)
 	{
 	   www="";
 	   for(i=0;i<4;i++)
 	   {
 	      www=www+sobjValue.charAt(i);
 	   }
 
 	   if ((www != "www.") && (www != "WWW."))
 	   {
 	      alert("Please enter the WebSite in the proper format");
 	      objName.focus();
 	      return false;
 	   }
 
 	   fourthchar=sobjValue.charAt(4);
 
 	   if(fourthchar == ".")
 	   {
 	    	alert("Please enter the WebSite in the proper format");
 			objName.focus();
 			return false;
 	   }
 	   lastchar=sobjValue.charAt(iobjLength-1);
 
 	   if(lastchar==".")
 		{
 			alert("Please enter the WebSite in the proper format");
 			objName.focus();
 			return false;
 		}
 
 		return true;
 	}
 
 }

//-----------
/*
var re = new RegExp(stringToRemove + '$');
var newString = oldString.replace(re, '');
*/
RegExp.escape = function(text) {
  if (!arguments.callee.sRE) {
    var specials = [
      '/', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\\$1');
}

