// JavaScript Document



function checkemail(str){
var invalidaddress=new Array();
invalidaddress[0]="bbb";
invalidaddress[1]="abc";
invalidaddress[2]="xxx";
invalidaddress[3]="xyz";
invalidaddress[4]="aaa";
var testresults;
var invalidcheck=0;
//var str=document.validation.emailcheck.value
var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str)){
var tempstring=str.split("@")
tempstring=tempstring[1].split(".")
if(tempstring[0].length<2||tempstring[1].length<2){invalidcheck=1}
else{
for (i=0;i<invalidaddress.length;i++){
	if (tempstring[0]==invalidaddress[i])invalidcheck=1
	}
}

if (invalidcheck!=1)
testresults=true
else{
testresults=false
}
}
else{
testresults=false
}
return (testresults)
}

/*function checkbae(){
if (document.layers||document.getElementById||document.all)
return checkemail()
else
return true
}
*/


function GetXmlHttpObject(handler)
{
	var objXmlHttp=null
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("AJAX doesnt work in Opera")
		return;
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
	{
		strName="Microsoft.XMLHTTP"
	}
	try
	{
		objXmlHttp=new ActiveXObject(strName)
		objXmlHttp.onreadystatechange=handler
		return objXmlHttp
	}
	catch(e)
	{
		alert("Error. Scripting for ActiveX might be disabled")
		return
	}
	}
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler
		return objXmlHttp
	}
}

function submitonce(theform){
	if (document.all||document.getElementById){
	for (i=0;i<theform.length;i++){
		var tempobj=theform.elements[i]
		if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
		{tempobj.value='Processing ...';tempobj.disabled=true;}
		}
	}
}

function getfee(id,elm,schpgmid)
{
	var i;
	var f = document.form1;
	var oFee;
	var count = document.form1.feecount.value;
	var myval = elm.value;
	var feeid1 = "csfee"+id;
	var feeid2 = "isfee"+id;
	
	for(i=1;i<=count;i++){
		oFee = eval('document.form1.schpgm_id'+i);
		if( i != id && oFee.value != '0' ){
				if( myval == oFee.value ){
				   alert('ERROR!\n\nYou selected this item already. \nPlease try another one.');
				   elm.value = '0';
				//	document.getElementById(feeid1).innerHTML="";
				//	document.getElementById(feeid2).innerHTML="";
				   //calfee2();
				   return;
				   }
		  }
	}
	document.form1.feeid.value = id;
	
	if ( schpgmid != "0" && schpgmid != "" )
		{
			var url="StudentAppFormGetfee.asp?schpgmid="+schpgmid+"&sid="+Math.random();
			xmlHttp=GetXmlHttpObject(stateChanged);
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		}
		else
		{
			document.getElementById(feeid1).innerHTML="";
			document.getElementById(feeid2).innerHTML="";
			calfee2();
		}
}



function calfee2(){
	var count = document.form1.feecount.value;
	var type  = document.form1.typeidval.value;
	var internationalstyle;
	var canadianstyle;
	var tcsfee = 0 ;
	var tisfee = 0 ;
	var csfee;
	var isfee;
	var i;
	var feeid1;
	var feeid2;
	
	if(type=='1'){
		internationalstyle = '';
		canadianstyle = 'none';
		}
	 else{
		internationalstyle = 'none';
		canadianstyle = '';
		}
	
	for(i=1;i<=count;i++){
		feeid1 = "csfee" + i;
		feeid2 = "isfee" + i;
		
		csfee = document.getElementById(feeid1).innerHTML;
		isfee = document.getElementById(feeid2).innerHTML;
		
		document.getElementById(feeid1).style.display=canadianstyle;
		document.getElementById(feeid2).style.display=internationalstyle;
		
		
		if(csfee=='') {csfee="0";isfee="0";}
		
		tcsfee = tcsfee + parseFloat(onlynum(csfee));
		tisfee = tisfee + parseFloat(onlynum(isfee));

		}	
		document.form1.csa.value = formatnumber(tcsfee,"",2) ;
		document.form1.isa.value = formatnumber(tisfee,"",2) ;

		document.getElementById('csa').style.display=canadianstyle;
		document.getElementById('isa').style.display=internationalstyle;

}

function getfee1(id,elm,schpgmid)
{
	var i;
	var f = document.form1;
	var oFee;
	var count = document.form1.feecount.value;
	var myval = elm.value;
	var feeid1 = "csfee"+id;
	var feeid2 = "isfee"+id;
	
	for(i=1;i<=count;i++){
		oFee = eval('document.form1.schpgm_id'+i);
		if( i != id && oFee.value != '0' ){
				if( myval == oFee.value ){
				   alert('ERROR!\n\nYou selected this item already. \nPlease try another one.');
				   elm.value = '0';
				   	document.getElementById(feeid1).innerHTML="";
					document.getElementById(feeid2).innerHTML="";
					calfee2();
				   return;
				   }
		  }
	}
	document.form1.feeid.value = id;
	
	if ( schpgmid != "0" && schpgmid != "" )
		{
			var url="../StudentAppFormGetfee.asp?schpgmid="+schpgmid+"&sid="+Math.random();
			xmlHttp=GetXmlHttpObject(stateChanged);
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		}
		else
		{
			document.getElementById(feeid1).innerHTML="";
			document.getElementById(feeid2).innerHTML="";
			calfee2();
		}
}

function getbyid(id)
{
   itm = null;
   if (document.getElementById)
   {
      itm = document.getElementById(id);
   }
   else if (document.all)
   {
      itm = document.all[id];
   }
   else if (document.layers)
   {
      itm = document.layers[id];
   }
    return itm;
}


function show(id,arg){
	if(arg) {
		id.style.display = ''
		}
		else
		{
			id.style.display = 'none'
			}
	
	}


function chkpgm()
{
	var i;
	var f = document.form1;
	var rtn = false;
	var objTemp;
	var count = document.form1.feecount.value;
	
	for(i=1;i<=count;i++){
		objTemp = eval('document.form1.schpgm_id'+i);
		if( objTemp.value != '0' )	rtn = true;
	}
	return rtn;
}


function chkform1(f)
{
	var msg = ' Please finish the following highlight fields: \n\n';
	var bgcolor = '#FFFF66';
	var rtn = true;
	var i = 0;
	
	if(!checkemail(f.email.value)){ msg= msg + '* Invalid Email Address!\n';
			f.email.style.backgroundColor=bgcolor;f.lastname.focus();rtn=false; }
	if(f.firstname.value==''){ i++; msg= msg + i+ ') First name\n';
			f.firstname.style.backgroundColor=bgcolor;f.firstname.focus();rtn=false;}
	if(f.lastname.value==''){ i++; msg= msg+ i + ') Last name\n';
			f.lastname.style.backgroundColor=bgcolor;f.lastname.focus();rtn=false; }
	if(f.dob.value==''){ i++; msg= msg+ i + ') Birthday\n';
			f.dob.style.backgroundColor=bgcolor;f.dob.focus();rtn=false; }
	if(f.nationality.value=='0'){ i++; msg= msg+ i + ') Nationality\n';
			f.nationality.style.backgroundColor=bgcolor;f.nationality.focus();rtn=false; }
	if(f.language.value=='0'){ i++; msg= msg+ i + ') First language\n';
			f.language.style.backgroundColor=bgcolor;f.language.focus();rtn=false; }
	if(f.address.value==''){ i++; msg= msg+ i + ') Address\n';
			f.address.style.backgroundColor=bgcolor;f.address.focus();rtn=false; }
	if(f.city.value==''){ i++; msg= msg+ i + ') City\n';
			f.city.style.backgroundColor=bgcolor;f.city.focus();rtn=false; }
	if(f.province.value==''){ i++; msg= msg+ i + ') Province\n';
			f.province.style.backgroundColor=bgcolor;f.province.focus();rtn=false; }
	if(f.country_id.value=='0'){ i++; msg= msg+ i + ') Country\n';
			f.country_id.style.backgroundColor=bgcolor;f.country_id.focus();rtn=false; }
	if(f.postalcode.value==''){ i++; msg= msg+ i + ') Postal Code\n';
			f.postalcode.style.backgroundColor=bgcolor;f.postalcode.focus();rtn=false; }
	if(f.telephone.value==''&&f.mobile.value==''){ i++; msg= msg+ i + ') Telephone or mobile.\n';
		f.telephone.style.backgroundColor=bgcolor;
		f.mobile.style.backgroundColor=bgcolor;
		f.telephone.focus();
		rtn=false; }
	if(f.visa_id.value=='0'){ i++; msg= msg+ i + ') Type of VISA. \n';
			f.visa_id.style.backgroundColor=bgcolor;f.visa_id.focus();rtn=false; }
	if(f.EnterYear.value=='0'){ i++; msg= msg+ i + ') Year enter. \n';
			f.EnterYear.style.backgroundColor=bgcolor;f.EnterYear.focus();rtn=false; }
			
			
		
	if(!chkpgm()) { i++; msg= msg+ i + ') Please select at least one program/services!\n';
			rtn=false;}

	if(!rtn) alert(msg);

	return rtn;
}


/* 
ec -- element of canadian amount
ei -- element of internation amount
intCamt - canadian amount for this item
intIamt - Internation amount for this item
*/

function calfee1(arg, ec, ei, intCamt, intIamt)
{
	var ctotal = parseFloat(onlynum(ec.value)); // Canadian total 
	var itotal = parseFloat(onlynum(ei.value)); // Internation total 
	
	
	 if(arg) {  // Add
	 //alert('add '+ onlynum(ec.value) + ' ' + ei.value + ' ' + intCamt + ' ' + intIamt )
	 ec.value = formatnumber(ctotal + intCamt,"",2);
	 ei.value = formatnumber(itotal + intIamt,"",2);
	 }
	 else {   // Deduct 
		// alert('deduct '+ onlynum(ec.value) + ' ' + ei.value + ' ' + intCamt + ' ' + intIamt )
	// ec.value = ctotal - intCamt;
	// ei.value = itotal - intIamt;
	 ec.value = formatnumber(ctotal - intCamt,"",2);
	 ei.value = formatnumber(itotal - intIamt,"",2);
	 }

}




function onlynum(str){
	var s; 
	s=str.replace(/\,/g, ""); 
	s=s.replace(/\$/g,"");
	return s;
}



function fix(fixnumber,decimalplaces){
var div=Math.pow(10,decimalplaces);
fixnumber=Math.round(fixnumber*div)/div;
return fixnumber;
}



function formatnumber(arg,prefix,digital){
var num = new NumberFormat();
num.setInputDecimal('.');
num.setNumber(arg); // obj.value is '-1000.244'
num.setPlaces(digital);
num.setCurrencyValue(''+prefix+'');
num.setCurrency(true);
num.setCurrencyPosition(num.LEFT_OUTSIDE);
num.setNegativeFormat(num.LEFT_DASH);
num.setNegativeRed(false);
num.setSeparators(true, ',', ',');
return num.toFormatted();
}

/// === Format number 
function NumberFormat(num, inputDecimal)
{
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.NO_ROUNDING = -1 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.roundToPlaces; 
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal); 
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(false); 
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num, inputDecimal)
{
if (inputDecimal != null) {
this.setInputDecimal(inputDecimal); 
}
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal) {
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
} else {
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp
}
function setPlacesNF(p)
{
this.roundToPlaces = !(p == this.NO_ROUNDING); 
this.places = (p < 0) ? 0 : p; 
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}
function toFormattedNF()
{	
var pos;
var nNum = this.num; 
var nStr;            
var splitString = new Array(2);   
if (this.roundToPlaces) {
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum)); 
} else {
nStr = this.expandExponential(Math.abs(nNum)); 
}
if (this.hasSeparators) {
nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
} else if (this.currencyPosition == this.LEFT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0) {
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getZerosNF(places)
{
var extraZ = '';
var i;
for (i=0; i<places; i++) {
extraZ += '0';
}
return extraZ;
}
function expandExponentialNF(origVal)
{
if (isNaN(origVal)) return origVal;
var newVal = parseFloat(origVal) + ''; 
var eLoc = newVal.toLowerCase().indexOf('e');
if (eLoc != -1) {
var plusLoc = newVal.toLowerCase().indexOf('+');
var negLoc = newVal.toLowerCase().indexOf('-', eLoc); 
var justNumber = newVal.substring(0, eLoc);
if (negLoc != -1) {
var places = newVal.substring(negLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
} else {
if (plusLoc == -1) plusLoc = eLoc;
var places = newVal.substring(plusLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
}
newVal = justNumber;
}
return newVal;
} 
function moveDecimalRightNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, false);
} else {
newVal = this.moveDecimal(val, false, places);
}
return newVal;
}
function moveDecimalLeftNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, true);
} else {
newVal = this.moveDecimal(val, true, places);
}
return newVal;
}
function moveDecimalAsStringNF(val, left, places)
{
var spaces = (arguments.length < 3) ? this.places : places;
if (spaces <= 0) return val; 
var newVal = val + '';
var extraZ = this.getZeros(spaces);
var re1 = new RegExp('([0-9.]+)');
if (left) {
newVal = newVal.replace(re1, extraZ + '$1');
var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');		
newVal = newVal.replace(re2, '$1$2.$3');
} else {
var reArray = re1.exec(newVal); 
if (reArray != null) {
newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length); 
}
var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
newVal = newVal.replace(re2, '$1$2$4.');
}
newVal = newVal.replace(/\.$/, ''); 
return newVal;
}
function moveDecimalNF(val, left, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimalAsString(val, left);
} else {
newVal = this.moveDecimalAsString(val, left, places);
}
return parseFloat(newVal);
}
function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
val = Math.round(val);
val = this.moveDecimalLeft(val);
return val;
}
function preserveZerosNF(val)
{
var i;
val = this.expandExponential(val);
if (this.places <= 0) return val; 
var decimalPos = val.indexOf('.');
if (decimalPos == -1) {
val += '.';
for (i=0; i<this.places; i++) {
val += '0';
}
} else {
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++) {
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
newVal = val + '';
var isPercentage = false;
if (newVal.indexOf('%') != -1) {
newVal = newVal.replace(/\%/g, '');
isPercentage = true; 
}
var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');	
newVal = newVal.replace(re, '');
var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
var treArray = tempRe.exec(newVal); 
if (treArray != null) {
var tempRight = newVal.substring(treArray.index + treArray[0].length); 
newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, ''); 
}
if (newVal.charAt(newVal.length - 1) == this.DASH ) {
newVal = newVal.substring(0, newVal.length - 1);
newVal = '-' + newVal;
}
else if (newVal.charAt(0) == this.LEFT_PAREN
&& newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
newVal = newVal.substring(1, newVal.length - 1);
newVal = '-' + newVal;
}
newVal = parseFloat(newVal);
if (!isFinite(newVal)) {
newVal = 0;
}
if (isPercentage) {
newVal = this.moveDecimalLeft(newVal, 2);
}
return newVal;
}


function high(e,bg,font,cursor){
if (cursor=='')cursor='hand';
e.style.backgroundColor=bg;
e.style.color=font;
e.style.cursor=cursor;
}
function highnews(e){
e.className='newsOver';
}

function unhighnews(e){
e.className='news';
}

function unhigh(e,bg,font){
e.style.backgroundColor=bg;
e.style.color=font;
}

function menuhigh(e){
e.className='MenuOver';
}
function menunhigh(e){
e.className='Menu';
}
function dropmenuhigh(e){
e.className='DropMenuOver';
}
function dropmenunhigh(e){
e.className='DropMenu';
}

function swapval(obj,i,j)
{
   var o = obj.options;
   var i_selected = o[i].selected;
   var j_selected = o[j].selected;
   var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
   var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
   o[i] = temp2;
   o[j] = temp;
   o[i].selected = j_selected;
   o[j].selected = i_selected;
   }

function mvup(obj){
  for(i=0;i<obj.options.length;i++){
     if(obj.options[i].selected){
        if(i != 0 && !obj.options[i-1].selected){
           swapval(obj,i,i-1);obj.options[i-1].selected = true;
        }
       }
     }
  }
  
function mvdn(obj){
 for(i=obj.options.length-1;i>=0;i--){
 	if(obj.options[i].selected){
		if(i !=(obj.options.length-1) && ! obj.options[i+1].selected){
			swapval(obj,i,i+1);obj.options[i+1].selected = true;
		}
	}
 }
}

function openwin(url,name){
var objWin = window.open(url,name,'width=1000,height=600,left=5,top=5,screenX=5,screenY=5,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, directories=yes, status=yes');
objWin.focus();
return false;
}
function openwin1(url,name,width,height){
var objWin = window.open(url,name,'width='+width+',height='+height+',left=5,top=5,screenX=5,screenY=5,toolbar=yes, menubar=no, scrollbars=yes, resizable=yes,location=yes, directories=yes, status=yes');
objWin.focus();
return false;
}

function chknum(fld, e) {
var strCheck = '-0123456789.,';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  
key = String.fromCharCode(whichCode);  
if (strCheck.indexOf(key) == -1) return false;  
}




function autosum(f,objname){
var total = 0;	
var ev;
var theform = eval('document.'+f); //document.forms[0]; 

	if (document.all||document.getElementById){
	for (i=0;i<theform.length;i++){
		var tempobj=theform.elements[i];
		
		if(tempobj.type.toLowerCase()== "text" && tempobj.name == objname)
		     {  
			 	ev = 0;
				if (tempobj.value !='' ) ev = parseFloat(onlynum(tempobj.value))
			    total += ev; 
			 }
		}
  }
 return total;	
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
