﻿//========================  get  Object from Document  ==============================
function getObj(idname)
{
	if (getObj)
	{
	    if (document.getElementById(idname)) return document.getElementById(idname);
	    if (document.getElementById("ctl00_"+idname)) return document.getElementById("ctl00_"+idname);
	    if (document.getElementById("ctl00_Top1_"+idname)) return document.getElementById("ctl00_Top1_"+idname);  
	    if (document.getElementById("ctl00_BodyCenter_"+idname)) return document.getElementById("ctl00_BodyCenter_"+idname); 
		return null;
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}

//========================  Write Message  ==============================
function myPrint(msg)
{
    var divPrint = getObj("divPrint");
    if (!divPrint)  
   { 
        divPrint = document.createElement("div");
        divPrint.id = "divPrint"; 
        document.body.insertBefore(divPrint,document.body.firstChild);
   }
    var txt = document.createTextNode(" | "+msg);
    divPrint.appendChild(txt);
}
function message(msg) //DON'T USE
{
    var p=window.createPopup();
    var pbody=p.document.body;
    pbody.style.border="solid dimgray 1px"
    pbody.innerHTML=msg;
    p.show(150,150,200,50,document.body);
}
//================================  showPopup ===================================
//----------base function 1
function createMyPopup(w,h,innerHTML)
{
    var popUp = document.createElement("div");
    document.body.appendChild(popUp); 
    popUp.innerHTML = innerHTML;
    popUp.id = "divPaneByCreatePopup";
    popUp.style.position = "absolute";
    if (w) popUp.style.width = w+"px";
    if (h) popUp.style.height = h+"px";
    popUp.style.top = Math.round((document.documentElement.clientHeight/2)-(popUp.clientHeight/2)+document.documentElement.scrollTop)+'px';
    popUp.style.left = Math.round((document.documentElement.clientWidth/2)-(popUp.clientWidth/2))+"px";
    return popUp;
}
function removeMyPopup()
{
    var div = getObj("divPaneByCreatePopup");
    document.body.removeChild(div); 
}
//-----------base function 2
function disableBG()
{
    var bodyx = getObj("bodyx");
    if (bodyx)
    {
        bodyx.style.display = "";
        return;
    }
    bodyx = document.createElement("div");
    bodyx.id = "bodyx";
    bodyx.style.position = "absolute";
    bodyx.style.top = "0px";
    bodyx.style.left = "0px";
    bodyx.style.width = document.body.clientWidth-5;
    bodyx.style.height = document.body.clientHeight;
    bodyx.style.border = "solid 1pt gray";
    bodyx.style.filter = "alpha(opacity:1)";
    bodyx.style.backgroundColor = "black";
    document.body.appendChild(bodyx);
   
    jsUtil_showHideCombo(false);
}
function enableBG()
{
    jsUtil_showHideCombo(true);
    bodyx.style.display = "none";
}
//-----------base function 3
function jsUtil_showHideCombo(isShow)
{
        //print(isShow);
		var combos = document.all.tags("select");
		for (var i = 0; i < combos.length; i++)
		{
            combos[i].style.visibility = isShow?"visible":"hidden";
		}
};

//-----------------------------------------
function createMyPopupAjax(w,h)
{
    var popUp = createMyPopup(w,h);
    var divAjax = document.createElement("div");
    divAjax.id = "divAjax";
    popUp.appendChild(divAjax);
    return popUp;
}

//function alert(msg)
//{
//    var innerHMTL = "";
//    innerHMTL += "<table style=\"border:solid 2px black; width:300px;\" cellspacing=\"0\">";
//    innerHMTL += "<tr><td align=\"center\" colspan=\"2\" background=\"../images/util/2.gif\" style=\"height:23px\" >&nbsp;</td></tr>";
//    innerHMTL += "<tr style=\"background-image: url(../images/util/5.gif); \">";
//    innerHMTL += "<td align=\"center\"  style=\"vertical-align:bottom;\"><img src=\"../images/util/callcenter.jpg\" /></td> ";
//    innerHMTL += "<td nowrap=\"nowrap\"  align=\"left\" style=\"padding:0px 10px 0px 10px; vertical-align:middle;\"> ";
//    innerHMTL += msg;
//    innerHMTL += "<br><br><img src=\"../images/util/10.gif\" style=\"cursor:hand; text-align:right; \" onclick=\"myAlertDel()\" /><br> ";
//    innerHMTL += "<img src=\"../images/spacer.gif\" /></td></tr></table> ";

//    disableBG();
//    createMyPopup(null,null,innerHMTL);
//}

function myAlertDel()
{
    enableBG();
    removeMyPopup();
}



//============================ Cookies Module ==================================
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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//============================ Check & UnCheck All ==================================
function checkAll()
{
		var chkCatalog = document.getElementsByTagName("input");
		var index = 0;
		for (var i = 0; i < chkCatalog.length; i++)
		{
			if (chkCatalog[i].type.toUpperCase() == "CHECKBOX" && chkCatalog[i].id.search("chkProduct") != -1)
			{
			    chkCatalog[i].checked = true;
			    index += 1;
			}
		}
}
function uncheckAll()
{
		var chkCatalog = document.getElementsByTagName("input");
		var index = 0;
		for (var i = 0; i < chkCatalog.length; i++)
		{
			if (chkCatalog[i].type.toUpperCase() == "CHECKBOX" && chkCatalog[i].id.search("chkProduct") != -1)
			{
			    chkCatalog[i].checked = false;
			    index += 1;
			}
		}
}

//============================ Math Module ==================================
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

//============================ String Module ============================
function Trim(TRIM_VALUE){
    if(TRIM_VALUE.length < 1){
      return"";
    }
    TRIM_VALUE = RTrim(TRIM_VALUE);
    TRIM_VALUE = LTrim(TRIM_VALUE);
    if(TRIM_VALUE==""){
      return "";
    }
    else{
      return TRIM_VALUE;
    }
}

function RTrim(VALUE){
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";
    if(v_length < 0){
        return"";
    }
    var iTemp = v_length -1;
    while(iTemp > -1){
          if(VALUE.charAt(iTemp) == w_space){
          }
          else{
            strTemp = VALUE.substring(0,iTemp +1);
            break;
          }
          iTemp = iTemp-1;
    } //End While
    return strTemp;
} //End Function

function LTrim(VALUE){
    var w_space = String.fromCharCode(32);
    if(v_length < 1){
        return"";
    }
    var v_length = VALUE.length;
    var strTemp = "";
    var iTemp = 0;
    while(iTemp < v_length){
          if(VALUE.charAt(iTemp) == w_space){
          }
          else{
            strTemp = VALUE.substring(iTemp,v_length);
            break;
          }
          iTemp = iTemp + 1;
    } //End While
    return strTemp;
} //End Function

