/**
 *  function searchonclick(){}
 * 
 *  function checkEnterKey(){}
 * 
 *  function init_view(){}
 * 
 *  function popup(url,left,top,width,height,scrollbars,resize,name){}
 *
 *  function statusPopup(p, left, top)
 *
 *	function isDate(dtStr)
 *
 *  function isNumeric(value)
 *
 *  function isValidDate(dtStr)
 *  
 *  function isValidName(name) 
 *  
 *  function highlight(x,y) 
 *
 *  function filtersearch(filterType)
 */

function searchonclick(){
if (validateViewForm(document.forms[0])){
	document.forms[0].curPageNumber.value=1;
	document.forms[0].submit();
}	
}

function checkEnterKey(e){
    if (e.keyCode) keycode=e.keyCode;
     else keycode=e.which;
     
    if (keycode==13){
	    if (!(validateViewForm(document.forms[0]))){
		  	return false;
		}	    	 	
		document.forms[0].curPageNumber.value=1;
	}
}




function init_view(){
	var searchstring = document.forms[0].searchBy.value;
	if (searchstring != "") {
		document.getElementById("clearResults").style.visibility="";
	}
}

function statusPopup(p, left, top){
   var str=p;
   document.getElementById("popup").style.pixelLeft=left;
   document.getElementById("popup").style.pixelTop=top;
   document.getElementById("popup").contentWindow.document.write("<html><body leftmargin=0 rightmargin=0 topmargin=0 bottomargin=0><table style='width:394px;height:75px;background-color:#025FBC'><tr><td><table style='width:394px;height:75px;background-color:#F1F1F1'><tr><td><P ALIGN=center><B><FONT SIZE=2 COLOR = \"000000\" FACE=\"verdana\">"+p+"</FONT></b></P></td></tr></table></td></tr></table></body></html>");
   document.getElementById("popup").style.visibility="visible";
   document.body.style.cursor="wait";
}


function popup(url,left,top,width,height,scrollbars,resize,nam){
	var url 		= (url == null ? "" : url);	
	var left 		= (left == null ? "150" : left);	
	var top 		= (top == null ? "50" : top);	
	var width 		= (width == null ? "700" : width);
	var height 		= (height == null ? "420" : height);	
	var scrollbars  = (scrollbars == null ? "0" : scrollbars);	
	var resize  = (resize == null ? "0" : resize);	
	var nam     = (nam == null ? "" : nam);	

	window.open(url,nam,"left="+left+",top="+top+",height="+height+",width="+width+",toolbar=no,location=no,status=1,menubar=no,scrollbars="+scrollbars+",titlebar=no,resizable="+resize);
}


/**
 * DHTML date validation script.
 */
// Declaring valid date character, minimum year and maximum year
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 isValidDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=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 : mm/dd/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 != 4 || 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 isNumeric(value){
 validChars="0123456789";
 for(i=0;i<value.length;i++){
  if (validChars.indexOf(value.charAt(i))!=-1)
   continue;
     return false;
 }
 return true;
}


/*function nrcIE(){
	if (document.all){return false;}
}

function nrcNS(e){
	if(document.layers||(document.getElementById&&!document.all)){ 
		if (e.which==2||e.which==3){
		return false;
		}
	}
} 

if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=nrcNS;
} else {
	document.onmouseup=nrcNS;
	document.oncontextmenu=nrcIE;
}

document.oncontextmenu=new Function("return false");
*/

function isPastDate(pdate){

var today = new Date();

var the_day = today.getDate();
var the_month = today.getMonth();
var the_year = today.getYear();

var mydate = pdate;
var the_array = mydate.split("/");
var my_day=the_array[1];
var my_month=the_array[0];
var my_year=the_array[2];
if (my_year<the_year){
	return true;
}else if (my_month<the_month){
	return true;
}else if (my_day<the_day){
	return true;
}else{
	return false;
}
}

function isValidName(name){
	var validChars="0123456789abcdefghijklmnopqrstuvwxyz-_";
	if (name.length==0){
		return 1;
	}
	for(i=0;i<name.length;i++){
		chr = name.charAt(i).toLowerCase();
		if (validChars.indexOf(chr)!=-1)
			continue;
		return 2;	
	}
	chr = name.charAt(0);
	if ((chr=='-') || (chr=='_')){
		return 3;
	}
	chr = name.charAt(name.length-1);
	if ((chr=='-') || (chr=='_')){
		return 4;	
	}
	if((name.indexOf("--") != -1) || (name.indexOf("__") != -1)){
		return 5;
	}
	return 6;
}


function highlight(x,y) {
	if (window != top) {
		try{
			var t = setTimeout("",5000);
			parent['EMF_TOP'].show_menu(x,y,true);
		}catch(err){
		}
	}
}

function filtersearch(filterType){
	f.filterBy.value = filterType;
	f.submit();
}








function numberFormat(val){
	var str=""+val+"";
	if(str.indexOf(".")==-1)
		str=str+".00";
	else{
	var newstr=str.substring(str.indexOf(".")+1,str.length)
					if(newstr.length==1)
						str=str+"0";
	}
	return (str);
}

function isNotWhitespace(Fieldname) {
		var Fieldvalue = eval("document.forms[0]."+Fieldname+".value");
	    var i = trim(Fieldvalue);
	    if(i == ' ' || i == '  ' || i == '' || i == '\n' || i == '\r' || i == '\t' || i == '\f' || i == '\v' || i == '\b' )		{
	    	return false;
		}
		else {
			return true;
	    }
	}

	function trim(Fieldvalue) {
		var tempstr = lTrim(Fieldvalue);
		return  rTrim(tempstr);
	}

	function lTrim(Fieldvalue){ 
		while(1) { 
			if (Fieldvalue.substring(0, 1) != " ")
	      	break;
	    	Fieldvalue = Fieldvalue.substring(1, Fieldvalue.length);
		}
		return Fieldvalue;
	}

	function rTrim(Fieldvalue) {
		while (1) {
	    	if (Fieldvalue.substring(Fieldvalue.length - 1, Fieldvalue.length) != " ")
			break;
	    	Fieldvalue = Fieldvalue.substring(0, Fieldvalue.length - 1);
		}
	  return Fieldvalue;
	}
	
 function checkCondition(){	
    if (!(document.forms[0].conditions.checked))	{
	alert ("Please check the Terms and Conditions");	
	document.forms[0].conditions.focus();
	return false;
	}
 return true	
 }
 
 
     function checkEmail(email) {
       

	if (email.charAt(0)==" ")
	{
		return false;
	}
	if (email.charAt(0)=="_" || email.charAt(0)=="-")
	{
		return false;
	}
	if (email.charAt(email.length-1)=="_" || email.charAt(email.length-1)=="-")
	{
		return false;
	}
	var strEmail=email; 
	strEmail= strEmail.toLowerCase();
	if ((strEmail.indexOf("@")==-1)||(strEmail.indexOf(".")==-1))
		{ return false;}
		else
		{
			var word=strEmail.split("@");
			if(word.length >2) {return false;}
			if(word[0]=="")
				{return false;} 
				word1= word[1];
				if(word[1].indexOf(".")==-1)
				{return false;}
				var sWord=word1.split(".");
				if(sWord[1].length <2)
				{return false;}
		}
		if(strEmail.indexOf("..") >= 0){return false;}
		if(strEmail.indexOf("__") >= 0){return false;}
		if(strEmail.indexOf("--") >= 0){return false;}
	var strDot=strEmail.split("@");
	if (strDot[1].indexOf(".")==0)
	{
		return false;
	}
	
	var valLet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.@_-0123456789"
	for (i=0;i<=strEmail.length;i++)
		{
			flgfound = false;
			for(k=0;k<=valLet.length;k++)
			{
				 if(strEmail.charAt(i) == valLet.charAt(k))
				  {
						flgfound = true;
						break;					
				  }

			}
		   if(flgfound == false)
		   {	
					return false;
	       }
		}
		j= strEmail.length-1
		ch=strEmail.charCodeAt(j);
			if (((ch<45)||(ch>122))||((ch<90)||(ch<94)))
				{
					return false;
				}

			return true;	
    }