// used for month combo
var monthname= new Array() 
monthname[1]="January"; 
monthname[2]="February"; 
monthname[3]="March"; 
monthname[4]="April"; 
monthname[5]="May"; 
monthname[6]="June"; 
monthname[7]="July"; 
monthname[8]="August"; 
monthname[9]="September"; 
monthname[10]="October"; 
monthname[11]="November"; 
monthname[12]="December"; 

function getYearCombo(cname,startval, endval)
{
	val = '<select name="'+cname+'">';
	val += '<option value="0">Year</option>';  	
	for(q=startval; q<endval; q++)	{
		val += '<option value="'+q+'">'+q+'</option>';  	
	}
	val += '</select>';
	return val;
}
function getMonthCombo(mname)
{
	val = '<select name="'+mname+'">';
	val += '<option value="0">Month</option>';  		
	for(q=1; q<monthname.length; q++)	{
		if(q < 10)	{
			v = "0"+q;
			val += '<option value="'+v+'">'+monthname[q]+'</option>';  		
		}	
		else
			val += '<option value="'+q+'">'+monthname[q]+'</option>';  					
	}
	val += '</select>';
	return val;
}

function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}


function getDayCombo(dname)
{
	val = '<select name="'+dname+'">';
	val += '<option value="0">Day</option>';  	
	for(q=1; q<=31; q++)	{
		if(q < 10)	{
			q = "0"+q;
			val += '<option value="'+q+'">'+q+'</option>';  		
		}
		else
			val += '<option value="'+q+'">'+q+'</option>';  					
	}
	val += '</select>';
	return val;
}

function alphanum(value,length)
{
	chk1="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\-";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function number(value,length)
{
	chk1="1234567890";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function phoneformate(value,length)
{
	chk1="+ 1234567890()-.";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function decimalNumber(value,length)
{
	chk1="1234567890.";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function smallLetter(value,length)
{
	chk1="abcdefghijklmnopqrstuvwxyz";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function capLetter(value,length)
{
	chk1="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function letter(value,length)
{
	chk1="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function symbol(value,length)
{
	chk1="~`!@#$%^&*()_-+=|\{}[]:;'<>?/,";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function btncclick()
{
	if(!checkvalid())
	{
		return false;
	}
	document.frmadd.addmore.value=true;
	return true;
}
function checkFloatNumber()
{  
	val = event.keyCode;
	//alert(val);
   	if(val==13)
		return true;
	if(val<48 && val!=46)
	{
	  event.keyCode=0;
	}
	if(val>57)
	{
	event.keyCode=0;
	}
	return true;
}

function phone_formate(input,length)
{
	chk1="+ 1234567890-()";
	if(length!=12)
	{
		return false;
	}
	for(i=0;i<length;i++)
	{
		ch1=input.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
		{
			return false;
		}
		if(input.charAt(3)!='-')
		{
			return false;
		}
		if(input.charAt(7)!='-')
		{
			return false;
		}
	}
return true;	
}

function quatation(value,length)
{
	chk1="\\";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==0)
			return true;
	}
//	return true;
}


	var bikky = document.cookie;
	var today = new Date();
	var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days

	function ShowHideCategories(CategoryName,Action)
	{
		var layerHidden = eval(getLayer(CategoryName + "LayerHidden"));
		var layer = eval(getLayer(CategoryName + "Layer"));
		if(Action=="Hide")
		{
			if (document.layers) 
			{
				layerHidden.visibility = "show" ;
				layer.visibility = "hide" ;
			}
			else if (document.getElementById) 
			{
				layerHidden.style.display = 'none';
				layer.style.display = '';
			}	
			//setCookie(CategoryName+"Visibility", Action);
		}
		else
		{
			if (document.layers) 
			{
				layerHidden.visibility = "hide" ;
				layer.visibility = "show" ;
			}
			else if (document.getElementById) 
			{
				layerHidden.style.display = '';
				layer.style.display = 'none';
			}
			//setCookie(CategoryName+"Visibility", Action);
		}
	}
	
	function getLayer(layerName)
	{
		if (document.layers) 
	        return window.document.layers[layerName]
		else if (document.getElementById)
			return document.getElementById(layerName)
	}
	function HighlightBoxWithBorder(Name,Highlight)
	{
		if(Highlight=="true")
		{
			Name.style.background = "#f0f0f0";
			Name.style.cursor="hand";
		}
		else
		{
			Name.style.background = "#ffffff";
		}
	}

function Highlight(e)
{
	if(e.className!="raw_selectedbg")
		e.className="evenrowbg";
}
function UnHighlight(e,classname)
{
//	alert(e.className)
	if(e.className!="raw_selectedbg")
		e.className=classname;
}
function ShowHelp(div, title, desc)
{
	div.style.display = 'inline';
	div.style.position = 'absolute';
	div.style.width = '170';
	div.style.backgroundColor = 'lightpink';
	div.style.border = 'dashed 2px red';
	div.style.padding = '10px';
	div.innerHTML = '<b>' + title + '</b><br><div style="padding-left:10; padding-top:5; 						padding-right:5">' + desc + '</div>';
}
function HideHelp(div)
{
	div.style.display = 'none';
}


function getCookie(name)
{
	var cname = name + "=";
	var dc = document.cookie;
	if (dc.length > 0)
	{
		begin = dc.indexOf(cname);
		if (begin != -1)
		{
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
				return unescape(dc.substring(begin, end));
		}
	}
	return null;
}

// Set the value into Cookie by Name
function setCookie(name, value) 
{
	var now = new Date();
	var then = new Date(now.getTime() + 31536000000);
	document.cookie = name + "=" + escape(value) + "; expires=" + then.toGMTString() + "; path=/";
}
//******************************************************************************************//
//********************* functions  for email-id validation ****************************//
//******************************************************************************************//

function isValidEmail(emailStr) {
	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(" ( "+ emailStr +" ) Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert(" ( "+ emailStr +" ) Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert(" ( "+ emailStr +" ) Ths domain name contains invalid characters.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		alert(" ( "+ emailStr +" ) The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert(" ( "+ emailStr +" ) Destination IP address is invalid!");
				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(" ( "+ emailStr +" ) The domain name does not seem to be valid.");
			return false;
	   }	
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert(" ( "+ emailStr +" ) The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

// Make sure there's a host name preceding the domain.

	if (len<2) {
		alert(" ( "+ emailStr +" ) This address is missing a hostname!");
		return false;
	}	
	return true;
}

function checkValidNumber()
{
	val = event.keyCode;
	if(val==13)
		return true;
	if(val<48)
	  event.keyCode=0;
	if(val>57)
	  event.keyCode=0;
	return true;

} 


///created by chetan

// check the (a...z) + (A...Z) + (.) + (space) + (_) +(') on key press event
function checkAlphabetic()
{  
	val = event.keyCode;
	if(val==13)
		return true;
	if(val<65 && val!=32 && val!=46 && val!=39)
	  event.keyCode=0;
	else if(val >90 && val!=95 && val <97)
		event.keyCode=0;
	else if(val>122)
		event.keyCode=0;
	return true;
}

// check the only alpahabet + Underscore on key press event
function checkAlphaWithUnderscore()
{  
	val = event.keyCode;
	if(val==13)
		return true;
	if(val<65)
	  event.keyCode=0;
	else if(val>90 && val!=95 && val<97)
		event.keyCode=0;
	else if(val>122)
		event.keyCode=0;
	return true;
}

// check the  alpahabet + Digit on key press event
function checkAlphaNumeric()
{
	val = event.keyCode;
	//alert(val);
   	if(val==13)
		return true;
	if(val<48)
		event.keyCode=0;
	else if(val>57 && val<65)
		event.keyCode=0;
	else if(val >90 && val <97)
		event.keyCode=0;
	else if(val>122)
		event.keyCode=0;
	return true;
}
function checkSpCharacter()
{
	val = event.keyCode;
	//alert(val);
   	if(val==13)
		return true;
	if(val<48)
		return true;
	else if(val>57 && val<65)
		return true;
	else if(val >90 && val <97)
		return true;
	else if(val>122)
		return true;
	return false;
}

function date_check(Year,Month,Day)
{
	thetime = new Date();
	var mm = thetime.getMonth()+1;
	var dd = thetime.getDate();
	var yy = thetime.getYear();
	/*alert(Year + " " + yy);
	alert(Day + " " + dd);
	alert(Month + " " + mm);		*/
		if(Year < yy)
		{
			//alert("Year must be Greater OR Equal Current Year");
			return false;
		}
		else if((Year==yy) && Month < mm)
		{
			//alert("Month must be Greater OR Equal Current Month");
			return false;
		}
		else if((Month==mm) && (Day<dd))
		{
			//alert("Day must be Greater OR Equal Current Day");
			return false;
		}
		else
		{
			return true;		
		}
	
}


function date_time_check(Month,Day,Hour)
{
	var mm = (new Date()).getMonth()+1;
	var dd = (new Date()).getDate();
	var hh = (new Date()).getHours();
	
	if(Month < mm)
	{
		alert("Month is Lower Than Current Month");
		return false;
	}
	if((Month==mm) && (Day<dd))
	{
		alert("Day is Less Than Current Day");
		return false;
	}
	if((Month==mm) && (Day==dd) && (Hour<=hh))
	{
		alert("Hour is Must Greater than Current Hour");
		return false;
	}
	return true;
}
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function pollwin(url,w, h)
{
	pollwindow=window.open(url,'pollwindow','top=0,left=0,status=no,toolbars=no,scrollbars=no,width='+w+',height='+h+',maximize=no,resizable');
	pollwindow.focus();
}

function convertToFormatNumber(obj){
	var tempVar = eval(obj.value);
	alert(tempVar);
	obj.value = formatNumber(tempVar, ",");	
}

   // CONSTANTS
  var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

  function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null;  // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

 // patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      // patch suggested by Tom Denn 25/4/2001
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

function getmonthvalue(val)
{
	for(q=1; q<monthname.length; q++)
	{
		if(q < 10)
			v = "0"+q;
		if(val==monthname[q])
			return q;
	}
}
