﻿// JScript File for Common Functions
function isIEObject(a) 
{
 return isObject(a) && typeof a.constructor != 'function';
}

function isArray(a) 
{
return isObject(a) && a.constructor == Array;
}

function isBoolean(a) 
{
  return typeof a == 'boolean';
}

function isEmpty(o) 
{
  if (isObject(o)) 
       for (var i in o) 
            return false;
  return true;
}

function isFunction(a) 
{
  return typeof a == 'function';
}

function isNull(a) 
{
  return typeof a == 'object' && !a;
}

function isNumber(a) 
{
   //return typeof a == 'number' && isFinite(a); //comment by san
   var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452. 
   var result = a.match(RegExp);
   return result;
}

function isObject(a) 
{
 return (typeof a == 'object' && !!a) || isFunction(a);
}

function isString(a) 
{
 return typeof a == 'string';
}

function isUndefined(a) 
{
 return typeof a == 'undefined';
} 

//===================Cookies Common Function Start===================>

//function to add or revise cookie 
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+"="+escape(value)+expires+"; path=/";
}


//function To read cookie
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);
		//use unescape can prevent the unreadable code "Chinese-big5" mistake
		if (c.indexOf(nameEQ) == 0) { return unescape(c.substring(nameEQ.length,c.length));}
	} //alert(unescape(c.substring(nameEQ.length,c.length))) ;
	return null; 
}

//function To erasecookie
function eraseCookie(name) 
{
	createCookie(name,"",-1);
}

//function to check whether cookies is exist
function checkCookieExist(name)
{
    var CookiesName = readCookie(name);
    if (CookiesName)
    {
        return true; 
    }
    else
    {
        return false;
    }
}
//===================Cookies Common Function End===================>