function goUrl(url, target)
{
	target.location.href = url;
}

function errorAndFocus(msg, obj)
{
	alert(msg);
	if (obj == undefined || obj == null)
		return false;

	obj.focus();
	return false;
}

function checkValidID(str)
{
	var re = /^[A-Za-z]+\d+[A-Za-z0-9]*$/;
	return re.test(str);
}

function checkEmail(str)
{
	var re = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
	return re.test(str);
}

function LogOut(){
    top.location.href = "/eng/global/GlbLgnOut.asp";
}

//New Popup open
function Popup(sURL,width,height){
    window.open(sURL,"","scroll=no,scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width="+ width +",height="+ height);
}
//Given name Popup open
function PopupName(url,name,width,height){
	window.open(url,name,"scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width="+ width +",height="+ height);
}
//Given name Popup open and return window reference
function PopupNameRef(url,name,width,height){
	return window.open(url,name,"scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width="+ width +",height="+ height);
}

function SearchZipcode( div ){
    PopupName("/eng/global/GlbZipCode.asp?of="+ div,"zipcode",421,350);
}

/* Confirm number */
function fnOnlyNumber()  //
{
	if ((event.keyCode>=48 && event.keyCode<=57)||(event.keyCode>=96 && event.keyCode<=105)||event.keyCode == 44 || event.keyCode==8 || event.keyCode==9 || event.keyCode==13 || event.keyCode==46 || event.keyCode==144) {
		event.returnValue = true;
	}
	else {event.returnValue=false;}
}

function resizeImage(imgObj, width, height)
{
	if (imgObj) {

		var h = imgObj.height / imgObj.width;
		var w = imgObj.width / imgObj.height;

		if (imgObj.width > width) {
			imgObj.width = width;
			imgObj.height = width * h;
		}

		if (imgObj.height > height) {
			imgObj.height = height;
			imgObj.width = height * w;
		}
	};
}

function AJAX(){
    var xmlHttp = null;
    var bReady = false;
    var is_ie5 = (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) && document.all;
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    } else {
        var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
        try {
            xmlHttp = new ActiveXObject(control);
        } catch (e) {
            xmlHttp = null;
        }
    }
    this.connect = function( sMethod, sUrl, sVars, FnName )
    {
        bReady = false;
        sMethod = sMethod.toUpperCase();
        try {
            if ( sMethod == "GET" )
            {
                if ( sVars.length > 0 )
                {
                    xmlHttp.open( sMethod, sUrl +"?"+ sVars, true );
                    sVars = "";
                } else {
                    xmlHttp.open( sMethod, sUrl, true );
                }
            } else {
                xmlHttp.open( sMethod, sUrl, true );
                xmlHttp.setRequestHeader("Method", "POST "+ sUrl +" HTTP/1.1");
                xmlHttp.setRequestHeader("Content-length", sVars.length);
            }
	        //xmlHttp.overrideMimeType(this.mimeType);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlHttp.setRequestHeader("Cookie",document.cookie);
            xmlHttp.onreadystatechange = function()
            {
                if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 && xmlHttp.statusText == 'OK' && !bReady ) {
                    bReady = true;
                    FnName( xmlHttp );
                }
            }
            xmlHttp.send( sVars );
        } catch(e) {
            //alert( "Error:"+ e +"\nName:"+ e.name +"\nNum:"+ e.number +"\nMachine:"+ (e.number>>16 & 0x1FFF) +"\nMessage:"+ e.message );
            return false;
        }
    }
}

function jsAjax(){
    var xmlHttp = null;
    var bReady = false;
    var is_ie5 = (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) && document.all;
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    } else {
        var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
        try {
            xmlHttp = new ActiveXObject(control);
        } catch (e) {
            xmlHttp = null;
        }
    }

    //this.connect = function( sMethod, sUrl, sVars, FnName )
	this.send = function(fnName, sUrl, sVars, sMethod)
    {

        bReady = false;
        sMethod = sMethod.toUpperCase();
        //try {
            if ( sMethod == "GET" )
            {
                if ( sVars && (sVars.length > 0) )
                {
                    xmlHttp.open( sMethod, sUrl +"?"+ sVars, true );
                    sVars = "";
                } else {
                    xmlHttp.open( sMethod, sUrl, true );
                }
            } else {
                xmlHttp.open( sMethod, sUrl, true );
                xmlHttp.setRequestHeader("Method", "POST "+ sUrl +" HTTP/1.1");
                xmlHttp.setRequestHeader("Content-length", sVars.length);
            }
	        //xmlHttp.overrideMimeType(this.mimeType);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlHttp.setRequestHeader("Cookie",document.cookie);
            xmlHttp.onreadystatechange = function()
            {
                if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 && xmlHttp.statusText == 'OK' && !bReady ) {
                    bReady = true;
                    fnName( xmlHttp );
                }
            }
            xmlHttp.send( sVars );
        //} catch(e) {
        //    alert( "Error:"+ e +"\nName:"+ e.name +"\nNum:"+ e.number +"\nMachine:"+ (e.number>>16 & 0x1FFF) +"\nMessage:"+ e.message );
        //    return false;
        //}
		return true;
    }
}
