/* ======================================================================
	Function	: openNewWindowNoScroll
	Input		: strPath   : String 				  
				  strWinName: String
				  iWidth    : int 				  
				  iHeight   : int
	Explanation : Opens a New window with specified name and specified path of file 
	========================================================================== */
function openNewWindowNoScroll(strPath,strWinName,iWidth,iHeight,iLeft,iTop)
{
	window.open(strPath,setWindowName(strWinName),"toolbar=no,location=no,status=no,width="+iWidth+",height="+iHeight+",left="+iLeft+",top="+iTop+",menubar=no,scrollbars=no,alwaysraised=no,resizable=no")
}


/* ======================================================================
	Function	: openNewWindowNoScrollCenter
	Input		: strPath   : String 				  
				  strWinName: String
				  iWidth    : int 				  
				  iHeight   : int
	Explanation : Opens a New window with specified name and specified path of file 
	========================================================================== */
function openNewWindowNoScrollCenter(strPath,strWinName,iWidth,iHeight)
{
	var iLeft = (screen.width - iWidth) / 2;
	var iTop = (screen.height - iHeight) / 2;
	window.open(strPath,setWindowName(strWinName),"toolbar=no,location=no,status=no,width="+iWidth+",height="+iHeight+",left="+iLeft+",top="+iTop+",menubar=no,scrollbars=no,alwaysraised=no,resizable=yes")
}

/* ======================================================================
	Function	: openNewWindow
	Input		: strPath   : String 				  
				  strWinName: String
				  iWidth    : int 				  
				  iHeight   : int
	Explanation : Opens a New window with specified name and specified path of file 
	========================================================================== */
function openNewWindow(strPath,strWinName,iWidth,iHeight)
{
	var iLeft = (screen.width - iWidth) / 2;
	var iTop = (screen.height - iHeight) / 2;
	window.open(strPath,setWindowName(strWinName),"toolbar=no,location=no,status=no,width="+iWidth+",height="+iHeight+",left="+iLeft+",top="+iTop+",menubar=no,scrollbars=yes,alwaysraised=no,resizable=yes")
}

/* ======================================================================
	Function	: openNewWindowLeftTop
	Input		: strPath   : String 				  
				  strWinName: String
				  iWidth    : int 				  
				  iHeight   : int
	Explanation : Opens a New window with specified name and specified path of file 
	========================================================================== */
function openNewWindowLeftTop(strPath,strWinName,iWidth,iHeight,iLeft,iTop)
{
	window.open(strPath,setWindowName(strWinName),"toolbar=no,location=no,status=no,width="+iWidth+",height="+iHeight+",left="+iLeft+",top="+iTop+",menubar=no,scrollbars=yes,alwaysraised=no,resizable=yes")
}

/* ======================================================================
	Function	: setWindowName
	Input		: strWinName: String
	Retrieval	: String
	Explanation : returns the name with valid characters if not found returns default name
	========================================================================== */
function setWindowName(strWinName)
{
	var strOutput = '';

	var iLen = strWinName.length;

	var strChar='';

	for(var iCnt=0;iCnt<iLen;iCnt++)
    {
		strChar = strWinName.charAt(iCnt);

		if(strChar	>=	"0" && strChar	<=	"9" || strChar	>=	"a" && strChar	<=	"z" || strChar	>=	"A" && strChar	<=	"Z")
		{
			strOutput += strChar;
		}
	}

	if(strOutput=='')
	{
		strOutput = 'ABCDE';
	}

	return strOutput;
}

/* ======================================================================
	Function	: setFieldsToUpperCase
	Input		: strData: String
	Retrieval	: String
	Explanation : returns the string by converting it to Upper Case
	========================================================================== */
function setToUpperCase(strData)
{
	var strReturn = "";

	if(strData != "") 
	{
		strReturn = strData.toUpperCase();
	}

	return strReturn;
}

/* ======================================================================
	Function	: sortArray
	Input		: obj : array object
	Retrieval	: obj : array object
	Explanation : To sort an String Array in an Alphabetical order
				  To sort an Integer Array in an numeric order
	========================================================================== */
function sortArray(obj)
{
	return obj.sort(); 
}

/* ======================================================================
	Function	: errorLogin
	Input		: 
	Retrieval	: 
	Explanation : 
	
	========================================================================== */
function errorLogin(strUrl)
{
	window.parent.topFrame.document.frmMain.exitFlag.value='2';		
	window.parent.location.href=strUrl;
}

/* ======================================================================
	Function	: returnBlank
	Input		: obj	     : Text box
	Retrieval	: String : if value of text box is null or 0 returns blank
	Explanation : Used To return blank value if 0
	========================================================================== */
function returnBlank(strValue)
{
	var strReturn = "";
	
	if(strValue!="" && strValue!="0")
	{	
		strReturn = strValue;
	}
	return strReturn;
}

/* ======================================================================
	Function	: confirmCancel
	Input		: 
	Retrieval	: boolean : 
	Explanation : 
	========================================================================== */
function confirmCancel()
{
	return window.confirm(CONFIRM_CANCEL);
}

/* ======================================================================
	Function	: confirmDelete
	Input		: 
	Retrieval	: boolean : 
	Explanation : 
	========================================================================== */
function confirmDelete()
{
	return window.confirm(CONFIRM_DELETE);
}

/* ======================================================================
	Function	: confirmReset
	Input		: 
	Retrieval	: boolean : 
	Explanation : 
	========================================================================== */
function confirmReset()
{
	return window.confirm(CONFIRM_RESET);
}


/* ======================================================================
	Function	: showAlert
	Input		: 
	Retrieval	: string : 
	Explanation : 
	========================================================================== */
function showAlert(msg,arg)  //  Set the customize error message in strErrorMessage.
{
	alert(getMessage(msg,arg));
}

function showConfirm(msg,arg)
{
	return confirm(getMessage(msg,arg));
}

function getMessage(msg,arg)
{
	if(arg)
	{
		if(typeof(arg)=='object')
		{
			var iArgLen = arg.length;
			for(var intI=0;intI<iArgLen;intI++)
			{
				if(arg[intI])
				{
					if(msg.indexOf("{"+intI+"}")>=0)
					{
						var objTemp = msg.split("{"+intI+"}");
						var iLen = objTemp.length-1;
						msg="";
						for(var iCount=0;iCount<iLen;iCount++)
						{
							msg += objTemp[iCount] + arg[intI];
						}
						msg +=objTemp[iLen];
					}
				}
			}
		}
		else
		{ 
			if(msg.indexOf("{0}")>=0)
			{
				var objTemp = msg.split("{0}");
				var iLen = objTemp.length-1;
				msg="";
				
				for(var iCount=0;iCount<iLen;iCount++)
				{
					msg += objTemp[iCount] + arg;
				}
				msg +=objTemp[iLen];
			}
		}
	}
	return msg;
}

/* ======================================================================
	Function	: checkBrowser 
	Retrieval	: Returns boolean if the browser is ie
	Explanation : This function is used to get the flag of browserif ie			  
	========================================================================== */
function isBrowserIE() 
{
	var blnFlag = false;

	var bName = navigator.appName;

	if(bName == "Microsoft Internet Explorer")
	{
		blnFlag = true;
	}

	return blnFlag;
}

/* ======================================================================
	Function	: checkBrowser 
	Retrieval	: Returns boolean if the browser is FF
	Explanation : This function is used to get the flag of browserif FF			  
	========================================================================== */
function isBrowserFireFox() 
{
	var blnFlag = false;

	if(navigator.userAgent.indexOf("Firefox")!= -1 )
	{
		blnFlag = true;
	}

	return blnFlag;
}

/* ======================================================================
	Function	: checkBrowser 
	Retrieval	: Returns boolean if the browser is Netscape
	Explanation : This function is used to get the flag of browserif Netscape			  
	========================================================================== */
function isBrowserNetscape() 
{
	var blnFlag = false;

	if(navigator.userAgent.indexOf("Netscape")!= -1 )
	{
		blnFlag = true;
	}

	return blnFlag;
}

/* ======================================================================
	Function	: Convert to UpperCase
	Retrieval	: Returns Upper Case Value
	Explanation : This function is used to convert object value into Upper Case			  
	========================================================================== */
function upperCase(obj)
{
    var val = obj.value
    obj.value = val.toUpperCase()
}

/* ======================================================================
	Function	: Convert to LowerCase
	Retrieval	: Returns Lower Case Value
	Explanation : This function is used to convert object value into Lower Case			  
	========================================================================== */
function lowerCase(obj)
{
    var val = obj.value
    obj.value = val.toLowerCase()
}

function alertFoc(msg,obj)
{
	alert(msg);
	obj.focus();
}
/* ======================================================================
	Function	: isExistsInArray
	Input		: Array & value
	Retrieval	: boolean Flag 
	Explanation : checks value exists in array or not.
	========================================================================== */
function isExistsInArray(array,val)  
{
	var blnFlag = false;
	if(array[0])
	{
		var iSize = array.length;
		for(var i=0;i<iSize;i++)
		{
			if(array[i] == val)
			{
				blnFlag = true;
				break;
			}
		}
	}
	else
	{
		if(array == val)
		{
			blnFlag = true;
		}
	}
	return blnFlag;
}

/* ======================================================================
	Function	: breakFormat
	Input		: value & replace value
	Retrieval	: String 
	Explanation : Inserts a break or empty in every new line in the string.
	========================================================================== */
   function breakFormat(strValue,strReplaceChar)
   {
      var sb = strValue;
      while (strValue.indexOf("\n") != -1)
      {
         strValue = strValue.replace(/\n/,strReplaceChar);
      }
      return strValue;
   }
   
/* ======================================================================
	Function	: validStr
	Input		: value
	Retrieval	: String 
	Explanation : validates the string data whether null and blank.
	========================================================================== */   	
	function validStr(strValue)
	{
		var strReturn = "";
		if(strValue != '' && strValue != null && strValue != 'null')
		{
			strReturn = strValue;
		}
		
		return strReturn;	
	}
	

/* ======================================================================
	Function	: checkChkBox
	Input		: arrChkLabels	: check box labels
				  arrChkStatus	: check box checked status
	Retrieval	: boolean : if any check box selected then true otherwise false
	Explanation : Used To validate the selected check boxes.
	========================================================================== */

function checkChkBox(arrChkLabels,arrChkStatus)
{
	var iLength = arrChkStatus.length;
	var blnFlag = false;
	var blnFlagValue = false;
	var strMessage = '';
	for(var iCnt=0;iCnt<iLength;iCnt++)
	{
		if(arrChkStatus[iCnt])
		{
			blnFlag = true;
			break;
		}
		else
		{
			if(blnFlagValue)
			{
				strMessage += ' or ';
			}
			strMessage += arrChkLabels[iCnt];
			blnFlagValue = true;
		}
	}
	
	if(!blnFlag)
	{
		showAlert(MSG_CHECK , new Array(strMessage) );
	}
	return blnFlag;
}	


function limitStr(strParam, iLen, blnFlag)
{
      var strReturn = "";

      if (strParam.length <= iLen)
      {
         strReturn = strParam;
      }
      else
      {
         if (!blnFlag)
         {
            strReturn = strParam.substring(0, iLen);
         }
         else
         {
            strReturn = strParam.substring(0, iLen) + "..";
         }
      }

      return strReturn;
}

function bookmarksite()
{
	var url = this.location;
	var who = document.title;
	var ver = navigator.appName
	var num = parseInt(navigator.appVersion)

   if (window.sidebar) // firefox
	window.sidebar.addPanel(who, url, "");
	else if(window.opera){ // opera
	var elem = document.createElement("A");
	  elem.rel="sidebar";
	  elem.title=who;
	  elem.href=url;
	  elem.click();
		} 
	  else if(document.all)// ie
				window.external.AddFavorite(url, who);
  }
