/********************************************************************************************
'Application name	  : BDI
'Purpose		  : Javascript Common Functions
'Created on		  : 031111
'Programmer		  : Yogesh
'Modified On		  :
'Modified By		  :
'Modification		  :
********************************************************************************************/
/**********************************************************************************************
'Function		: MakeSubmit
'Input			: sAction
'Output			: none
'Explanation		: Used for Redirection : sAction is path of the file 
**********************************************************************************************/

function MakeSubmit(sAction)
{
	document.forms[0].action=sAction;
	document.forms[0].submit();
}	

/**********************************************************************************************
'Function		: AllTrim
'Input			: String
'Output			: Trimmed String 
'Explanation		: Used  to Trim string 
**********************************************************************************************/
function AllTrim(msStr)
{
 mnCnt=0;
 mnI=0;
 msStr1="";

 for (mnI=0;mnI<msStr.length;mnI++)
 {
 if (msStr.charAt(mnI) == " ")
 {
 mnCnt++;
 }
 else
 {
 mnCnt = 0;
 }
 if (mnCnt <= 1)
 msStr1 += msStr.charAt(mnI);
 }

 if (msStr1.charAt(0) == " ")
 msStr1 = msStr1.substring(1,msStr1.length);

 if (msStr1.charAt(msStr1.length-1) == " ")
 msStr1 = msStr1.substring(0,msStr1.length-1);

 return msStr1;
}

/**********************************************************************************************
'Function		: Maxlen
'Input			: Obj
'Output			: 
'Explanation		: Used to Get Length of  string in given object 
**********************************************************************************************/
function Maxlen(obj)
{
	var LEN = 0;
	for (var i=0;i<obj.value.length;i++)
	 	{
			if ( obj.value.charCodeAt(i) <= 255 )
				LEN += 1;
			else
			{
				LEN += 2;
			}
		}
	return LEN;
}

/**********************************************************************************************
'Function		: f_ReadCookie
'Input			: CookieName
'Output			: 
'Explanation		: Used to read Cookie 
**********************************************************************************************/
function f_ReadCookie(cookieName) 
{
    if (cookieName == "" )
        {
            return;
        } 
    var theCookie=""+document.cookie+(("/") ? "; path=" + "/" : "") ;
    var ind=theCookie.indexOf(cookieName);
    if (ind==-1 || cookieName=="") return ""; 
    var ind1=theCookie.indexOf(';',ind);
    if (ind1==-1) ind1=theCookie.length; 
    return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
// read cookie

// Cookie Check function call 
	f_WriteCookie("ckTmp","Y"); // write temp. cookie
	sVal = f_ReadCookie("ckTmp"); // read this value again
	if (sVal != "Y")
	{
		return false;
		//alert('<?echo $arrErrMessage[4]?>');
	}
	return true;
}

/**********************************************************************************************
'Function		: f_WriteCookie
'Input			: CookieName,value
'Output			: 
'Explanation		: Used to write Cookie 
**********************************************************************************************/
function f_WriteCookie(name, value) 
{
    //if (name == "" || value == "" )
	if (name == "")
        {
           return false;
           //alert('<?echo $arrErrMessage[1]?>');
        }
    //if (value != null && value != "")
	if (value != null)
        {
            // put this line if you want to give expiry of cookie.
            //document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
            //YL document.cookie=name + "=" + escape(value);
			var curCookie = name + "=" + escape(value) +
		    //((expires) ? "; expires=" + expires.toGMTString() : "") +
      		(("/") ? "; path=" + "/" : "") //+
      		//((domain) ? "; domain=" + domain : "") +
      		//((secure) ? "; secure" : "");
  document.cookie = curCookie;

			
        }
}// write cookie

/**********************************************************************************************
'Function		: f_CheckBrowserCookie
'Input			: 
'Output			: 
'Explanation		: 
**********************************************************************************************/
function f_CheckBrowserCookie()
{ 
// Cookie Check function call 
	f_WriteCookie("ckTmp","Y"); // write temp. cookie
	sVal = f_ReadCookie("ckTmp"); // read this value again<br>
	if (sVal != "Y")
	{
		return false;
		//alert('<?echo $arrErrMessage[4]?>');
	}
	return true;
}

/**********************************************************************************************
'Function		: IsNumeric
'Input			: Value
'Output			: True/False depending upon value passed
'Explanation		: Check is value passed is numeric or not
**********************************************************************************************/
function IsNumeric(sStr)
{
 	var msStr = "-0123456789";
	 for (i=0;i<sStr.length;i++)
		 {
			 if ( msStr.indexOf(sStr.charAt(i)) == -1 )
				 {
						 return false; // Not Numeric....
				 }
		 }
			 return true; // string is Numeric....
}

/**********************************************************************************************
'Function		: isArray
'Input			: Object
'Output			: True/False depending upon object passed
'Explanation		: Used to check if the object is array or not
**********************************************************************************************/
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

/**********************************************************************************************
'Function		: openWindow
'Input			: FileName,Target and Parameters
'Output			: 
'Explanation		: Opens New browser Window
**********************************************************************************************/
function openWindow(file,target,params) 
{
	var winobj;
    winobj=window.open(file,target,params);
    if (winobj !=null)
    {
		winobj.focus();
    }
}