/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>=5)

function window.confirm(str)
{
    execScript('n = msgbox("'+str+'","4132", "Please Confirm")', "vbscript");
    return(n == 6);
}

@end @*/

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

/*
Opening new Window with Width & Height
 */
function wopen(url, w, h)
{
	w += 32;
	h += 96;
	var win = window.open(url,
			'popup', 
			'width=' + w + ', height=' + h + ', ' +
			'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=yes, resizable=yes');
	win.resizeTo(w, h);
	win.focus();
}

/*
 * Function test whether entered string contains only numbers or not
 */
function isNumeric(sText)
{
	return isValidString(sText, "0123456789");
}

/*
 * Function test whether entered string contains only numbers and a decimal or not
 */
function isDecimal(sText)
{
  return isValidString(sText, "0123456789.");
}

/*
 * Function test whether entered string contains only validChars or not
 */
function isValidString(sText, validChars)
{
  var isNumber = true;
  var charvar;
  for (i = 0; i < sText.length && isNumber == true; i++) 
  { 
	  charvar = sText.charAt(i);
	  if (validChars.indexOf(charvar) == -1) 
	  {
	     return false;
	  }
  }
  
  return true;   
}


var xmlHttp;

function searchInv(qryStr)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url="invsrch.php?srchStr="+qryStr+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged; 
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChanged() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("srchResult").innerHTML=xmlHttp.responseText; 
	} 
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

/**
 * Function to calculate age of student in days. 
 * 
 * Student's age as number days should  > (number of cutoff years * 365.25)
 * 
 * @param {String} DateOfBirth
 */
function getAge(dob, cutoffDateAsStr)
{
	var birthDate = new Date(dob);
	var cutoffDate = new Date(cutoffDateAsStr);
	
	return (cutoffDate.getTime() - birthDate.getTime())/(24*60*60000);
}

/**
 * Function to calculate age of student. This funciton returns student age as a string
 * @param {String} DateOfBirth
 */
function getAgeMessage(dob, cutoffDate)
{
	var birthDate = new Date(dob);
	
	aSecond = 1000;
	aMinute = aSecond * 60;
	aHour = aMinute * 60;
	aDay = aHour * 24;
	aWeek = aDay * 7;
	aMonth = aDay * 30;
	
	var age = cutoffDate.getTime() - birthDate.getTime();
	
	if (age < 0) {
		return -1;
	}
	
	years = (new Date(cutoffDate.getTime() - aMonth* (birthDate.getMonth()) )).getFullYear() 
	- (new Date(birthDate.getTime() - aMonth* (birthDate.getMonth()) )).getFullYear();
	
	offsetCutoff = (new Date(cutoffDate.getTime() - aDay* (birthDate.getDate() -1) ));
	offsetbirthDate = (new Date(birthDate.getTime() - aDay* (birthDate.getDate() -1) ));
	if(years > 1){
		months = years*12 + ( offsetCutoff.getMonth() - offsetbirthDate.getMonth()) ;
	}else{
		months = (cutoffDate.getFullYear() - birthDate.getFullYear())*12 + ( offsetCutoff.getMonth() - offsetbirthDate.getMonth()) ;
	}
	
	agestr="";
	
	if (months < 24){
	weeks = Math.floor(age / aWeek);
	age -= weeks * aWeek;
	days = Math.floor(age / aDay); 
	
	if(weeks > 0){
		if(weeks == 1){
			agestr = agestr + weeks + " week ";
		}else if(weeks < 9){
			agestr = agestr + weeks + " weeks ";
		}else{
			agestr = agestr + months ;
		
			if(cutoffDate.getDate() - birthDate.getDate() > 10){
			agestr = agestr + "&#189;"; // "½";
			}
			agestr = agestr + " months ";
		}
	}
	
	if(days > 0){
		if(weeks < 9){
			if(weeks > 0){
				agestr = agestr + " and ";
			}
			if(days == 1){
				agestr = agestr + days + " day ";
			}else{
				agestr = agestr + days + " days ";
			}
		}
	}
	}else{
		agestr = agestr + years;
		if (months%12 > 5 && years<14){
			agestr = agestr + "&#189;"; // "½";
		}
		agestr = agestr + " years ";
	}
	
	return agestr;
}

/**
 * Accept only digits in the numberic fields like phone# and ZIP code
 */
function numericOnly(myfield, e, dec)
{
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
	    (key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   myfield.form.elements[dec].focus();
	   return false;
	   }
	else
	   return false;
}


