// JavaScript Document
//this function return all the attribute values of the element
function MM_findObj(n, d) 
{ 
  var p,i,x; 
  if(!d)
  {
	  d=document;
  }
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    d=parent.frames[n.substring(p+1)].document; 
	n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all)
  {
	  x=d.all[n];
  }
 for (i=0;!x&&i<d.forms.length;i++)
 {
	x=d.forms[i][n];
 }
 for(i=0;!x&&d.layers&&i<d.layers.length;i++)
 {
	 x=MM_findObj(n,d.layers[i].document);
 }
 if(!x && d.getElementById)
 {
	 x=d.getElementById(n);
 }
 return x;
}

//this function validaes the form 
function MM_validateForm() 
{ 
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3)
  { 
	test=args[i+2]; 
	val=MM_findObj(args[i]);
    if (val) 
	{ 
		nm=val.id; 
		if ((val=val.value)!="")
		{
		    if (test.indexOf('isEmail')!=-1) // check if the input is an email
		    { 
			    p=val.indexOf('@');
			    if (p<1 || p==(val.length-1))
			    {
					errors+='- '+nm+' must contain an e-mail address.\n';
			    }
		    } 
		    else if (test.indexOf('isDate')!=-1) // check if the input is a date
		    { 
				strValue=val;
				//var objRE = /([1-9]|0[1-9]|1[012])[-]([0-9]|[012][0-9]|3[01])[-](2)\d\d\d/;
  				if(!(typeof strValue == 'string' && strValue != '' && isNaN(strValue) && objRE.test(strValue)))
				{
					errors+='- '+nm+' must contain a date in the format mm-dd-yyyy.\n';
			    }
		    } 
			else if (test.indexOf('isTime')!=-1) // check if the input is time
		    { 
				strValue=val;
 			    //var objRE = /([1-9]||0[1-9]|1[012])[:]([0-5][0-9])[ ](am|pm)/;
  				if(!(typeof strValue == 'string' && strValue != '' && isNaN(strValue) && objRE.test(strValue)))
				{
					errors+='- '+nm+' must contain a time in the format hh:mm am/pm.\n';
			    }
		    }
			else if (test.indexOf('isEqual') != -1) // compares two element values (used to check password fileds)
			{
				p=test.indexOf(':');
				firstval=val;
				second=test.substring(p+1,test.length);
				secondval=MM_findObj(second);
				
				if (firstval != secondval.value)
				{
					errors+='- '+nm+' and '+second+' do not match.\n';
				}
			}
			else if (test!='R') 
			{ 
				num = parseFloat(val);
				
				if (isNaN(val)) // check if the input is a number
				{
					errors+='- '+nm+' must contain a number.\n';
				}
				if (test.indexOf('inRange') != -1) // check if the input is a number between a range
				{
					p=test.indexOf(':');
					min=test.substring(8,p); 
					max=test.substring(p+1);
					if (num<min || max<num)
					{
						errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			}
		}
		else if (test.charAt(0) == 'R') 
		{
			errors += '- '+nm+' is required.\n'; 
		}
	}
  }
  if (errors) 
  {
	  alert('The following error(s) occurred:\n'+errors);
  }
  document.MM_returnValue = (errors == '');
}

//this function confirm if the user is ure to delete or remove something
function confirmdelete(message)
{
var agree=confirm(message);
if (agree)
	return true ;
else
	return false ;
}


//this function is used to hide and show div layers 
function showhide(smt)
{
	var tmp= document.getElementById(smt).style;
	
	if(tmp.display=="block")
	{
		tmp.display = "none";
	}
	else 
	{
		tmp.display = "block";
	}

}
//this function is used to hide and show div layers 
function show(smt)
{
	var tmp= document.getElementById(smt).style;
	
		tmp.display = "block";

}
//this function is used to hide and show div layers 
function showpop(smt)
{
	var tmp= document.getElementById(smt).style;
	
		tmp.visibility = "visible";

}
//this function is used to hide and show div layers 
function hide(smt)
{
	var tmp= document.getElementById(smt).style;
	
		tmp.display = "none";

}
//this function is used to hide and show div layers 
function hidepop(smt)
{
	var tmp= document.getElementById(smt).style;
	
		tmp.visibility = "hidden";

}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


function MM_jumpMenuGo(objId,targ,restore){ //v9.0
  var selObj = null;  with (document) { 
  if (getElementById) selObj = getElementById(objId);
  if (selObj) eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; }
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function SetChecked(val,chkName,form) {
dml=document.forms[form];
len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if (dml.elements[i].id==chkName) {
dml.elements[i].checked=val;
}
}
}


