/*This file deals with coookies management*/
//setCookie('username',username,365)
/* check whetehr cookie is enabled by client or not*/
function isCookiesEnabled()
{
    if( window.clientInformation.cookieEnabled ==false)
    {
        alert("Cookies not enabled on this system, You may feel inconveniency, surfing this site,\nplease enable cookies for better user experience.");
        return false;
    }
    else
        return true;
}

/*The parameters of the function above hold the name of the cookie, the value of the cookie, and the number of 
days until the cookie expires.*/
function setCookie(cookieName, cookieValue, expires, path, domain, secure){

    //var exdate=new Date();
    //exdate.setDate(exdate.getDate()+expiredays);
    
    document.cookie =
    escape(cookieName) + '=' + escape(cookieValue)
    + (expires ? '; expires=' + expires.toGMTString() : '')
    + (path ? '; path=' + path : '')
    + (domain ? '; domain=' + domain : '')
    + (secure ? '; secure' : '');
}
function CreateCookie(cookiename,id){
    setCookie(cookiename, id,"","/");
}

/*
The function above first checks if a cookie is stored at all in the document.cookie object. If the document.cookie 
object holds some cookies, then check to see if our specific cookie is stored. If our cookie is found, then return 
the value, if not - return an empty string.
*/
function getCookie(cookieName){
    var cookieValue = '';
    if (document.cookie.length>0){
        var posName = document.cookie.indexOf(escape(cookieName) + '=');
        if (posName != -1){
            var posValue = posName + (escape(cookieName) + '=').length;
            var endPos = document.cookie.indexOf(';', posValue);
            if (endPos != -1) 
                cookieValue = unescape(document.cookie.substring(posValue, endPos));
            else 
                cookieValue = unescape(document.cookie.substring(posValue));
        }
    }
    return (cookieValue);
}

if(typeof (Browser)==="undefined"){Browser={};}
Browser.Detector = {
    getAgent: function () {
        return navigator.userAgent.toLowerCase();
    },
    isMac: function (M) {
        var U = M || this.getAgent(); return !!U.match(/mac/i);
    },
    isWin: function (M) {
        var U = M || this.getAgent(); return !!U.match(/win/i);
    },
    isWin2k: function (M) {
        var U = M || this.getAgent(); return this.isWin(U) && (U.match(/nt\s*5/i));
    },
    isWinVista: function (M) {
        var U = M || this.getAgent(); return this.isWin(U) && (U.match(/nt\s*6/i));
    },
    isWebKit: function (M) {
        var U = M || this.getAgent(); return !!U.match(/AppleWebKit/i);
    },
    isChrom: function (M) {
        var U = M || this.getAgent(); return !!U.match(/chrom/i);
    },
    isSafari: function (M) {
        var U = M || this.getAgent(); return !!U.match(/safari/i);
    },
    isOpera: function (M) {
        var U = M || this.getAgent(); return !!U.match(/opera/i);
    },
    isIE: function (M) {
        var U = M || this.getAgent(); return !!U.match(/msie/i);
    },
    isIEStrict: function (M) {
        var U = M || this.getAgent(); return U.match(/msie/i) && !this.isOpera(U);
    },
    isFlock: function (M) {
        var U = M || this.getAgent(); return !!U.match(/flock/i);
    },
    isFirefox: function (M) {
        var U = M || this.getAgent(); return !!U.match(/firefox/i);
    },
    isiPhone: function (M) {
        var U = M || this.getAgent(); return this.isMobile(U);
    },
    isMobile: function (M) {
        var U = M || this.getAgent(); return this.isWebKit(U) && U.match(/Mobile/i);
    },
    isiTunesOK: function (M) {
        var U = M || this.getAgent(); return this.isMac(U) || this.isWin2k(U);
    },
    isQTInstalled: function () {
        var U = false;
        if (navigator.plugins && navigator.plugins.length) {
            for (var M = 0; M < navigator.plugins.length; M++) {
                var g = navigator.plugins[M];
                if (g.name.indexOf("QuickTime") > -1) U = true;
            }
        } else {
            qtObj = false;
            execScript("on error resume next: qtObj = IsObject(CreateObject(\"QuickTimeCheckObject.QuickTimeCheck.1\"))", "VBScript");
            U = qtObj;
        }
        return U;
    },
    getQTVersion: function () {
        var U = "0";
        if (navigator.plugins && navigator.plugins.length) {
            for (var g = 0; g < navigator.plugins.length; g++) {
                var S = navigator.plugins[g];
                var M = S.name.match(/quicktime\D*([\.\d]*)/i);
                if (M && M[1]) U = M[1];
            }
        } else {
            ieQTVersion = null;
            execScript("on error resume next: ieQTVersion = CreateObject(\"QuickTimeCheckObject.QuickTimeCheck.1\").QuickTimeVersion", "VBScript");
            if (ieQTVersion) U = (ieQTVersion >> 24).toString(16);
        }
        return U;
    },
    isQTCompatible: function (g, j) {
        function M(w, R) {
            var i = parseInt(w[0], 10);
            if (isNaN(i)) i = 0;
            var V = parseInt(R[0], 10);
            if (isNaN(V)) V = 0;
            if (i === V)
                return (w.length > 1) ? M(w.slice(1), R.slice(1)) : true;
            else
                return (i < V) ? true : false;
        }
        var S = g.split(/\./);
        var U = j ? j.split(/\./) : this.getQTVersion().split(/\./);
        return M(S, U);
    },
    isValidQTAvailable: function (U) {
        return this.isQTInstalled() && this.isQTCompatible(U);
    }
};

function trimAll(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}

function trim(strText)
{
	while (strText.substring(0,1) == ' ')
		strText = strText.substring(1, strText.length);
	while (strText.substring(strText.length-1,strText.length) == ' ' )
		strText = strText.substring(0, strText.length-1);
	return strText;
}


	// should enter only numeric values in the text field
	function enterNumeric(objControl)
	{
		//var RegExp = /'|"/i;
		//alert(objControl.value.match(RegExp))
		if(objControl == undefined)	// for decimal places
		{
			if((event.keyCode < 96 || event.keyCode > 105) && (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode!=46 && event.keyCode!=8 && event.keyCode!=37 && event.keyCode!=39 && event.keyCode !=9 && event.keyCode != 116 && event.keyCode!=35 && event.keyCode!=36))
			{
				event.keyCode = 0
				return false;
			}			
		}
		else	// no decimal places
		{
			if((event.keyCode < 96 || event.keyCode > 105) && (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode!=46 && event.keyCode!=8 && event.keyCode!=37 && event.keyCode!=39 && event.keyCode != 190 && event.keyCode != 110 && event.keyCode !=9 && event.keyCode != 116 && event.keyCode!=35 && event.keyCode!=36) || (event.keyCode == 190 && objControl.value.indexOf(".") != -1) || (event.keyCode == 110 && objControl.value.indexOf(".") != -1))
			{
				event.keyCode = 0
				return false;
			}
		}
		return true;
	}

function enterNonNumeric(objControl)
	{
		//var RegExp = /'|"/i;
		//alert(objControl.value.match(RegExp))
			if((event.keyCode > 64 && event.keyCode < 91) || (event.keyCode > 96 && event.keyCode < 123) || event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 35 || event.keyCode == 36)
			{
			}
			else
			{
				event.keyCode = 0
				return false;			
			}
		
		return true;
	}
	// the numeric filed should contain value > 0
	function IsValidNumeric(oSrc, args)
	{
		args.IsValid = (document.getElementById(oSrc.controltovalidate).value > 0)
	}

	function ConfirmDel() 
	{
		if (confirm("Are you confirm to delete selected records?")==0)
		{
			document.getElementById("ChkTmp").checked = false;
		}
		else
		{
			document.getElementById("ChkTmp").checked = true;
		}
		
	}
	
	
