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 trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function validateform(str)
{
 
	var sstr = str.split(',')
	
	var i,j,tstr,errorStr
	errorStr=""
	for (i=0;i<sstr.length;i=i+3)
	{
	   
		var s = trim(eval("document.forms[0]." + sstr[i] + ".value"))
		
		if ((sstr[i+2]=="R" || sstr[i+2]=="RE" || sstr[i+2]=="RN") && s=="")
			errorStr = errorStr + "<LI>" + sstr[i + 1] + " is Required.</LI>"
			
		else if(sstr[i+2]=="RN"  && parseInt(s)==0)		
			errorStr = errorStr + "<LI>" + sstr[i + 1] + " is Required.</LI>"		
		else if((sstr[i+2]=="E" || sstr[i+2]=="RE") && s!='')
			if (!checkEmail(s))
					errorStr = errorStr + "<LI>" + sstr[i + 1] + " is not a valid Email Address.</LI>"				
		/*alert(legalstring(s))
		if (!legalstring(s))
		{
				errorStr = errorStr + "<LI>" + sstr[i+1] + " contains Illegal character(s).</LI>"
		}*/
				
	}
	
	if (errorStr!="")
	{
	
		displayerror(errorStr)
		return false
	}
	else
		return true;
}
function displayerror(str,showbox)
{	

	document.getElementById("message").innerHTML=str		
	var twidth=document.getElementById("errorbox").style.width.substring(0,document.getElementById("errorbox").style.width.length-2)
	document.getElementById("errorbox").style.left=(screen.width-twidth)/2
	document.getElementById("errorbox").style.top=document.body.scrollTop + 120
	document.getElementById("errorbox").style.display=""
}
function checkEmail(strng)
{
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) 
		return false;
	var illegalChars= /[\(\)\<\>\?\,\;\:\\\/\"\[\]\*\+\-\&\%\!\#\$\^\=]/		
	if (strng.match(illegalChars)) 
		return false;
	else
		return true;
}

function NumbersOnly(e)
{	
	
	if (window.event)
	{
		if (event.keyCode<48 || event.keyCode>57)
			event.keyCode=0;
	}
	else 
	{
		if (e.which==8 || e.which==0)
			return true;
		else if (e.which<48 || e.which>57)
			return false; 
	}	
}
function NumbersExcept0(e)
{	
	if (window.event)
	{
		if (event.keyCode<49 || event.keyCode>57)
			event.keyCode=0;
	}
	else 
	{
		if (e.which==8 || e.which==0)
			return true;
		else if (e.which<49 || e.which>57)
			return false; 
	}	
}
function legalstring(s)
{	
	var legalChars= /^[0-9a-zA-Z]*/;
//	var legalChars=/[a-zA-Z_0-9\~\`\!\@\#\$\%\^\&\*\(\)\+\=\|\[\]\{\}\<\>\,\.\/\?]/;
//	var illegalChars = /\'/;
	if (s.match(illegalChars))
		return false;
	else
		return true;
}
function showcal(s)
{
//alert('avi');
	var str;
	str=document.all(s).value.split("-")	
	//alert(str[1])
	//alert(str[1])
	//alert(str[2])

	document.all("frmcal").src='../calendar.asp?frmnm=top&obj=' + s + '&month=' + mnum(str[1]) + '&year=' + str[2];				
	document.all('divcal').style.display='';
	document.all('divcal').style.left=event.x-200;
	document.all('divcal').style.top=event.y;
	
}
function getFrames()
{	
	var frmnm,currfrm;
	frmnm="['"  + frameElement.name + "']";	
	currfrm="parent"	
	while ( eval(currfrm) != top)
	{
		frmnm= "['" + eval(currfrm + '.name') + "']" + frmnm
		currfrm = "parent." + currfrm		
	}
	return	"top.frames" + frmnm	
}
function hidecal()
{
	document.all("divcal").style.display='none';
}
function mnum(a)
{
	switch(a)
	{
		case "JAN": 
			return 1
		case  "FEB":
			return 2
		case "MAR": 
			return 3
		case "APR": 
			return 4
		case  "MAY":
			return 5
		case  "JUN":
			return 6
		case "JUL" :
			return 7
		case "AUG" :
			return 8
		case "SEP" :
			return 9
		case "OCT" :
			return 10
		case "NOV" :
			return 11
		case "DEC" :
			return 12;				
		}			
}

function mnumfull(a)
{
	switch(a)
	{
		case 1: 
			return "January"
		case  2:
			return "February"
		case 3: 
			return "March"
		case 4: 
			return "April"
		case  5:
			return "May"
		case  6:
			return "June"
		case 7:
			return "July"
		case 8:
			return "August"
		case 9:
			return "September"
		case 10 :
			return "October"
		case 11 :
			return "November"
		case 12 :
			return "December";				
		}			
}

function mnumweekday(a)
{
	switch(a)
	{
		case 0: 
			return "Sunday"
		case 1:
			return "Monday"
		case 2: 
			return "Tuesday"
		case 3: 
			return "Wednesday"
		case 4:
			return "Thursday"
		case 5:
			return "Friday"
		case 6:
			return "Saturday"
	}			
}
function isURL(url) 
{
  var urlPattern = /^(?:(?:ftp|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'<>()\[\]{}\s\x7f-\xff]+)*)?/;
 
  return urlPattern.test(url.toLowerCase());
}
