// Produced by MSR Inc.
// 2003 All Rights Reserved


// Browser check

var isNN4up = false;
var isIE4up = false;

var browserVer = parseInt(navigator.appVersion);
var browserName = navigator.appName;

if (browserVer >= 4 ) {
	if (browserName == "Netscape") {
		isNN4up = true;
	}
	else if (browserName == "Microsoft Internet Explorer") {
		isIE4up = true;
	}
}


// JS utilitites

 function makeArray() {
	this.length = makeArray.arguments.length
	for (var i = 0; i < this.length; i++) {
		this[i] = makeArray.arguments[i];
	}
 }

 function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
 }

 function getSearchAsArray() {

	var results = new Array();
	if (isNN4up || isIE4up) {
		var input = unescape(document.location.search.substring(1));
		if (input) {
			var srchArray = input.split("&");
			var tempArray = new Array();
			for (i = 0; i < srchArray.length; i++) {
			tempArray = srchArray[i].split("=");
			results[tempArray[0]] = tempArray[1];
			}
		}
	}
	return results;
 }


// DHTML utilities

function winPopup(popURL,WindowName,wt,ht,Scrolling,resizable,top,left) {
	if (Scrolling >0){
	Scrolling=1
	}
	else {
	Scrolling=0
	}
	if (resizable>0){
	resizable=1
	}
	else {
	resizable=0
	}
	if (top>0){
	top=top
	}
	else {
	top=0
	}
	if (left>0){
	left=left
	}
	else {
	left=0
	}
	PageURL=popURL;
	settings="toolbar=0,location=0,directories=0,"+
	"status=0,menubar=0,scrollbars=" +Scrolling+","+
	"resizable="+ resizable +",width="+wt+",height="+ht+
	",top=" + top + ",left="+ left;
	popWin=window.open(PageURL,WindowName,settings);
	
	//popWin.creator=self;
	popWin.focus();	
	//popWin.print();
}

 function showElement(elemID) {
	if (isIE4up) {
		document.all[elemID].style.visibility = "visible";
	} else if (isNN4up) {
		document.layers[elemID].visibility = "show";
	}
 } 

 function hideElement(elemID) {
	if (isIE4up) {
		document.all[elemID].style.visibility = "hidden";
	} else if (isNN4up) {
		document.layers[elemID].visibility = "hide";
	}

 }

 function updateElement(elemID,elemMsg) {
	if (isIE4up) {
		document.all[elemID].innerHTML = elemMsg;
	} else if (isNN4up) {
		document.layers[elemID].document.open();
		document.layers[elemID].document.write(elemMsg);
		document.layers[elemID].document.close();
	}
 }

 function showImage(img,options) {
	PageURL="VR_Image.asp?img="+img+"&options="+options;

	settings="toolbar=0,location=0,directories=0,"+
	"status=0,menubar=0,scrollbars=1,"+
	"resizable=0,width=660,height=510";
	
	MyNewWindow=window.open(PageURL,"image",settings);
 }

 function changeImg(imgName,imgSrc,optionNumber) {
	var tempSrc = imgSrc.substring(0,imgSrc.lastIndexOf("."));
	if (optionNumber > 0) {
		tempSrc = tempSrc + optionNumber + ".jpg"
	} else {
		tempSrc = tempSrc + ".jpg"
	}
	// alert(tempSrc);
	if (document.images) {
		document[imgName].src=tempSrc;
	}
 }
 
 function checkNumeric(objName,minval, maxval,comma,period,hyphen,allowformatCurrency)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{if (allowformatCurrency=='1'){
	objName.value=numberfield.value;
	return true;
	}else
	{
	objName.value=formatCurrency(numberfield.value);
	return true;
	}
				
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

for (i = 0;  i < checkStr.value.length;  i++)
{
ch = checkStr.value.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{	
alertsay = "Please enter only numeric values \""
alertsay = alertsay + checkOK + "\"" //in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseFloat(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
{
alertsay = "Please enter a value greater than or "
alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}
}
function Calculate(){
 var answer = '';
    for (var i = 0; i<document.Form1.elements.length; i++) {
        if ((document.Form1.elements[i].name.indexOf('txt') > -1)) {
            if (document.Form1.elements[i].value.length != 0 || isNAN(eval(document.Form1.elements[i].value))) {
                //answer += document.Form1.elements[i].options[document.Form1.elements[i].selectedIndex].value + ' ';
                answer += eval(document.Form1.elements[i].value) ;

            }
        }
    }
    document.Form1.answer.value = answer;
alert("Calculate");
} 
//Begin
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
//num = num.substring(0,num.length-(4*i+3))+','+
num = num.substring(0,num.length-(4*i+3))+
num.substring(num.length-(4*i+3));
//return (((sign)?'':'-') + '$' + num + '.' + cents);
return (((sign)?'':'-') + num + '.' + cents);
}
//  End -->

///Date Validation

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// 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 isDate(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 ValidateDate(objDate){
	var dt=objDate//document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

//-------------US TElephone format

var n;
var p;
var p1;
function ValidatePhone(){
p=p1.value
if(p.length==3){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	//pp="("+pp+")";
	document.frmPhone.txtphone.value="";
	document.frmPhone.txtphone.value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		//alert(p31);
		document.frmPhone.txtphone.value="";
		document.frmPhone.txtphone.value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	document.frmPhone.txtphone.value="";
	pp="("+p13+")"+p14+p15;
	document.frmPhone.txtphone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	document.frmPhone.txtphone.value="";
	document.frmPhone.txtphone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
}
//}
setTimeout(ValidatePhone,100)
}
function getIt(m){
n=m.name;
//p1=document.forms[0].elements[n]
p1=m
ValidatePhone()
}
function testphone(obj1){
p=obj1.value
//alert(p)
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
}
}
//  End -->

function digitvalidation(entered, min, max, alertbox, datatype)
{



with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") 
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);  entered.select(); entered.focus();} return false;}
else {return true;}
}
} 
function CheckboxHeaderClick(gridId,chkID)
{
    var oGrid = igtbl_getGridById(gridId);
    var check=true;
    var j=0;
    var chkSpecial;
    var count = oGrid.Rows.length;
    if (chkID==null)
    chkID = 'chkSpecial';
    chkSpecial = igtbl_getElementById(chkID);

    //Get the check all boxes state
    check = chkSpecial.checked;

    //Set all other checkboxes accordingly
    var e = document.forms[0].elements;
    //igtbl_dontHandleChkBoxChange = true;
    for (i=0; i<e.length; i++)
    {
        if ((e[i].type == 'checkbox') && (e[i].outerHTML.indexOf(gridId) > 0))
        e[i].checked = check;
    }
    //igtbl_dontHandleChkBoxChange = false;
}

