﻿
function $G(id)
{
    return document.getElementById(id);
}

function $F(id)
{
    return $G(id).value;
}

String.prototype.trim = function() 
{ 
    if (this == null) return "";
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
}
String.prototype.lTrim = function() 
{ 
    if (this == null) return "";
    return this.replace(/(^\s*)/g, ""); 
}
String.prototype.rTrim = function() 
{ 
    if (this == null) return "";
    return this.replace(/(\s*$)/g, "");
}
String.prototype.removeQuote = function() {
    if (this == null) return "";
    return this.replace(/(\")/g, "");
}

function checkEmail(email)
{
    var re = new RegExp("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$", "ig");
    return re.test(email)
}
function checkWebSiteUrl(url)
{
    var re = new RegExp("^http(s)?://([\w-]+\.)*", "ig");
    return re.test(url);
}

function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}




function getXmlHttp()
{
	var http_request;
	if(window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) { 
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) { 
		window.alert("can't create XMLHttpRequest object.");
		return null;
	}	
	return http_request;
}

function getElementPositionX(elemID)
{
   var offsetTrail = document.getElementById(elemID);
   var offsetLeft = 0;
   
   while(offsetTrail)
   {
      offsetLeft += offsetTrail.offsetLeft;
      offsetTrail = offsetTrail.offsetParent;
   }
   
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof(document.body.leftMargin) != "undefined") {
        offsetLeft += document.body.leftMargin;
    }
    
    return offsetLeft;
}
function getElementPositionY(elemID)
{
   var offsetTrail = document.getElementById(elemID);
   var offsetTop = 0;
   
   while(offsetTrail)
   {
      offsetTop += offsetTrail.offsetTop;
      offsetTrail = offsetTrail.offsetParent;
   }
   
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof(document.body.leftMargin) != "undefined") {
        offsetTop += document.body.topMargin;
    }
    return offsetTop;
}
function dataToUrlParam(datas)
{
    var tmpArray = [];
    var tmpName = "";
    var tmpValue = "";
    var returnStr = "";
    for ( var data in datas )
    {
        tmpName = data.trim();
        tmpValue = datas[data].trim();
        if (tmpValue != "")
        {
            tmpArray.push(encodeURIComponent(tmpName) + "=" + encodeURIComponent(tmpValue));
        }
    }
    returnStr = tmpArray.join("&");
    return returnStr;
}
function goPageWidthData(url, datas)
{
    var paramStr = dataToUrlParam(datas).trim();
    var joinSymbol = (url.indexOf("?") > -1) ? "&" : "?";
    if (paramStr == "") joinSymbol = "";
    window.location.href = url + joinSymbol + paramStr;
}
function controlImgSize(tartgetImgObj, width, height)
{
    if (width == 0) width = tartgetImgObj.style.width;
    if (height == 0) width = tartgetImgObj.style.height;
    var tmpImage = new Image();
    tmpImage.src = tartgetImgObj.src;
    var resultWidth;
    var resultHeight;
    if ((tmpImage.width/tmpImage.height) >= (width/height))
    {
        if (tmpImage.width > width)
        {
            resultWidth = width;
            resultHeight = width*(tmpImage.height/tmpImage.width);
        }
        else
        {
            resultWidth = tmpImage.width
            resultHeight = tmpImage.height
        }
    }
    else
    {
        if (tmpImage.height > height)
        {
            resultWidth = height*(tmpImage.width/tmpImage.height);
            resultHeight = height;
        }
        else
        {
            resultWidth = tmpImage.width
            resultHeight = tmpImage.height
        }
    }
    tartgetImgObj.style.width = resultWidth + "px";
    tartgetImgObj.style.height = resultHeight + "px";
}
function buildUrlWithData(url, datas)
{
    var paramStr = dataToUrlParam(datas).trim();
    var joinSymbol = (url.indexOf("?") > -1) ? "&" : "?";
    if (paramStr == "") joinSymbol = "";
    return url + joinSymbol + paramStr;
}
function buildNoCacheUrl(strUrl)
{
    var joinSymbol = (strUrl.indexOf("?") > -1) ? "&" : "?";
    var randomTimeTag = (new Date).getTime();
    return strUrl + joinSymbol + "randomTimeTag=" + randomTimeTag;
}
function isNumber(inputString, isHasPoint) {
    var re;
    if (isHasPoint) {
        re = new RegExp("^[\-\+]?\\d+(\\.\\d*)?$", "ig");
    }
    else {
        re = new RegExp("^\\d+$", "ig");
    }

    return re.test(inputString);
}

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
function setCookie(name, value) {
    var exp = new Date();
    var minutes = 10;
    var domain = "meetingselect.com";
    exp.setTime(exp.getTime() + minutes * 60 * 1000);
    // document.cookie = name + "=" + value + "; Path=/; expires=" + exp.toGMTString() + "; domain=" + domain;
    document.cookie = name + "=" + value + "; Path=/; domain=" + domain;
}

function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    document.cookie = name + "=" + value + "; Path=/; expires=" + exp.toGMTString() + ";";
}


function getPositionTemp(Obj) {
    var e = Obj;
    var t = e.offsetTop;
    var l = e.offsetLeft;
    var height = e.offsetHeight;
    while (e = e.offsetParent) {
        t += e.offsetTop;
        l += e.offsetLeft;
    }
    return { left: l, top: t }
}
