// JavaScript Document
var isIE=1;
var isSaf=0;
if (navigator.userAgent.indexOf("MSIE")==-1){isIE=0};
if (navigator.userAgent.indexOf("AppleWebKit")>=0){isSaf=1};



function getObj(objID) {
	
    // Chino's Super Duper DOM addressing script (xbrowser within limits..:-)
    if(document.getElementById && document.getElementById(objID)) {
	// W3C
	//alert("document.getElementById(objID)");
	return document.getElementById(objID);
    } else if (document.all && document.all(objID)) {
	// IE4
	//alert("document.all(objID)");
	return document.all(objID);
    } else if (document.layers && document.layers[objID]) {
	// NS4 .. note: not perfect.. this will not find nested layers
	//alert("document.layers[objID]");
	return document.layers[objID];
    } else {
    // returning 0, will not work for anything else
	//alert("false");
	return false;
    }
} 
function sbtnHot(id){getObj(id).className = "sbtn_r"};
function sbtnOff(id){getObj(id).className = "sbtn"};
function bannerHot(id){getObj(id).className = "banner_memu_over"};
function bannerOff(id){getObj(id).className = "banner_menu_acti"};
toarray = new Array();
function showBtn(x){
	getObj("btn"+x).className = "vbtn";
	for(i=1000;i<1100;i++){getObj("btn"+i).className = "vbtn"};
	getObj("btn"+x).className = "vbtn";
	//n = parseInt(Math.random() * 2);
	//btn = "btn"+x;
	//toarray[n] = window.setTimeout("exShowBtn(btn)",1); 
}

function exShowBtn(btn){
	getObj(btn).className = "vbtn";
}
function hideBtn(x){
	getObj("btn"+x).className = "hbtn";
}
function showpage(p,t,b){
	getObj("btn"+b).className = "vbtn";
	for(x=1;x<t+1;x++){
		myPg = getObj("pg"+x);
		if(myPg != false){myPg.style.display = "none"};
	}
	getObj("pg"+p).style.display = "inline";
}
function showPageBtn(x){
	getObj("btn"+x).className = "vbtn";
}
function showMainBtn(x){
	for(i=1;i<5;i++){
		getObj("btn"+i).className = "vbtn";
	}
}
function btnRollover(id){
		getObj(id).className="btn_dn"
		getObj(id+"-b1").style.visibility="hidden";
		getObj(id+"-b2").style.color="#ffffff";
		}
function btnRollout(id){
		getObj(id).className="btn_up"
		getObj(id+"-b1").style.visibility="visible";
		getObj(id+"-b2").style.color="#000000";
		}
function doJrollin(id){
	if(getObj(id).className =="btndisabled"){ return(false) };
	getObj(id).src=eval(id+"_bd").src;
	}
function doJrollout(id){
	if(getObj(id).className =="btndisabled"){ return(false) };
	getObj(id).src=eval(id+"_bu").src;
	}
	
function doAlert(msg){
		alert(msg);
}
function enC(str){
	s = ""
	a = new Array();
	for(z=0;z<str.length;z++){
		a.push(str.charCodeAt(z));
		}
	for(z=0;z<a.length;z++){
		s+= String.fromCharCode(a[z] + 2);
		}
	return(escape(s));
	}
	
function denC(str){
	s = ""
	str = unescape(str);
	a = new Array();
	for(z=0;z<str.length;z++){
		a.push(str.charCodeAt(z));
		}
	for(z=0;z<a.length;z++){
		s+= String.fromCharCode(a[z] - 2);
		}
	return(escape(s));
	}
	
function cap1stChar(theString){
	ch = theString.slice(0,1);
	chs = theString.slice(1);
	ch = ch.toUpperCase();
	return(ch+chs);
}


function hilite(id){
	getObj(id).value = "";
	getObj(id).className = "input2b";
	getObj(id).focus();
	}
function hiliteSelect(id){
	getObj(id).value = "";
	getObj(id).className = "style_select2b";
	getObj(id).focus();
	}
function hiliteFind1(id){
	getObj(id).value = "";
	getObj(id).className = "style_input2b";
	getObj(id).focus();
	}	
function hiliteFind2(id){
	getObj(id).value = "";
	getObj(id).className = "style_input2c";
	getObj(id).focus();
	}		
function hiliteNone(id){
	getObj(id).value = "";
    getObj(id).className = "input2bNone"; 
	getObj(id).focus();
	}

function makeDays(day){
	s = "<select name='dob_day' id='dob_day' style='width:40px;padding-left:-1px;' class='style_select'>";

	for(x=1;x<32;x++){
		if(x.toString()==day){
			s += "<option SELECTED value='"+x+"'>"+x+"</option> \n";
			}else{
			s += "<option value='"+x+"'>"+x+"</option> \n";
			}
		}
	s += "</select>";
	getObj("day_slot").innerHTML = s;
	}

function makeMonths(mon){
s = "<select name='dob_month' id='dob_month' style='width:50px;padding-left:-1px;' class='style_select'> \n";
a = ["", "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" ]
for(x=0;x<13;x++){
	if(x==mon){
		s += "<option SELECTED value='"+x+"'>"+a[x]+"</option> \n";
		}else{
		s += "<option value='"+x+"'>"+a[x]+"</option> \n";
		}
	}
s += "</select>";
getObj("month_slot").innerHTML = s;
}

function makeYears(year){
	s = "<select name='dob_year' id='dob_year' style='width:52px;padding-left:-1px;' class='style_select'>";
	d = new Date();
	y = d.getFullYear();
	if(y<2000){y = y+1900};
	if (y<2007){y=2007};
	y = y - 16; // age limit
	 for(x=y;x>(y-100);x--){
		if(x.toString()==year){
			s += "<option SELECTED value='"+x+"'>"+x+"</option> \n";
			}else{
			s += "<option value='"+x+"'>"+x+"</option> \n";
			}
		}
	s += "</select>";
	getObj("year_slot").innerHTML = s;
	}


	//==============Slip Month, Day Year================== 
	function slipMonth(s){
		var intmonth=s.indexOf("/");			
		return s.substr(0,intmonth);
	}
	function slipDay(s){
		var intmonth=s.indexOf("/");
		s=s.substr(intmonth+1);
		var intday=s.indexOf("/");
		return s.substr(0,intday);
	}
	function slipYear(s){
		var intmonth=s.indexOf("/");
		s=s.substr(intmonth+1);
		var intday=s.indexOf("/");		
		return s.substr(intday+1);
	}
				
			
	function getYear(d) {
		return (d < 1000) ? d + 1900 : d;
	}			
			
	function isDate (year, month, day) {
		// month argument must be in the range 1 - 12
		month = month - 1; // javascript month range : 0- 11
		var tempDate = new Date(year,month,day);
		if ((getYear(tempDate.getYear()) == year) && (month == tempDate.getMonth()) &&	(day == tempDate.getDate()) && year >1900) {
			return true;
		} else {
			return false;
		}
	}
			
	function checkDate(s){
		var month=slipMonth(s);
		var day=slipDay(s);
		var year=slipYear(s);
		if(isDate(year, month, day)) {
			return true;
		} else {
			return false;
		}
	}		
	//==============================================	

	function isValidEmail(email) {
		// validate email
		// NamPham - 080223
		atSignIndex = email.indexOf("@");
		dotIndex = email.indexOf(".");
	    if((atSignIndex<=0)||(dotIndex<=0)||(dotIndex==email.length-1)||(dotIndex < atSignIndex)||email.length < 5)  {
			return(false);
		}
		return(true);
	}
	
	function checkAllowedChars(s, allowed) {
		// check string if it contains only allowed characters
		// NamPham - 080227
		for (x = 0; x < s.length; x++) {
			if (allowed.indexOf(s.charAt(x))<0){
				return false;
			};
		}
		return true;
	}
	
function selectDefaultCountry() {
	//alert("TATA");
    var countrySelect = getObj('country');
    if (countrySelect.selectedIndex == 0) {
        for (i = 0; i < countrySelect.options.length; i++) {
            if (countrySelect.options[i].value == "US") {
                countrySelect.selectedIndex = i;
                break;
            }
        }
    }
}

function updateStateSelector() {
    var countrySelect = getObj('country');
    var stateSelect = getObj('state');
    
    if (countrySelect.options[countrySelect.selectedIndex].value == "US") {
        if (stateSelect.selectedIndex == stateSelect.options.length - 1)
            stateSelect.options[0].selected = true
        stateSelect.disabled = false;
    } else {
        // select 'Not Applicable'
        stateSelect.options[stateSelect.options.length - 1].selected = true
        stateSelect.disabled = true;
    }
}

function updateCanadaStateSelector() {
    var countrySelect = getObj('country');
    var stateSelect = getObj('state');
    
    if ((countrySelect.options[countrySelect.selectedIndex].value == "US") || (countrySelect.options[countrySelect.selectedIndex].value == "CA")) {
        if (stateSelect.selectedIndex == stateSelect.options.length - 1)
            stateSelect.options[0].selected = true
        stateSelect.disabled = false;
    } else {
        // select 'Not Applicable'
        stateSelect.options[stateSelect.options.length - 1].selected = true
        stateSelect.disabled = true;
    }
}



function doClick(buttonName,e)
{

//the purpose of this function is to allow the enter key to 
//point to the correct button to click.

    var key;

    if(window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13)
    {
        //Get the button the user wants to have clicked

        var btn = document.getElementById(buttonName);
        if (btn != null)
        { //If we find the button click it
            btn.click();
            event.keyCode = 0
        }
    }
}

// popup box
function move_box(an, box) {
  var cleft = 0;
  var ctop = 0;
  var obj = an;
  while (obj.offsetParent) {
    cleft += obj.offsetLeft;
    ctop += obj.offsetTop;
    obj = obj.offsetParent;
  }
  box.style.left = cleft + 'px';
  ctop += an.offsetHeight + 8;
  if (document.body.currentStyle &&
    document.body.currentStyle['marginTop']) {
    ctop += parseInt(
      document.body.currentStyle['marginTop']);
  }
  box.style.top = ctop + 'px';
}

function refreshDiv(divId)
{
    // cause IE refresh div to show scrollbar if available
    getObj(divId).style.display = "block";
}
