    // JScript File
    
var originalColor = "";
var currentPage = "";
var selectedTabColor = "#ffffff"; 
var mouseOverTabColor = "#e0dfe3";
var disabledColor = "#edede6";

function mouseOver(id){
 //alert("mouse over function."+id);  
  if (document.location.toString().toLowerCase().indexOf(id+".php") == -1){
    //originalColor =  document.getElementById(id).style.backgroundColor;
    //SET selected tab color 
//    document.getElementById(id).style.backgroundColor = mouseOverTabColor;
  }else{
//    document.getElementById(id).style.cursor = "pointer";
  }
}

function mouseOut(id){
//  alert("mouse out function.");   
  if (document.location.toString().toLowerCase().indexOf(id+".php") == -1){
//    document.getElementById(id).style.backgroundColor = originalColor;
  }
}

function getPage(page){
  //alert(page);
  if (document.location.toString().toLowerCase().indexOf(page+".php") == -1){
    document.location = ""+page+".php";
  }
}

function setSelectedTab(page){
  document.getElementById(page).style.backgroundColor = selectedTabColor;
  document.getElementById(page).style.borderBottom = "";
  document.getElementById(page).style.cursor = "default";
}

function onloadHandler(){
  if (document.location.toString().indexOf("branchall.php") != -1){
    setSelectedTab("branchall");
  }
  if (document.location.toString().indexOf("default.php") != -1){
    setSelectedTab("default");
  }
  if (document.location.toString().indexOf("contact.php") != -1){
    setSelectedTab("contact");
  }
  if (document.location.toString().indexOf("franchise.php") != -1){
    setSelectedTab("franchise");
  }
}


function isblank(s)
{
  for(var i=0; i<s.length; i++){
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
  }
  return true;
}

function changeDate(dateObjName,wkdayObjName,val){
  var dateObj = eval("document.forms[0]."+dateObjName+"");
  var dteStr = dateObj.value;
  wkDayArray = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday";
  
  dteStr = dteStr.split("-");
  var dte = new Date(dteStr[0]+"/"+dteStr[1]+"/"+dteStr[2]);

   dte.setDate(dte.getDate()+val);
  //dte.setDate(dte.getDate()+(7+dte.getDay()-1)%7);

  dateObj.value = dte.getFullYear()+"-"+(dte.getMonth()+1)+"-"+dte.getDate();
  
  if (wkdayObjName != ""){
    if (eval("document.forms[0]."+wkdayObjName) != null){
      eval("document.forms[0]."+wkdayObjName+".value =wkDayArray.split(',')[dte.getDay()]");
    } 
  }
  
  if (val == 7 || val == -7)
    document.forms[0].submit(); 
}

function validBlank(obj, msg){
  if (isblank(obj.value)){
    alert(msg);
    obj.focus();
    obj.select();
    return false;
  }else
    return true;
}

function validPositiveNum(obj, msg){
	//allow blank
	if (!isblank(obj.value)){
		if (!CheckIsPositiveNumber(obj.value)){
			alert(msg);
			obj.focus();
			obj.select();
			return false;
		}else
			return true;
	}else
		return true;
}

function checkIsInteger(obj){
	aVal = obj.value.toString();
	if (aVal !=""){
		var IntegerNumber=/^(\d{1,20})$/;
		var matchArray = aVal.match(IntegerNumber);
		if (matchArray == null){
			alert(obj.name.toUpperCase() + " field accepts Integer number only.");
			obj.focus();
			obj.select();
			return false ;
		}
	}	
	return true ;
}

function CheckIsPositiveNumber(aVal){
	if (aVal !=""){
		var IntegerNumber=/^(\d{1,20}[.]{0,1}\d{0,20})$/;
		var matchArray = aVal.match(IntegerNumber);
		if (matchArray == null){
			return false ;
		}
	}	
	
	return true ;
}


function checkTextLength(obj, maxlength){
	//Check Text length on TEXTAREA
	document.getElementById(obj.name+"_textareachars").innerHTML = maxlength-obj.value.length;
	if (obj.value.length >= maxlength){
		obj.value = obj.value.substring(0,maxlength);
	}
}

function createOptionForSelect(objName, strValue, strText, action, selected){

//	var selectObj = eval("document.forms[0]."+objName);
	var selectObj = document.getElementById(objName);

	if (action == "create"){
		//Create new OPTION item for SELECT box
		var newelem=document.createElement("OPTION");
		newelem.text=(strText);
		newelem.value=strValue;
		newelem.selected = selected;
		selectObj.options.add(newelem);
		delete newelem; //delete object.
	}else if (action == "remove"){
	  curlen=selectObj.options.length;
		for (i=curlen; i>=0; i--) {
		   selectObj.remove(0);
		}
	}
}

function getDatePicker(calObj,frmElement,displayTime, callBackFunction){
	if (document.forms[0].dirtyform != null){
		//if from ORDER FORM, warning before popup calendar
		if (document.forms[0].dirtyform.value == "1"){ 
			allowChangeDate = false;
			if (confirm("Have you saved your data? If not, click Cancel button to save your data first!")){
				allowChangeDate = true;
			}
		}else
			allowChangeDate = true;
	}else
		allowChangeDate = true;
	
	
	if (allowChangeDate){
		//work with calendar
		eval(calObj+"= new calendar1(frmElement)");
		//display year button or not. Not work with current object
		eval(calObj+".year_scroll = true");
		//display time box or not
		eval(calObj+".time_comp = displayTime");
		//define calendar position
		eval(calObj+".left = document.getElementById('"+calObj+"_gif').offsetLeft-150");
		eval(calObj+".top = document.getElementById('"+calObj+"_gif').offsetTop+10");

//alert(document.getElementById(calObj+"_gif").offsetTop);	
//		eval(calObj+".top = document.getElementById('"+calObj+"_gif').offsetTop+100");
		eval(calObj+".callBackFunction = callBackFunction;");

		//open calendar
		eval(calObj+".popup()");
	}
}

/**
 * Format date get from Calendar to dd mmm yyyy hh:mm
 */
function formatInputDate(obj,displaySecond){
 	aryMonths = Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	aryDate = obj.value.split(" ");
	aryDateVal = aryDate[0].split("/");

	if (aryDate.length > 1){
		timeVal = aryDate[1];
		if (displaySecond != ""){
			//Not display second
			aryTimeVal = timeVal.split(":");
			timeVal = aryTimeVal[0]+":"+aryTimeVal[1];
		}
	}else{
		timeVal = "";
	}
	day = aryDateVal[0];
	mth = aryDateVal[1];
	year = aryDateVal[2];
	obj.value = day+" "+aryMonths[mth-1]+" "+year+ " " + timeVal;
}


function ajaxGet(target,objValue,callBackFunction){
	aUrl = rooturl+"index.php?ajax="+target+"&val="+objValue+"&"+Math.floor(Math.random()*10000);

	contentType = "text/plain";
	val = globalGetDetails(aUrl,contentType,callBackFunction);
}


function globalGetDetails(aURL,ContentType,callBackFunc){
	//Ajax Request
	var details;
	var http_request =false;

	try {
		if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {}
			}
		}else if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
//					http_request.overrideMimeType('text/xml');
					http_request.overrideMimeType(ContentType);
			}
		}

		http_request.onreadystatechange=function()
      {
      if(http_request.readyState==4)
        {
        	if (callBackFunc != ""){
        	  eval(callBackFunc+'("'+http_request.responseText+'")');
        	}
        }
      }
    http_request.open("GET",aURL,true);
    http_request.send(null);
    
    
	}catch (exception) {
	}
}


function replaceAll(strValue, findChar, replaceChar){
/************************************************
DESCRIPTION: Replace all instance of findChar.
Note: if passed \, user should pass with delimitor like this \\
*************************************************/ 
	findChar = "/"+findChar+"/g";
	strValue = strValue.replace(eval(findChar),replaceChar);
	return strValue;
}

function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}

function refresh(){
	document.location = document.location;
}

//http://snippets.dzone.com/posts/show/425
// n=number, c=float point cutoff, d=deciman separator, t=thousand separator
/*fmtMoney = function( n, c, d, t ) {
	var m = ( c = Math.abs( c ) + 1 ? c : 2, d = d || ",", t = t || ".", /(\d+)(?:(\.\d+)|)/.exec( n + "" ) ), x = m[1].length % 3;
	return ( x ? m[1].substr( 0, x ) + t : "" ) + m[1].substr( x ).replace( /(\d{3})(?=\d)/g, "$1" + t ) + ( c ? d + ( +m[2] ).toFixed( c ).substr( 2 ) : "" );
};
*/

//Not work with 1.9984 format
fmtMoney = function(n, c, d, t){ //v1.0
var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".",
/(\d+)(?:(\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0;
return (x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(\d{3})(?=\d)/g,
"$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : "");
};


/*Parse number to currency format:
By Website Abstraction (www.wsabstract.com)
and Java-scripts.net (www.java-scripts.net)
*/

//Remove the $ sign if you wish the parse number to NOT include it
var prefix="";
var wd
function parseelement(thisone){
	if (thisone.value.charAt(0)=="$")
		return
	if (thisone.value.indexOf(",")!=-1)
		return

	wd="w"
	var tempnum=thisone.value
	for (var i=0;i<tempnum.length;i++){
		if (tempnum.charAt(i)=="."){
			wd="d"
			break
		}
	}
	
	if (wd=="w")
		thisone.value=prefix+tempnum+".00"
	else{
		if (tempnum.charAt(tempnum.length-2)=="."){
			thisone.value=prefix+tempnum+"0"
		}
		else{
			tempnum=Math.round(tempnum*100)/100
			thisone.value=prefix+tempnum
		}
	}
	
	//add thousand separator 
	tempnum = thisone.value;
	var tmpamount = "";
	count = 0;
	for (var i=tempnum.length;i>=0;i--){
		if ((count % 3) == 0 && count != 0 && tempnum.charAt(i)!="."){
			tmpamount = tempnum.charAt(i)+","+tmpamount;	
		}else{
			tmpamount = tempnum.charAt(i)+tmpamount;	
		}
		count ++;
		if (tempnum.charAt(i)=="."){
			count = 0;
		}		
//alert("comer:" + tmpamount);		
	}
		thisone.value = tmpamount;
}


//This works
//http://javascript.internet.com/forms/currency-format.html
function formatCurrency(num) {
	comma = ",";
	dollarSign = "";
	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))+comma+ num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + dollarSign + num + '.' + cents);
}

function removeCurrencyFormat(num) {
	return replaceAll(num,",","");
}

//YuanFu specific
//rounding at 8 up, 7 down
function roundPayAmount(num){
	var tmpnum = parseFloat(num)-0.03;
	return Math.round(tmpnum*10)/10;
}

//YuanFu specific
//rounding at 8 up, 7 down
function roundRecAmount(num){
	var tmpnum = parseFloat(num)+0.03;
	return Math.round(tmpnum*10)/10;
}

function formatRate(num) {
	var tmpnum = parseFloat(num);
	return Math.round(tmpnum*10000)/10000;
}

//parse value as Float and remove 
function getFloat(val){
	tmpval = replaceAll(val,",","");	
	return parseFloat(tmpval);
}

//pre-select SELECT box 
function _getSelectValue(objName,value){
	var obj = document.getElementById(objName);
	for (var o=0;o<obj.options.length;o++){
		if (obj.options[o].value == value){
			obj.options[o].selected = true;
		}
	}
}

function SubmitEnter(targetObj,e,callbackFunction)
{
 var keycode;
 if (window.event) keycode = window.event.keyCode;
 else if (e) keycode = e.which;
 else return true;

 if (keycode == 13){
	 if (callbackFunction != ""){
		 eval(callbackFunction+"();");
	 }
	 return false;
 }else
	 return true;
}

function turnOffBubbleCapture(e){
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}


$().ready(function() {
	$('#divHome').click(function(){
		document.location = "homepage.html";
	});
});