document.oncontextmenu = DRC;
var tooltipObj = null;
function CallHandleKeyPress(e,objOE,objMW)
{
	try
	{
		var iRet = 1;
		if (objOE.document.getElementById("rdoBS1").disabled == false)
		{
			if (GetKeyCode(e) == 43 || GetKeyCode(e) == 112)
			{
				objOE.document.getElementById("rdoBS1").checked=true;
				objOE.document.getElementById("OrdBody").style.backgroundColor = "#a9d5ff";
				iRet = 0;
			}
			else if(GetKeyCode(e) == 45 || GetKeyCode(e) == 113)
			{
				objOE.document.getElementById("rdoBS2").checked=true;
				objOE.document.getElementById("OrdBody").style.backgroundColor = "#ffcccc";
				iRet = 0;
			}
		}
		if (GetKeyCode(e) == 119 && e.type == "keydown")
		{
			iRet = 0;
			objMW.OWTB();
		}
		if (GetKeyCode(e) == 114 && e.type == "keydown")
		{
			iRet = 0;
			objMW.OWOB();
		}
		if (GetKeyCode(e) == 120 && e.type == "keydown")
		{
			objMW.OWHoldings();
			iRet = 0;
		}
		if (GetKeyCode(e) == 121 && e.type == "keydown")
		{
			objMW.OWActivityLog();
			iRet = 0;
		}
		if(GetKeyCode(e) == 117 && e.altKey == true && e.type == "keydown")
		{
			objMW.OWNetPosition();
		}
		else if(GetKeyCode(e) == 117 && e.altKey == false && e.type == "keydown")
		{
		    iRet = 0;
		}
		if (GetKeyCode(e) == 116)
		{
			iRet = 0;
		}
		if(GetKeyCode(e) == 67 && e.ctrlKey == true)
		{
		    iRet = 0;
		}
		if (GetKeyCode(e) == 123)
		{
			iRet = 0;
		}
		if (GetKeyCode(e) == 122 && e.type == "keydown")
		{
		    objMW.OWPurchasePower();
			iRet = 0;
		}
        if(GetKeyCode(e) == 8 && GetSource(e) !="textfield")
		{
			    iRet = 0;
		}
		if(GetKeyCode(e) == 86 && e.ctrlKey == true)
		{
                    iRet = 0;
		}
		if(iRet == 0)
		{
		    SetKeyCode(e, 0);
			return false;
		}
		else
		{
		    return true;
		}		
	}
	catch(e)
	{	
		LMsg('HandleKeyPress : ' + e.message);
	}
}
function StopEventPropagation(e)
{
	e.cancelBubble=true;
	if(e.stopPropagation)
	{
		e.stopPropagation();
	}
}
function HandleKeyPress(e)
{
	try
	{
		return window.parent.frames.frTop.CallHKP(e);
	}
	catch(e)
	{
		LMsg("HandleKeyPress() " + e.message);
	}
}

function ConvertCase(e)
{
	try
	{
		if (GetKeyCode(e) >= 97 && GetKeyCode(e) <= 122)
			SetKeyCode(e, GetKeyCode(e) - 32);
} 
	catch(e)
{
		LMsg('LoginPage ConvertCase : '+ e.message);
	}
} 
function NumericOnlyForPrice(e)
{
	try
	{
		var add_Char;
		add_Char= GetKeyCode(e);
		if (GetKeyCode(e) == 13 || GetKeyCode(e) == 8 || GetKeyCode(e) == 0)
		{
			return true;
		}
		if (add_Char > 57  || add_Char < 48 )
		{
			if ( add_Char != 46 && add_Char != 13 && add_Char != 45)
			{
				SetKeyCode(e,0);
				return false;
		}
	}
	}
	catch(Exception)
	{
		LMsg("NumericOnlyForPrice() " + e.message);	
	}
} 
function OnSplKeys(e)
{
	try
	{
	    if ((GetKeyCode(e) == 13)||(GetKeyCode(e) == 8)||(GetKeyCode(e) == 0))
		{return true}
		else if (GetKeyCode(e) >= 48 && GetKeyCode(e) <= 57)
		{return true}
		else if (GetKeyCode(e) >= 97 && GetKeyCode(e) <= 122)
		{return true}
		else if (GetKeyCode(e) >= 65 && GetKeyCode(e) <= 90)
		{return true}
		else
		{
			return SetKeyCode(e, 0);
			return false;
		}
	}
	catch (e)
	{
		LMsg("OnSplKeys : " + e.message);
	}
}
function DateValidate(txtExpiryDate)
{
  try
  {
	var dtval,day,month,year;
	dtval = Trim(txtExpiryDate);
	day = parseInt(txtExpiryDate,10);
	
	if(isNaN(day)) 
	{
		alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
		return false;
	}
	else
	{
		if (day <= 0)
		{
			alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
			
			return false;
		}			
		if ( dtval.substr(day.toString().length).length < 7) // 7 including month and year like Jan2004
		{
			alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
		
			return false;
		} 
		else
		{
			
			if (day.toString().length == 1)
			{
				if(txtExpiryDate.substr(0, 1) == "0")
			{
							month = dtval.substr(day.toString().length+1,3);
				year = dtval.substr(day.toString().length+4,4);
				}
				else
				{
					month = dtval.substr(day.toString().length,3);
					year = dtval.substr(day.toString().length+3,4);
				}
			}
			else
			{
				month = dtval.substr(day.toString().length,3);
				year = dtval.substr(day.toString().length+3,4);
			}
				
			month = month.toUpperCase();
			year = parseInt(year);
			
			if (isNaN(year))
			{
				alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
				
				return false;
			}	
			
			if(Trim(year.toString()).length != 4)
			{
				alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
				
				return false;					
			}											
			if ( parseInt(year) == parseInt(0))
			{
				alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
				
				return false;
			}
			else
			{
				if (month == "JAN" || month == "MAR" || month == "MAY" || month == "JUL" || month == "AUG" || month == "OCT" || month == "DEC" )
				{
					if (day > 31)
					{
						alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
					
						return false;
					}					
				}
				else if(month == "APR" || month == "JUN" || month == "SEP" || month == "NOV")
				{
					if (day > 30)
					{
						alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
						
						return false;
					}
				}
				else if (month == "FEB")
				{
					if (year % 4 == 0 && day > 29)
					{
						alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
						
						return false;
					}
					else if (year % 4 != 0 && day > 28)
					{
						alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
						
						return false;
					}
				}
				else
				{
					alert('Please enter Expiry Date in valid format i.e. DDMMMYYYY');
					
					return false;
				}
			} 				
		}
	}		
	
  }
	catch(e)
	{  }
}

function Trim(objTxtValue)
{
	try
	{
         return objTxtValue.split(" ").join("");
	}
	catch(Exception)
	{
               return "";
	}	
}
function DigAfterDec(dblValueToCheck, intNoOfDecimals)
{
	try
	{
		var strValue=dblValueToCheck.toString();
		intCount=strValue.indexOf(".");
		if(intCount != -1)
		{
			intCount=strValue.length-intCount-1;
			if(intCount > parseInt(intNoOfDecimals))
				return false;
		}
		return true;
	}
	catch(Exception)
	{
	}
}
function CheckIfNumeric(strValue)
{
	try
	{
		blnFlag = true;
		if(isNaN(strValue))
			return false;
		else
			return true;
	}
	catch(Exception)
	{
	}
}
function DecEnt(strValue)
{	
	 try
	{
		blnFlag = false;
		for(var j=0; j < strValue.length; j++)
		{
			var ch = strValue.substring(j,j+1);
			if (ch == ".")
			{
				blnFlag = true;
			}
		}
		return blnFlag;
	}
	catch(Exception)
	{
	}
}		
function NumZero(strValue)
{
  try
  {	
	  blnFlag = false;
	  if(parseFloat(strValue) == 0)
	  {
		  blnFlag = true;
	  }
	  return blnFlag;
  }
  catch(Exception)
  {
  }
}		
function PlusMinus(strValue)
{	
	try
	{
		if((strValue.indexOf("+")+1) || (strValue.indexOf("-")+1))
			return true;
		else
			return false;
	}
	catch(Exception)
	{
	}
}
function NumericOnly(e)
{
	try
	{
		var add_Char;
		add_Char= GetKeyCode(e);
		if (add_Char == 8 || add_Char == 0)
		return true;
		if (add_Char == 13)
		{
			EnterKey(e);
			return true;
		}
		if(add_Char <= 57 && add_Char >= 48)
		{return true}
		else if( add_Char == 46)
		{return true;}
		else if(add_Char == 45 || add_Char == 43 || add_Char == 189)
		{
		    return HandleKeyPress(e);
		}
		else
		{
		    return SetKeyCode(e,0);
		    return false;
	        }
	}
	catch(Exception)
	{
	}
}
function IntegerOnly(e)
{
	try
	{
		//Alive();
		var add_Char;
		add_Char= GetKeyCode(e);  
		if (add_Char == 8 || add_Char == 0)
		return true;
		if (add_Char == 13)
		{
			EnterKey(e);
			return true;
		}
		if (add_Char <= 57 && add_Char >= 48)
		return true;
		else
		{
			return SetKeyCode(e,0);
		    return false;
		}
	}//try end
	catch(Exception)
	{
	}
}

function IsSplChar(strFieldVal)
{
	try
	{
		myRegExp = new RegExp("[A-Z0-9]{1,10}", "gi");
		var arr = myRegExp.exec(strFieldVal);
		if(arr == strFieldVal)
			return true;
		else
			return false;
	}
	catch(e)
	{
		LMsg('IsSplChar ' +  e.message);
		return false;
	}
}   

function IsAlphaNum(strInput)
{
	try
	{
		Reg2 = new RegExp("^([A-Z0-9]*[A-Z][0-9][A-Z0-9]*)|([A-Z0-9]*[0-9][A-Z][A-Z0-9]*)", "gi");
		if(Reg2.test(strInput))
			return true;
		else
			return false;
	}
	catch(e)
	{
		LMsg('LoginPage IsAlphaNum'+ e.message);
	}
} 

function parseMsg(strKey,strSrc)
{
	try
	{
		var strVal="";
		var myRegExp = new RegExp("[^0-9]"+Trim(strKey)+"[ ]*=[ ]*([^|]*)","g");
		var arrRegResult = myRegExp.exec(strSrc);
		if(arrRegResult[1] != "undefined" && arrRegResult[1] != "")
		{
			strVal=arrRegResult[1];
		}
		return strVal;	
	}
	catch(e)
	{
		return "";
	}
}

function GetMktSegId(strExchName, strInstName)
	{ 
		try
		{	 
			var strMktSegId = "-1";
			strExchName  = Trim(strExchName);
			strInstName  = Trim(strInstName);
			switch(strExchName)
			{  
				case C_S_DFM_EXCH:
					if(strInstName == "")
						strMktSegId = C_V_DFM_CASH ;
				break; 
				case C_S_ADSM_EXCH:
					if(strInstName == "")
						strMktSegId = C_V_ADSM_CASH ;
				break; 
				case C_S_SSE_EXCHANGE:
					if(strInstName == "")
						strMktSegId = C_V_SSE_CASH ;
				break; 
				case C_S_DGCX_EXCH:
					switch(strInstName)
					{
						case C_S_INST_FUTCOM:
						case C_S_INST_OPTCOM:
							strMktSegId = C_V_DGCX_DERIVATIVES ;
						break;
						case C_S_INST_FUTSPT:
							strMktSegId = C_V_DGCX_SPOT ;
						break;
						
					}
					break; 
			}
			return strMktSegId;
		}
		catch (e)
		{
			LMsg('GetMktSegId '  + e.message); 
		}
	}
	
function GetMapMktSegId(strExchName,strInstName)
{
	try
	{ 
		var strMapMktSegId = "-1";
		strExchName  = Trim(strExchName);
		strInstName  = Trim(strInstName);
		switch(strExchName)
		{ 
			case C_S_DGCX_EXCH:
				switch(strInstName)
				{
					case C_S_INST_FUTCOM:
						strMapMktSegId = C_V_MAPPED_DGCX_DERIVATIVES ;
						break;
					case C_S_INST_FUTSPT:
						strMapMktSegId = C_V_MAPPED_DGCX_SPOT ;
						break;
				}
				break;
			case C_S_ADSM_EXCH:
				strMapMktSegId = C_V_MAPPED_ADSM ;
				break;
			case C_S_DFM_EXCH:
				strMapMktSegId = C_V_MAPPED_DFM ;
				break; 
		}
		return strMapMktSegId;
	}
	catch (e)
	{
		LMsg('MarketWatch GetMapMktSegId '  + e.message);
	}
}

function GetMktSegShortDesc(intMktSegId)
{
	try
	{
		var strMktSegShortDesc="";
		switch(intMktSegId)
		{ 
			case C_V_DGCX_DERIVATIVES:
				strMktSegShortDesc = C_S_DGCX_FUTURES_SHORT_DESC;
				break; 
		}
		return strMktSegShortDesc;
	}
	catch(e)
	{
		LMsg('MarketWatch GetMktSegShortDesc ' + e.message);
	}
}

function GetMktStatDesc(intMarketStatus)
{
	try
	{
		var strMkTStatDesc="";
		switch(intMarketStatus)
		{
			case "1":
				strMkTStatDesc = "Open";
				break;
			case "2":
				strMkTStatDesc = "Close";
				break;
			case "-1":
				strMkTStatDesc = "Unavailable";
				break;
		}		
		return strMkTStatDesc;
	}
	catch(e)
	{
		LMsg('MarketWatch GetMktStatDesc' + e.message);
	}
}
function GetAMOStatDesc(intAMOStatus)
{
	try
	{
		var strAMOStatDesc="";
		switch(intAMOStatus)
		{
			case "1":
				strAMOStatDesc = "Open";
				break;
			case "2":
				strAMOStatDesc = "Close";
				break;
			case "-1":
				strAMOStatDesc = "Unavailable";
				break;
		}		
		return strAMOStatDesc;
	}
	catch(e)
	{
		LMsg('MarketWatch GetMktStatDesc' + e.message);
	}
}
function GetInstName(strInstId)
{
	try
	{
		strInstId = Trim(strInstId);
		var strInstName = "";
		switch(strInstId)
		{ 
			case C_V_INST_FUTCOM:
				strInstName = C_S_INST_FUTCOM;
				break;
			case C_V_INST_FUTSPT:
				strInstName = C_S_INST_FUTSPT;
				break;
		}
		return strInstName;
	}
	catch(e)
	{
		LMsg('MarketWatch GetInstName '  + e.message);
	}
}

function GetInstId(strInstName)
{
	try
	{
		strInstName = Trim(strInstName);
		var strInstId = "-1";
		switch(strInstName)
		{ 
			case C_S_INST_FUTCOM:
				strInstId = C_V_INST_FUTCOM ;
				break;
			case C_S_INST_FUTSPT:
				strInstId = C_V_INST_FUTSPT ;
				break;
		}
		return strInstId;
	}
	catch(e)
	{
		LMsg('MarketWatch GetInstId '  + e.message);
	}
}

function GetDispInstName(strInstName)
{
	try
	{ 
		if (strInstName == C_S_INST_FUTCOM)
			strInstName = C_S_INST_FUTCOM;
		else if (strInstName == C_S_INST_FUTSPT)
			strInstName = C_S_INST_FUTSPT;
		return strInstName;
	}
	catch(e)
	{
		LMsg('MarketWatch GetDispInstName ' + e.message);
	}
}

function GetMapInstName(strInstName)
{
	try
	{ 
		var strMapInstName;
		strMapInstName = strInstName;
		return strMapInstName;
	}
	catch(e)
	{
		LMsg('MarketWatch GetMapInstName ' + e.message);
	}
}

function GetExchName(intMktSegId)
{
	try
	{
		var strExch; 
		if (intMktSegId == C_V_DGCX_DERIVATIVES)
			strExch = C_S_DGCX_EXCH;
		else if (intMktSegId == C_V_DGCX_SPOT)
			strExch = C_S_DGCX_EXCH; 
		else if (intMktSegId == C_V_ADSM_CASH)
			strExch = C_S_ADSM_EXCH; 
		else if (intMktSegId == C_V_DFM_CASH)
			strExch = C_S_DFM_EXCH; 		
		else if (intMktSegId == C_V_SSE_CASH)
			strExch = C_S_SSE_EXCHANGE; 	
		return strExch;
	}
	catch(e)
	{
		LMsg('MarketWatch  GetExchName ' + e.message);
	}
}

function AddDecimals(strPara,IntNoOfDeci)
{
	StrDecimals = Left("0000000000",IntNoOfDeci)
	StrPriDeciArr = strPara.split(".")
	if(typeof(StrPriDeciArr[1]) == "undefined")
		StrPriDeciArr[1] = StrDecimals
	else 
		StrPriDeciArr[1] = Left(StrPriDeciArr[1] + StrDecimals,IntNoOfDeci)
	return StrPriDeciArr[0] + "." + StrPriDeciArr[1]

}
function Left(cStr,nChar)
{
	return cStr.substring(0,nChar)
}

function FormatB5Pr(PriceVal)
{
	try
	{
		var intNewPriceVal;
		if (parseInt(Trim(PriceVal)) >= parseInt("0"))
		{
			if (Trim((PriceVal.slice(0,-2))).length == 0)
			{
				intNewPriceVal = "0" + '.' + PriceVal.substr(PriceVal.length-2,2);
			}
			else
			{
				intNewPriceVal = (PriceVal.slice(0,-2)) + '.' + PriceVal.substr(PriceVal.length-2,2);
			}		
		}
		else
		{ 
			intNewPriceVal = "";
		}
		return intNewPriceVal;		
	}
	catch(e)
	{
		LMsg('F FormatB5Price ' + e.message);
	}
}  

function FormatB5PrSpd(PriceVal)
{
	try
	{
		var intNewPriceValSpd;
		if (parseInt(Trim(PriceVal)) == "")
		{
			intNewPriceValSpd = '&nbsp;';
		}
		if (parseInt(Trim(PriceVal)) >= parseInt(0))
		{   
			
			if (Trim((PriceVal.slice(0,-1))).length == 0)
			{
				intNewPriceValSpd = "0" + '.' + "0" + PriceVal.substr(PriceVal.length-2,2) ;
			}
			else if(Trim((PriceVal.slice(0,-1))).length == 1)
			{
				intNewPriceValSpd = "0" + '.' + PriceVal.substr(PriceVal.length-2,2);
			} 
			else
			{
				intNewPriceValSpd = (PriceVal.slice(0,-2)) + '.' + PriceVal.substr(PriceVal.length-2,2);
			}  
		}
		else if (parseInt(Trim(PriceVal)) < parseInt(0))
		{   
			if (Trim((PriceVal.slice(1,-1))).length == 0)
			{
				intNewPriceValSpd = (PriceVal.slice(0,-1)) + "0" + '.' + "0"+ PriceVal.substr(PriceVal.length-1,1);
			}
			else if(Trim((PriceVal.slice(1,-1))).length == 1)
			{
				intNewPriceValSpd  = (PriceVal.slice(0,-2)) + "0" + '.' + PriceVal.substr(PriceVal.length-2,2);
			} 
			else 
			{
				intNewPriceValSpd  = (PriceVal.slice(0,-2)) + '.' + PriceVal.substr(PriceVal.length-2,2);
			} 
		} 
		return intNewPriceValSpd;	
	}
	catch(e)
	{
		LMsg('F FormatB5PrSpd' + e.message);
	}
}
function FillCombo(strArrText,strArrVal,strCltr)
{
	try
	{	
	    strCltr.innerHTML = "";
		for(i=0;i < strArrText.length;i++)
		{
			var oOpt;
	        oOpt = document.createElement("OPTION");
			oOpt.innerHTML = strArrText[i];
			oOpt.value = strArrVal[i];
			strCltr.appendChild(oOpt);
	      
		}
	}
	catch(e) 
	{ 
		LMsg("FillCombo"+e.message); 
	}	
}
function FillAlertDate(strCltr)
{
	try
	{	
	    strCltr.innerHTML = "";
		for(i=1;i <=60 ;i++)
		{
			var oOpt;
	        oOpt = document.createElement("OPTION");
			oOpt.innerHTML = i;
			oOpt.value = i;
			strCltr.appendChild(oOpt);
	      
		}
	}
	catch(e) 
	{ 
		LMsg("FillCombo"+e.message); 
	}	
}
function LMsg(strMessage)
{
//	alert(strMessage);
}
function DRC()
{
	return false;
}
function ToPaise(strPrice, ExchId)
{
	try
	{
		if (strPrice == "") return "0";
			var strOutput = 0;
		if(C_V_DFM_CASH == ExchId)
		{
		      strOutput = Math.round(parseFloat(strPrice) * 1000); 
		}
		else
		{	
		    strOutput = Math.round(parseFloat(strPrice) * 100); 
		}
		var strOpt = strOutput.toString();
		var arrOpt = strOpt.split(".");
		strOutput = parseInt(arrOpt);
		
		return strOutput;
	}
	catch(e)
	{
		return 0;
	}
}

function ToRupees(strPrice, ExchId)
{
	try
	{
		var strOutput = 0;
		if(C_V_DFM_CASH == ExchId)
		{
		    if (strPrice == "") return "0.000";
		    strOutput = (parseFloat(strPrice) / 1000);
		    if(strPrice < parseInt(1000))
		    {
		        strOutput = strOutput.toFixed(3);
		    }
		    else
		    {
		        strOutput = strOutput.toFixed(2);
		    }
		}
		else
		{
		    if (strPrice == "") return "0.00";
		    strOutput = (parseFloat(strPrice) / 100).toFixed(2);
		}
		return strOutput;
	}
	catch(e)
	{
		return 0;
	}
}	

function trapbackspace()
{
	if (event.keyCode == 8)
	{
		event.keyCode = 0;
	}
}

function AlphaNumeric()
{
	try
	{
		if (event.keyCode >= 97 && event.keyCode <= 122)
		{
			event.keyCode = event.keyCode - 32;
		}
	
		else if (event.keyCode >= 65 && event.keyCode <=90)
		{
			return;
		}
	
		else if (event.keyCode >=48 && event.keyCode <=57)
		{	
			return;
		}
	
		else if (event.keyCode == 32)
		{
			event.keyCode = 0;
		}
		
		else 
		{
			event.keyCode = 0;
		}
	}
	catch(Exception)
	{}
}

function AlphabeticOnly()
{
	try
	{
		
		if (event.keyCode >= 97 && event.keyCode <= 122 )
		{
			event.keyCode = event.keyCode - 32;
		}
		
		else if (event.keyCode >=65 && event.keyCode<=90)
		{
			return;
		}
		
		else 
		{
			event.keyCode = 0;
		}
				
	}
	catch(Exception)
	{}
}
//added by yogesh p allow only alphanumeric and space
function AlphabeticAndSpaceOnly()
{
	try
	{
		if (event.keyCode >= 97 && event.keyCode <= 122 )
		{
			event.keyCode = event.keyCode - 32;
		}
		
		else if (event.keyCode >=65 && event.keyCode<=90)
		{
			return;
		}
		
		else 
		{
			if (event.keyCode == 32)
			{
				return;
			}
			else
			{
				event.keyCode = 0;
			}
		}
				
	}
	catch(Exception)
	{}
}
//end yogesh p


function validatePrice(sender)
{
	try
	{
		var strValue;
		strValue = sender.value;
		if (strValue.indexOf('.') != -1 && event.keyCode == 46)
		{
			event.keyCode=0;
			return;
		}
		
		else if (event.keyCode >= 48 && event.keyCode <= 57)
		{
			return;
		}	
		
		else if (event.keyCode == 46)
		{
			return;
		}
		
		else if (event.keyCode < 48 || event.keyCode > 57)
		{
			event.keyCode = 0;
		}	
	
		if (strValue.length == 5 && strValue.indexOf('.') != -1)
			return;
	
		if (strValue.length == 5 && event.keyCode == 13)
			return;
	
		if (strValue.length == 5 && event.keyCode != 46)
			event.keyCode=0;
	}
	catch(Exception)
	{
		//alert(Exception.message);
	}
}

function isValidFormat(sDateValue) {
	
	var dateStrArr;
	dateStrArr = sDateValue.split('/');
	
	if (dateStrArr.length < 3) 
	{
	  return false;
	}
	

	for (i = 0; i < dateStrArr.length; i++) 
	{
		if (isNaN(dateStrArr[i]) || (dateStrArr[i]) == "" ) 
		{
			return false;
		}
	
		else if (((parseInt(dateStrArr[i], 10) < 1) || (parseInt(dateStrArr[i], 10) > 31)) && (i == 1)) 
		{
			return false;
		} 
	
		else if (((parseInt(dateStrArr[i], 10) < 1) || (parseInt(dateStrArr[i], 10) > 12)) && (i == 0))
		{
			return false;
		} 
	
		else if (((dateStrArr[i].length != 4) || (parseInt(dateStrArr[i], 10) < 1900) || (parseInt(dateStrArr[i], 10) > 2050)) && (i == 2) )
		{
		  return false;
		}
	}
	
}

var forbiddenElements	=	new Array("INPUT", "TEXTAREA");

function trapContentPasteKey() 
{
	var kc = window.event.keyCode;
	//alert(event.keyCode);
	if ((window.event.ctrlKey  && (kc == 86  || kc == 118)) ||	/*	Ctrl - V					*/
		(window.event.shiftKey &&  kc == 45               ) ||	/*	Shift - Insert				*/
		(window.event.shiftKey &&  kc == 121              ) ||	/*	Shift - F10					*/
		(kc == 93							              )		/*	Windows Key - Right Click	*/
		) 
	{
		alert("This functionality is not allowed.");
		window.event.returnValue = false;
	}
	if (event.keyCode == 8)
	{
		event.keyCode = 0;
	}	

}

			
function trapContentPasteMouse() 
{
	var mb					=	window.event.button;
	var triggerElement		=	window.event.srcElement.tagName;
				
	//	variable forbiddenElements is declare in the general section, 
	//	at the beginning of this file
				
	if (mb == 2 && (triggerElement == forbiddenElements[0] || triggerElement == forbiddenElements[1])) 
	{
		alert("This functionality is not allowed.");
		window.event.returnValue = false;
					 
	}
	
	else if (mb == 2)
	{
		//alert("Please use keys.");
		//window.event.returnValue = false;
	}
						
}
	
function clearClientClipBoard() 
{
	window.clipboardData.clearData();
}

	
function attachTrapContentPasteIEMenuEvent()
{
	
	var iCount, oColl;
	var oTrig;
				
	oColl		=	document.all;
	
	if (oColl == null) return;
				
	for (iCount = 0; iCount < oColl.length; iCount++) 
	{
		oTrig	=	oColl.item(iCount);
		if (oTrig.tagName == forbiddenElements[0] || oTrig.tagName == forbiddenElements[1]) 
		{
			oTrig.attachEvent("onbeforepaste", clearClientClipBoard);
		}
	}
	
}
function echeck(value) {

		/*var at="@"
		var dot="."
		var usc="_"
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter valid emailid in the format name@hotmail.com")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter valid emailid in the format name@hotmail.com")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter valid emailid in the format name@hotmail.com")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter valid emailid in the format name@hotmail.com")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter valid emailid in the format name@hotmail.com")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter valid emailid in the format name@hotmail.com")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter valid emailid in the format name@hotmail.com")
		    return false
		 }

 		 return true	*/

 		var rx = new RegExp("\\w+([.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
		var matches = rx.exec(value);
		return (matches != null && value == matches[0]);			
	}
//5*5$DGCX-FUT|5*9$DGCX-OPT|6*1$DGCX-SPOT|1*$ADSM|3*$DFM

/*Parameters
1	DDl object
2	Applet object
3	Market Type	(1-Equity, 2-Derivative, 0-Both)
4	Check Mkt allowed - if true Applet will check Mkt allowed flag
5	Check Ord allowed - if true Applet will check Ord allowed flag
6	Return Mapped Id - if true Applet will return Mapped Mkt Seg Id
7	Add All - if true FillExchInstDD will add 'All' in DDl
8	Default value
9	Instrument Tyle (0-All, 1-Spot, 4-Future, 3-Option)
*/
function FillExchInstDD(oDDL, oCom, nMktType, bMktAlwd, bOrdAlwd, bMapMktId, bAddAll, strDefault, nInstType)
{
	try
	{
		if(nInstType == undefined)
			nInstType = "0";
	
		var strExchInstList = new String(oCom.GetExchangeSegmentInfo(nMktType, bMktAlwd, bOrdAlwd, bMapMktId, nInstType));
		
		var arExchInst = strExchInstList.split("|");
		
		var arExchInstEle;
		var oOpt;
		oDDL.innerHTML = "";
		if(bAddAll)
		{
		    oOpt = document.createElement("OPTION");
	        oOpt.innerHTML = "All";
	        oOpt.value = "0";
	        oDDL.appendChild(oOpt);
		}
		
		for(i=0; i < arExchInst.length; i++)
		{
			if(arExchInst[i] == "") continue;
			
			arExchInstEle = arExchInst[i].split("$");
			
			oOpt = document.createElement("OPTION");
	        oOpt.innerHTML = arExchInstEle[1];
	        oOpt.value = arExchInstEle[0];
	        oDDL.appendChild(oOpt);
			
			if(strDefault == oOpt.value)
			{
				oOpt.selected = true;
			}
		}
	}
	catch(e)
	{
		LMsg('FillExchInstDD : ' + e.message);
	}
}

function GetIds(strIds)
{
	return strIds.split(C_V_ID_SEPERATOR);
}

function GetMktType( oCom, intExchId, intInstId)
{
	try
	{
		return oCom.GetMarketType(intExchId + C_V_ID_SEPERATOR + intInstId);
	}
	catch(e)
	{
		LMsg('GetMktType : ' + e.message);
	}
}

function GetInstType( oCom, intExchId, intInstId)
{
	try
	{
		return oCom.GetInstrumentType(intExchId + C_V_ID_SEPERATOR + intInstId);
	}
	catch(e)
	{
		LMsg('GetInstType : ' + e.message);
	}
}

function FillExchDD(oDDL, oCom, nMktType, bMktAlwd, bOrdAlwd, bMapMktId, bAddAll, strDefault)
{
	try
	{
		var strExchInst = String(oCom.GetExchanges(nMktType,bMktAlwd,bOrdAlwd,bMapMktId));
		
		arExchInst = strExchInst.split("|");
		
		var arExchInstEle;
		var oOpt;
		oDDL.innerHTML = "";
		if(bAddAll)
		{
		    oOpt = document.createElement("OPTION");
	        oOpt.innerHTML = "All";
	        oOpt.value = "0";
	        oDDL.appendChild(oOpt);
		}
		for(i=0; i < arExchInst.length; i++)
		{
			if(arExchInst[i] == "") continue;
			
			arExchInstEle = arExchInst[i].split("$");
			
			oOpt = document.createElement("OPTION");
	        oOpt.innerHTML = arExchInstEle[1];
	        oOpt.value = arExchInstEle[0];
	        oDDL.appendChild(oOpt);
			
			
			if(strDefault == oOpt.value)
			{
				oOpt.selected = true;
			}
		}
	}
	catch(e)
	{
		LMsg('FillExchDD : ' + e.message);
	}
}
function GetNames(strNames)
{
	return strNames.split(C_V_NAME_SEPERATOR);
}
function GetKeyCode(e)
{
    try
    {
        if(e.which != null) 
        { // Look for a Mozilla-compatible browser
            return e.which;
        }
        else 
        { // Must be an IE-compatible Browser
            return e.keyCode;
        }
    }
    catch(e)
	{
		LMsg('GetKeyCode : ' + e.message);
	}
}
function GetSource(e)
{
    if(e.which != null)
    {
        return e.target.className;
    }
    else
    {
        return e.srcElement.className;
    }
}
function SetKeyCode(e, code)
{
    try
    {
        if(e.which != null) 
        { // Look for a Mozilla-compatible browser
        }
        else 
        { // Must be an IE-compatible Browser
            e.keyCode = code;
        }
        if(code == 0)
        {
            e.cancelBubble = true;
            return false;
        }
        else
        {
            return true;
        }
    }
    catch(e)
	{
		LMsg('SetKeyCode : ' + e.message);
	}
}
function GetComObj(oWin)
{
    try
    {
        var oTempWin = oWin;
        while(oTempWin.blMainPage == undefined)
        {
            oTempWin = oTempWin.parent;
        }
        return oTempWin.getObj();
    }
    catch(e)
    {
        LMsg('GetComObj : ' + e.message);
    }
}
function GetiDAObj(oWin)
{
    try
    {
        var oTempWin = oWin;
        while(oTempWin.blMainPage == undefined)
        {
            oTempWin = oTempWin.parent;
        }
        return oTempWin.getiDA();
    }
    catch(e)
    {
        LMsg('GetComObj : ' + e.message);
    }
}

function GetIndexOfObject(oObject,id)
{
    try
    {
        for(var i=0; i < oObject.length; i++)
        {
            if(oObject[i].id == id)
            {
                return i;
            }
        }
        return "";
    }
    catch(e)
    {
        return "";
    }
}
function GetFormatNumber(nVal,iPrec)
{
    if(!isNaN(nVal))
    {
        if(!isNaN(iPrec))
        {
            return parseFloat(nVal).toFixed(iPrec);
        }
        return parseFloat(nVal).toFixed(2);
    }
}
function TimeOut()
{
    try
    {
		alert("Your session timed out. Please login again");
        window.open("LoginApplet.htm","_top");
    }
     catch(e)
    {
       
    }
}
 function SpecialKeys(e)
        {
	        try
	        {
        /*var blRet = true;
		        if ((GetKeyCode(e) >= 65 && GetKeyCode(e) <= 90)||(GetKeyCode(e) >= 97 && GetKeyCode(e) <= 122))
		        {		
		        }
		        else if (GetKeyCode(e) >= 48 && GetKeyCode(e) <= 57)
		        {	}
		        else if(GetKeyCode(e) == 13)
		        {	}
		        else 
		        {
			        SetKeyCode(e,0);
			        blRet = false;
			    }
	    return blRet;*/
	    return OnSplKeys(e);
	        }
	        catch(e)
	        {	
        LMsg('SpecialKeys ' + e.message);
	        }
        }
function TrimHTML(objTxtValue, bGetData)
{
    try
    {
        var strRet = objTxtValue;
        if((bGetData != undefined)&&(bGetData))
    {
            var arVal = objTxtValue.split("&nbsp;");
            if(arVal.length > 1)
        {
                strRet = arVal[1];
        }
    }
        else
        {
            strRet = objTxtValue.split("&nbsp;").join("");
    }
        
    }
    catch(e)
    {
        strRet = objTxtValue;
    }	
    return strRet;
}
function GetExpNumber(dblInterest, dblContractDays)
{
		return Math.pow(2.71, ((dblInterest/100)*(dblContractDays/365)));
}
function addCommas(nStr)
{
    try
    {
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test (x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }
    catch(e)
    {
        return nStr;
    }
}

function removeCommas(nStr)
{
    try
    {
        return nStr.split(",").join("");
    }
    catch(e)
    {
        return nStr;
    }
}

function ShowTooltip(obj, strMsg, strColor, strPosition)
{
    try
    {
        if((strPosition == undefined) ||(strPosition == ''))
            strPosition = "left";
        
        //For Tooltip object
        tooltipObj = new TP_formTooltip();
        if((strColor == undefined)||(strColor == ''))
        {
            tooltipObj.setPageBgColor('#EEEEEE');
        }
        else
        {
            tooltipObj.setPageBgColor(strColor);
        }
        tooltipObj.setTooltipCornerSize(15);

        tooltipObj.setTooltipPosition(strPosition);
        tooltipObj.__displayTooltip(obj, strMsg);
    }
    catch(e)
    {
        LMsg('ShowTooltip ' + e.message);
    }
}

function HideToolTip()
{
    try
    {
        if(tooltipObj != null)
	    {
	        tooltipObj.__hideTooltipFromLink();
	    }
    }
    catch(e)
    {
        LMsg('HideToolTip ' + e.message);
    }
}

function OWHelp(obj)
{
    var strSet="width=830px,height=700px,resizable=no,scrollbars=yes,top=100,left=100"
    window.open(obj ,'',strSet);
}
		
function checkCapsLock( e ) {
	var myKeyCode=0;
	var myShiftKey=false;
	var myMsg='Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';

	// Internet Explorer 4+
	if ( document.all ) {
		myKeyCode=e.keyCode;
		myShiftKey=e.shiftKey;

	// Netscape 4
	} else if ( document.layers ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	// Netscape 6
	} else if ( document.getElementById ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	}

	// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
		alert( myMsg );
	// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
		alert( myMsg );
    }
}
