function submitForm()
{
document.toShowOrder.submit();
}


//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

//Gets called when country combo box selection changes
function OnCountryChange() 
{
	var countryList = document.getElementById("Country");

	//Getting the selected country from country combo box.
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
	//alert(selectedCountry);
	// URL to get states for a given country
	
	var requestUrl = "/Ajax/GetStateList.asp?SelectedCountry=" + encodeURIComponent(selectedCountry);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}

function OnQuoteChange(pkgID, contractMonth) 
{

	var quote = document.getElementById("cmbQuote");
	var selectedQuote = quote.options[quote.selectedIndex].value;
	
	if (selectedQuote == "")
		return;
	var requestUrl
	requestUrl = "/Ajax/GetQuote.asp?Quote=" + encodeURIComponent(selectedQuote) + "&pkgid=" + pkgID;
	
	if (pkgID == "104" || pkgID == "108")
	{
		var contractMonth = document.getElementById("contractMonth");
		
		contractMonth = contractMonth.options[contractMonth.selectedIndex].text;
		requestUrl += "&ContractMonth=" + contractMonth;
		
	}
	//alert(requestUrl);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleQuoteResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}

function OnLoginClick()
{
	showdeadcenterdiv("loginSubmit", "loader");
	
	var UserName = document.getElementById("UserName").value;
	var Password = document.getElementById("Password").value;
	//var flag = document.getElementById("Flag").value;
	//var RememberMe = document.getElementById("RememberMe").checked;
	var RememberMe = "off";
	
	//alert("aa");
	var requestUrl
	requestUrl = "/Ajax/Login.asp?UserName=" + UserName + "&Password=" + Password + "&RememberMe=" + RememberMe;
	//alert(requestUrl);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleLoginResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
	
}

function OnStockChatLoad(isSingleRow)
{
	//alert("aa");
	
	var requestUrl
	if (isSingleRow == true)
		requestUrl = "/Ajax/StockChatSingleRow.asp?rand=" + Math.floor(Math.random()*10000);
	else
		requestUrl = "/Ajax/StockChat.asp?rand=" + Math.floor(Math.random()*10000);
	//alert(requestUrl);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		if (isSingleRow == true)
			XmlHttp.onreadystatechange = HandleStockChatResponseSingleRow;
		else
			XmlHttp.onreadystatechange = HandleStockChatResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
	
}

function OnAdminStockChatLoad(isSingleRow)
{
	//alert("aa");
	
	var requestUrl
	if (isSingleRow == true)
		requestUrl = "/Ajax/StockChatSingleRow_Admin.asp?rand=" + Math.floor(Math.random()*10000);
	else
		requestUrl = "/Ajax/StockChat_Admin.asp?rand=" + Math.floor(Math.random()*10000);
	//alert(requestUrl);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		if (isSingleRow == true)
			XmlHttp.onreadystatechange = HandleStockChatResponseSingleRowAdmin;
		else
			XmlHttp.onreadystatechange = HandleStockChatResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
	
}

function OnForgotPasswordClick()
{
	//document.getElementById("Submit").value = "Processing...";
	
	var EmailAddress = document.getElementById("EmailAddress").value;
	//alert("aa");
	var requestUrl
	requestUrl = "/Ajax/ForgotPassword.asp?EmailAddress=" + EmailAddress;
	//alert(requestUrl);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleForgotPasswordResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
	//document.getElementById("Submit").value = "Login";
}

//Called when response comes back from server
function HandleResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			ClearAndSetStateListItems(XmlHttp.responseXML.documentElement);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

function HandleContractMonthResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			ClearAndSetContractMonth(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

function HandleQuoteResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			//alert(XmlHttp.responseText);
			
			PopulateQuoteDetails(XmlHttp.responseXML.documentElement)
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

function HandleLoginResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			//alert(XmlHttp.responseText);
			PopulateLoginErrorMessage(XmlHttp.responseXML.documentElement)
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
			//document.getElementById("errLabel").innerText = "There was a problem retrieving data from the server.";
			//document.getElementById("errLabel").textContent = "There was a problem retrieving data from the server.";
			document.getElementById("loginSubmit").value = "Login";
			document.getElementById("loginSubmit").disabled = false;
			document.getElementById("loader").style.display = "none";
			document.getElementById("UserName").focus();
		}
	}
}

function HandleStockChatResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			//alert(XmlHttp.responseText);
			if (XmlHttp.responseText != "")
			{
				document.getElementById("chatDisp").innerHTML = XmlHttp.responseText;// + document.getElementById("chatDisplay").innerHTML;
			}
		}
		else
		{
			window.location.reload(true);
		}
	}
}

function HandleStockChatResponseSingleRow()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			//alert(XmlHttp.responseText);
			if (XmlHttp.responseText != "")
			{
				if(document.getElementById("live_market") != null)
					document.getElementById("live_market").style.display = "none";
				document.getElementById("chatDisp").innerHTML = XmlHttp.responseText + document.getElementById("chatDisp").innerHTML;
				//if (navigator.appName == "Microsoft Internet Explorer")
					window.focus();
				//else
				//	alert("New message has been posted!");
				//window.open ("/Login/Subs/NewMsg.asp", "newMsg", "width=200, height=100, scrollbars=1;statusbar=0;")
				window.open ("/AJAX/NewMsg.asp", "newMsg", "width=300, height=150, scrollbars=1;statusbar=0;")
			}
		}
		else
		{
			window.location.reload(true);
		}
	}
}

function HandleStockChatResponseSingleRowAdmin()
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{	
			if (XmlHttp.responseText != "")
			{
				if(document.getElementById("live_market") != null)
					document.getElementById("live_market").style.display = "none";
				document.getElementById("chatDisp").innerHTML = XmlHttp.responseText + document.getElementById("chatDisp").innerHTML;
				window.focus();
			}
		}
		else
		{
			window.location.reload(true);
		}
	}
}

function HandleForgotPasswordResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		//alert(XmlHttp.status);
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			//alert(XmlHttp.responseText);
			PopulateForgotPasswordErrorMessage(XmlHttp.responseXML.documentElement)
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
			document.getElementById("loginSubmit").value = "Login";
			document.getElementById("loginSubmit").disabled = false;
			document.getElementById("loader").style.display = "none";
		}
	}
}

function PopulateLoginErrorMessage(loginNode)
{
	var msg = loginNode.getAttribute("msg");
	if (msg == "Success")
	{
		window.location.href = "/Redirect.asp?From=Login";
	}
	else if (msg == "ActivationRequired")
	{
		window.location.href = "/Login/AccountNotActivated.asp";
	}
	else
	{
		alert(msg);
		//document.body.inn
		//document.getElementById("errLabel").innerText = msg;
		//document.getElementById("errLabel").textContent = msg;
		document.getElementById("loginSubmit").value = "Login";
		document.getElementById("loginSubmit").disabled = false;
		document.getElementById("loader").style.display = "none";
		document.getElementById("UserName").focus();
	}
}

function PopulateForgotPasswordErrorMessage(fpNode)
{
	var msg = fpNode.getAttribute("msg");
	if (msg == "Success")
	{
		document.getElementById("forgotpassword_error").innerText = msg;
	}
	else
	{
		alert(msg);
		//document.getElementById("forgotpassword_error").innerText = msg;
		//document.getElementById("forgotpassword_error").textContent = msg;
	}
}


function PopulateQuoteDetails(quoteNode)
{
	//alert(quoteNode.getAttribute("last_traded_price"));
	//alert(quoteNode.innerText);
	//var nodQuote = quoteNode.getElementsByTagName('Quote');

	//alert(quoteNode.getAttribute("company_code"));
	//var nodCompanyName = quoteNode.getElementsByTagName('company_name');
	//var nodCurrentPrice = quoteNode.getElementsByTagName('last_traded_price');
	////alert(nodCurrentPrice[0].innerText);
	////var companyName = document.getElementById("companyName");
	//alert(quoteNode.getAttribute("company_name"));
	
	document.getElementById("companyName").innerText = quoteNode.getAttribute("company_name");
	//document.getElementById("hidCompanyName").innerText = quoteNode.getAttribute("company_name");
	//document.getElementById("txtCurrentPrice").innerText = quoteNode.getAttribute("last_traded_price");
	document.getElementById("companyName").textContent = quoteNode.getAttribute("company_name");
	var lotSize = quoteNode.getAttribute("lot_size");
	if (lotSize == null)
	{
		lotSize = "0";
	}
	if (lotSize != "0")
	{
		document.getElementById("companyName").innerText += " - Lot Size: " + lotSize;
		document.getElementById("companyName").textContent += " - Lot Size: " + lotSize;
	}
	
	document.getElementById("hidCompanyName").value = quoteNode.getAttribute("company_name");
	document.getElementById("hidLotSize").value = lotSize;
	
	document.getElementById("txtCurrentPrice").value = quoteNode.getAttribute("last_traded_price");
	
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetStateListItems(countryNode)
{
    var stateList = document.getElementById("State");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = countryNode.getElementsByTagName('Choices');
	stateNodes = countryNode.getElementsByTagName('Choice');
	var text; 
	var optionItem;
	var value;
	
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		text = GetInnerText(stateNodes[count]);
   		if (text == undefined)
   			text = ""
   		value = stateNodes[count].getAttribute("value");
   		//alert(textValue);
		optionItem = new Option( text, value,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
}


function ClearAndSetContractMonth(list)
{


    var stateList = document.getElementById("contractMonth");
	if (list == "")
	{
		stateList.value = "";
		return false;
	}

	//Clears the state combo box contents.
	/*
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}
	*/
	var text; 
	var optionItem;
	var value;
	var l_ArrayScripts;
	l_ArrayScripts = list.split(",");
	/*
	//Add new states list to the state combo box.
	for (var count = l_ArrayScripts.length-1; count >= 0; count--)
	{
		text = l_ArrayScripts[count].toUpperCase()
   		if (text == undefined)
   			text = ""
   		value = text;
   		//alert(textValue);
		optionItem = new Option( text, value,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
	*/
	stateList.value = l_ArrayScripts[l_ArrayScripts.length-1];
}


//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}

function OnCallTypeChange()
{
	var frm = document.frmQuote;
	var callTypeValue = frm.cmbCallType.options[frm.cmbCallType.selectedIndex].value;
	//alert(callTypeValue);
	if (callTypeValue == '103' || callTypeValue == '104')
	{
		frm.cmbType.selectedIndex = 0;
		//frm.cmbType.disabled = true;
		frm.cmbType.readonly = true;
	}
	else if (callTypeValue == "107")
	{
		frm.cmbType.selectedIndex = 1;
		//frm.cmbType.disabled = true;
	}
	else
	{
		//frm.cmbType.disabled = false;
	}
}

function OnCheckTwoChange()
{
	var frm = document.frmQuote;
	var checkValue = frm.m_CheckTwo.checked;
	
	if (checkValue == false)
	{
		frm.txtBuySell2.disabled = true;
		frm.txtTarget12.disabled = true;
		frm.txtTarget22.disabled = true;
		frm.txtStoploss2.disabled = true;
		if(document.getElementById("tabTwo") != null)
			document.getElementById("tabTwo").style.display = "none";
	}
	else
	{
		frm.txtBuySell2.disabled = false;
		frm.txtTarget12.disabled = false;
		frm.txtTarget22.disabled = false;
		frm.txtStoploss2.disabled = false;
		if(document.getElementById("tabTwo") != null)
			document.getElementById("tabTwo").style.display = "block";
	}
	
}


function OnPredefinedCheckChange()
{
	var frm = document.frmQuote;
	var checkValue = frm.chkPredefined.checked;

	if (checkValue == true)
	{
		//frm.txtComments.value = frm.cmbCommentCombo[frm.cmbCommentCombo.selectedIndex].text
		frm.cmbCommentCombo.style.display = "block";
		frm.cmbCommentsPkgID.selectedIndex = 0;
		frm.cmbCommentsPkgID.style.display = "none";
	}
	else
	{
		frm.cmbCommentCombo.selectedIndex = 0;
		frm.txtComments.value = "";
		frm.cmbCommentCombo.style.display = "none";
		frm.cmbCommentsPkgID.style.display = "block";
	}
}

function OnCommentCheckChange()
{
	var frm = document.frmQuote;
	var checkValue = frm.chkComments.checked;

	if (checkValue == true)
	{
		document.getElementById("spanPredefined").style.display = "block";
		frm.cmbCommentCombo.selectedIndex = 0;
		frm.cmbCommentsPkgID.selectedIndex = 0;
		frm.cmbCommentsPkgID.style.display = "block";
		//frm.cmbCommentCombo.style.display = "block";
		//frm.txtComments.value = frm.cmbCommentCombo[frm.cmbCommentCombo.selectedIndex].text;
		frm.cmbCallType.disabled = true;
		frm.cmbQuote.disabled = true;
		frm.txtCurrentPrice.disabled = true;
		frm.cmbType.disabled = true;
		frm.txtBuySell.disabled = true;
		frm.txtTarget1.disabled = true;
		frm.txtTarget2.disabled = true;
		frm.txtStoploss.disabled = true;
		frm.contractMonth.disabled = true;
		frm.hidLotSize.disabled = true;
		if (frm.txtType != null)
		{
			frm.txtType.disabled = true;
		}
		if (frm.txtBuySell2 != null)
		{
			frm.txtBuySell2.disabled = true;
			frm.txtTarget12.disabled = true;
			frm.txtTarget22.disabled = true;
			frm.txtStoploss2.disabled = true;
			frm.m_CheckTwo.checked = false;
			frm.m_CheckTwo.disabled = true;
		}
		//if(frm.isActive != null)
		//	frm.isActive.disabled = true;
		if(frm.isPublish != null)
			frm.isPublish.disabled = true;
		if(frm.cmbResult != null)
			frm.cmbResult.disabled = true;
		if(frm.resultPrice != null)
			frm.resultPrice.disabled = true;

		document.getElementById("tabOne").style.display = "none";
		if(document.getElementById("tabTwo") != null)
			document.getElementById("tabTwo").style.display = "none";
	}
	else
	{
		frm.cmbCommentCombo.selectedIndex = 0;
		frm.cmbCommentsPkgID.selectedIndex = 0;
		frm.txtComments.value = "";
		frm.cmbCommentCombo.style.display = "none";
		frm.cmbCommentsPkgID.style.display = "none";
		document.getElementById("spanPredefined").style.display = "none";
		frm.chkPredefined.checked = false;
		//frm.txtComments.value = "";
		//frm.cmbCommentCombo.style.display = "none";
		frm.cmbCallType.disabled = false;
		frm.cmbQuote.disabled = false;
		frm.txtCurrentPrice.disabled = false;
		frm.cmbType.disabled = false;
		frm.txtBuySell.disabled = false;
		frm.txtTarget1.disabled = false;
		frm.txtTarget2.disabled = false;
		frm.txtStoploss.disabled = false;
		frm.contractMonth.disabled = false;
		frm.hidLotSize.disabled = false;
		if (frm.txtType != null)
		{
			frm.txtType.disabled = false;
		}

		if (frm.txtBuySell2 != null)
		{
			frm.m_CheckTwo.checked = false;		
			frm.m_CheckTwo.disabled = false;
			frm.txtBuySell2.disabled = true;
			frm.txtTarget12.disabled = true;
			frm.txtTarget22.disabled = true;
			frm.txtStoploss2.disabled = true;
		}
		//if(frm.isActive != null)
		//	frm.isActive.disabled = false;
		if(frm.isPublish != null)
			frm.isPublish.disabled = false;
		if(frm.cmbResult != null)
			frm.cmbResult.disabled = false;
		if(frm.resultPrice != null)
		{
			if(frm.cmbResult.options[frm.cmbResult.selectedIndex].value == '0' || frm.cmbResult.options[frm.cmbResult.selectedIndex].value == '1' || frm.cmbResult.options[frm.cmbResult.selectedIndex].value == '2' || frm.cmbResult.options[frm.cmbResult.selectedIndex].value == '3' || frm.cmbResult.options[frm.cmbResult.selectedIndex].value == '4')
				frm.resultPrice.disabled = true;
			else
				frm.resultPrice.disabled = false;
		}

		document.getElementById("tabOne").style.display = "block";
		if(document.getElementById("tabTwo") != null)
		{
			if(frm.m_CheckTwo.checked)
				document.getElementById("tabTwo").style.display = "block";
			else
				document.getElementById("tabTwo").style.display = "none";
		}
	}
}

function CallValidateStockEntry(frm, IsInstantSend)
{
	if (frm.forDate != undefined)
	{
		if (frm.forDate.value == "")
		{
			alert("Choose date.");
			return false;
		}
	}

	var frmBuySellPrice = frm.txtBuySell;
 	var frmTarget1 = frm.txtTarget1;
	var frmTarget2 = frm.txtTarget2;
	var frmStoploss = frm.txtStoploss;
	var frmContractMonth = frm.contractMonth;
	var frmHidLotSize = frm.hidLotSize;
	
	var buySellPrice = parseFloat(frmBuySellPrice.value);
	var target1 = parseFloat(frmTarget1.value);
	var target2 = parseFloat(frmTarget2.value);
	var stopLoss = parseFloat(frmStoploss.value);
	var type;
	if (frm.cmbType == "[object HTMLSelectElement]")
		type = frm.cmbType.options[frm.cmbType.selectedIndex].value;
	else
		type = frm.cmbType.value;
	
	if (frm.cmbQuote.options[frm.cmbQuote.selectedIndex].value == "")
	{
		alert("Choose Script.");
		frm.cmbQuote.focus();
		return false;
	}
 
	 if (frmContractMonth.value == "")
	{
		alert("Enter Contract Month");
		frmContractMonth.focus();
		return false;
	}
	 if (frmHidLotSize.value == "")
	{
		alert("Enter Lot Size");
		frmHidLotSize.focus();
		return false;
	}

	if (frm.txtCurrentPrice.value == "" || isNaN(frm.txtCurrentPrice.value))
	{
		//alert("Enter valid current price.");
		//frm.txtCurrentPrice.focus();
		//return false;
	}

	if (buySellPrice == "" || isNaN(buySellPrice))
	{
		alert("Enter valid buy / sell price.");
		frm.txtBuySell.focus();
		return false;
	}
 
	if (target1 == "" || isNaN(target1))
	{
		alert("Enter valid target 1 price.");
		frm.txtTarget1.focus();
		return false;
	}

	if (target2 == "" || isNaN(target2))
	{
		//alert("Enter valid target 2 price.");
		//frm.txtTarget2.focus();
		//return false;
	}

	if (stopLoss == "" || isNaN(stopLoss))
	{
		alert("Enter valid stoploss price.");
		frm.txtStoploss.focus();
		return false;
	}
	
	if (type == "2")
	{
		//alert(stopLoss + " " + buySellPrice);
		if (target1 <= buySellPrice)
		{
			alert("Target 1 should not be less then Buy Price for LONG position.");
			frmTarget1.focus();
			return false;
		}
		
		if (target2 <= buySellPrice)
		{
			alert("Target 2 should not be less then Buy Price for LONG position.");
			frmTarget2.focus();
			return false;
		}
		if (target2 <= target1)
		{
			alert("Target 2 should not be less than Target 1 for LONG position.");
			frmTarget2.focus();
			return false;
		}
		if (stopLoss >= buySellPrice)
		{
			alert("Stoploss should be less than Buy Price for LONG position.");
			frmStoploss.focus();
			return false;
		}
		
	}
	
	if (type == "1")
	{
		if (target1 >= buySellPrice)
		{
			alert("Target 1 should be less then Sell Price for SHORT position.");
			frmTarget1.focus();
			return false;
		}
		
		if (target2 >= buySellPrice)
		{
			alert("Target 2 should be less then Sell Price for SHORT position.");
			frmTarget2.focus();
			return false;
		}
		if (target2 >= target1)
		{
			alert("Target 2 should be less than Target 1 for SHORT position.");
			frmTarget2.focus();
			return false;
		}
		if (stopLoss <= buySellPrice)
		{
			alert("Stoploss should be greater than Sell Price for SHORT position.");
			frmStoploss.focus();
			return false;
		}
	}
	
	if(frm.m_CheckTwo != null)
	{
		if(frm.m_CheckTwo.checked == true)
		{
			frmBuySellPrice = frm.txtBuySell2;
			frmTarget1 = frm.txtTarget12;
			frmTarget2 = frm.txtTarget22;
			frmStoploss = frm.txtStoploss2;
			
			
			buySellPrice = parseFloat(frmBuySellPrice.value);
			target1 = parseFloat(frmTarget1.value);
			target2 = parseFloat(frmTarget2.value);
			stopLoss = parseFloat(frmStoploss.value);

			type = frm.cmbType.options[frm.cmbType.selectedIndex].value;
			
			if (buySellPrice == "" || isNaN(buySellPrice))
			{
				alert("Enter valid buy / sell price.");
				frmBuySellPrice.focus();
				return false;
			}
		 
			if (target1 == "" || isNaN(target1))
			{
				alert("Enter valid target 1 price.");
				frmTarget1.focus();
				return false;
			}

			if (stopLoss == "" || isNaN(stopLoss))
			{
				alert("Enter valid stoploss price.");
				frmStoploss.focus();
				return false;
			}
			
			if (type == "1")
			{
				//alert(stopLoss + " " + buySellPrice);
				if (target1 <= buySellPrice)
				{
					alert("Target 1 should not be less then Buy Price for LONG position.");
					frmTarget1.focus();
					return false;
				}
				
				if (target2 <= buySellPrice)
				{
					alert("Target 2 should not be less then Buy Price for LONG position.");
					frmTarget2.focus();
					return false;
				}
				if (target2 <= target1)
				{
					alert("Target 2 should not be less than Target 1 for LONG position.");
					frmTarget2.focus();
					return false;
				}
				if (stopLoss >= buySellPrice)
				{
					alert("Stoploss should be less than Buy Price for LONG position.");
					frmStoploss.focus();
					return false;
				}
				
			}
			
			if (type == "2")
			{
				if (target1 >= buySellPrice)
				{
					alert("Target 1 should be less then Sell Price for SHORT position.");
					frmTarget1.focus();
					return false;
				}
				
				if (target2 >= buySellPrice)
				{
					alert("Target 2 should be less then Sell Price for SHORT position.");
					frmTarget2.focus();
					return false;
				}
				if (target2 >= target1)
				{
					alert("Target 2 should be less than Target 1 for SHORT position.");
					frmTarget2.focus();
					return false;
				}
				if (stopLoss <= buySellPrice)
				{
					alert("Stoploss should be greater than Sell Price for SHORT position.");
					frmStoploss.focus();
					return false;
				}
			}
		}
	}

	if(confirm("Are you sure you want to submit?"))
	{
		if(IsInstantSend == true)
		{
			 frm.action = "/TrendAdmin/Stock/FrameStockEntry.asp?instant=true";
			 frm.submit;
		}
		return true;
	}
	else
		return false;
}

function ValidateStockEntry(IsInstantSend)
{
 var frm = document.frmQuote;
 if (frm.chkComments.checked == false)
 {
	if (CallValidateStockEntry(frm, IsInstantSend) == false)
	{
		return false;
	}
 }
 else
 {
	if(frm.chkPredefined.checked)
	{
		if(frm.cmbCommentCombo.selectedIndex == 0)
		{
			alert("Select the comment;");
			frm.cmbCommentCombo.focus();
			return false;
		}
	}
	else
	{
		if(frm.cmbCommentsPkgID.selectedIndex == 0)
		{
			alert("Select the service for which SMS to be sent.;");
			frm.cmbCommentsPkgID.focus();
			return false;
		}
	 }

	if (frm.txtComments.value == "")
	{
		alert("Enter comments.");
		frm.txtComments.focus();
		return false;
	}
	if(frm.txtComments.value.length > 158)
	{
		alert("SMS Text should not be more than 160 characters length:\nCurrent Total Length is " + frm.txtComments.value.length + "\n\n Please change the comment to make it short");
		frm.txtComments.focus();
		return false;
	}

	if(confirm("Are you sure you want to submit?"))
	 {
		if(IsInstantSend == true)
		{
			 frm.action = "/TrendAdmin/Stock/FrameStockEntry.asp?instant=true";
			 frm.submit;
		}
		return true;
	 }
	else
		return false;
	}
}


function showPreview()
{
	var frm = document.frmQuote;
	var comments = document.getElementById("txtComments").innerText;
	//alert(comments);
	if (frm.chkComments.checked == true)
	{
		//document.getElementById("divComment").style.visible = "show";
		document.getElementById("paraComment").innerText = comments;
	}
	else
	{
		document.getElementById("bCallType").innerText = frm.cmbCallType.options[frm.cmbCallType.selectedIndex].text;
		document.getElementById("hScript").innerText = frm.cmbQuote.options[frm.cmbQuote.selectedIndex].text;
	}
}

function ValidateForDate(frm)
{
	if (frm.forDate.value == "")
	{
		alert("Choose date.");
		return false;
	}
}


function ValidateUserName()
{
	var userName = document.headerLogin.UserName.value;
	
	if (userName == "Email Address")
	{
		document.headerLogin.UserName.value = "";
	}

}

function ValidatePassword()
{
	var password = document.headerLogin.Password.value;
	
	if (password == "password")
	{
		document.headerLogin.Password.value = "";
	}

}

function ValidateCheque()
{
	var frm = document.frmConfirmOrder;
	var chequeNumber = frm.chequeNumber.value;
	var bankName = frm.bankName.value;
	var branchName = frm.branchName.value;
	var cityName = frm.cityName.value;
	if (isNaN(chequeNumber))
	{
		alert("Enter valid cheque number.");
		frm.chequeNumber.focus();
		return false;
	}
	if(Trim(chequeNumber) == "")
	{
		alert("Enter cheque number.");
		frm.chequeNumber.value = "";
		frm.chequeNumber.focus();
		return false;
	}
	
	if(Trim(bankName) == "")
	{
		alert("Enter bank name.");
		frm.bankName.value = "";
		frm.bankName.focus();
		return false;
	}
	
	if(Trim(branchName) == "")
	{
		alert("Enter branch name.");
		frm.branchName.value = "";
		frm.branchName.focus();
		return false;
	}
	
	if(Trim(cityName) == "")
	{
		alert("Enter city name.");
		frm.cityName.value = "";
		frm.cityName.focus();
		return false;
	}
	return true;
}

function Trim(val)
{
	return val.replace(/^\s+|\s+$/g,"");
}

function checkKeycode(btnSubmit) 
{
	if ((event.which == 13) || (event.keyCode == 13)) 
	{
		document.getElementById(btnSubmit).click();
		return false;
	}
	
}


/* DISPLAY IN CENTER SCREEN */
function showdeadcenterdiv(btnName, divName) 
{
	var bt = document.getElementById(btnName);
	bt.value = "Logging in...";
	bt.disabled = true;
	
	var dv = document.getElementById(divName);
	dv.style.display = "block";
	
	
	dv.style.top = Math.round((document.documentElement.clientHeight/2)-(dv.style.height/2)+document.documentElement.scrollTop)/3+'px';
	dv.style.left = Math.round((document.documentElement.clientWidth/2)-(dv.style.width/2))/2+"px";
	
} 

function DisplayPasswordHint(show)
{
    try
    {
        var it = document.getElementById("passwordHint");
        
        if (show == 'true')
        {
            var parent = document.getElementById("txtPassword");
            it.style.visibility = 'visible';
        }
        else
            it.style.visibility = 'hidden';
    }
    catch(e){}
}

function newExcitingAlerts() {
    var oldTitle = document.title;
    var msg = "New Message Posted!";
    var timeoutId = setInterval(function() {
        document.title = document.title == msg ? ' ' : msg;
    }, 1000);
    window.onmousemove = function() {
        clearInterval(timeoutId);
        document.title = oldTitle;
        window.onmousemove = null;
    };
}

function hint(id){
var hintbox = document.getElementById(id);
hintbox.style.display='block';
}
function hide(id){
var hintbox = document.getElementById(id);
hintbox.style.display='none';
}
							
function CancelOrder(orderID)
{
if(confirm("Are you sure you want to cancel your pending payment subscription?"))
	window.location.href = "/Login/Subs/Cancel.asp?orderid=" + orderID;
}

function ToggleType()
{
	if(document.frmQuote.cmbType.selectedIndex == 0)
	{
		document.getElementById("m_PanelType").innerHTML = "Enter Short";
		document.getElementById("m_tdBuySell1").innerHTML = "Buy Above<font color=red><sup>*</sup></font>";		
		document.getElementById("m_tdBuySell2").innerHTML = "Sell Below<font color=red><sup>*</sup></font>";
	}
	else
	{
		document.getElementById("m_PanelType").innerHTML = "Enter Long";
		document.getElementById("m_tdBuySell1").innerHTML = "Sell Below<font color=red><sup>*</sup></font>";
		document.getElementById("m_tdBuySell2").innerHTML = "Buy Above<font color=red><sup>*</sup></font>";
	}
}



function OnCommentCombo()
{
	document.frmQuote.txtComments.value = Trim(document.frmQuote.cmbCommentCombo[document.frmQuote.cmbCommentCombo.selectedIndex].text);
}

//var m_Agri = ",Cardamom,Coriander,Jeera,Pepper,Red Chilli,Turmeric,Castor Oil,Coconut Oil,Cotton Seed,Groundnut Oil,Soy Bean,Cotton Yarn,Kapas,Raw Jute,Chana,Masur,Yellow Peas,Rubber";
//var m_Metal = ",Gold,Silver,Platinum,Aluminium,Copper,Lead,Nickel,Sponge Iron,Steel,Tin,Zinc";
//var m_Energy = ",Crude Oil,Natural Gas,ATF,Brent Crude Oil,Furnace Oil,Heating Oil";

// SCRIPT CODE, LOT SIZE, COMPANYNAME
var m_Agri = ",TMCFGRNZM|100|TURMERIC,PEPPER|10|PEPPER,SYBEANIDR|100|SYBEANIDR,CHARJDDEL|100|CHANA,BARLEYJPR|100|BARLEYJPR,CASTORDSA|500|CASTORDSA,CER|250|CER,CFI|250|CFI,CPO|1000|CPO,DHANIYA|100|DHANIYA,JEERAUNJHA|30|JEERAUNJHA,KAPASSRNR|50|KAPASSRNR,MENTHAOIL|360|MENTHAOIL,POTATO|300|POTATO,CARDAMOM|500|CARDAMOM,CORIANDER|50|CORIANDER,JEERA|30|JEERA,KAPASKHALI|200|KAPASKHALI,SUGARS150|100|SUGARS150,SUGARM200|100|SUGARM200,SBMEALIDR|10|SOYABEANMEAL,SBMEXPKDL|10|SBMEALEXPORTKANDLA,MSOILCGNR|100|RMSEEDOILCAKE,RBDPLNKAK|1000|RBDPOLEINKAKINADA,JUTRAWKOL|100|RAWJUTEKOLKATA,RMSEEDJPR|500|RAPEMUSTSEEDJAIPU,PVC6567MUM|3000|POLYVINYLCHLORIDE,PPIM10MUM|3000|POLYPROPYLENE,PPRMLGKOC|10|PEPPERMALABARGARBLE,MTHOILCHD|360|MENTHAOIL,JEERAUNJHA|30|JEERAAVGQLTYUNJHA,GURCHMUZR|250|GURMUZZAFFARNAGAR,GARSEDJDR|100|GARSEDJDR,GARGUMJDR|50|GARGUMJDR,DHANIYA|100|CORIANDER,COFFEERC|2000|COFFEEROBUSTA,CHLL334GTR|50|CHILLILCA334GUNTUJ,CASTORDSA|500|CASTORSEED,STEELLONG|10|STEELLONG";
//var m_Agri = ",Cardamom|10|Cardamom,Coriander|20|Coriander,CHANADEL|30|CHANADEL,JUTE|40|JUTE,LONGCOTTON|50|LONGCOTTON,POTATOTRWR|60|POTATOTRWR,REFSOYOIL|70|REFSOYOIL,Pepper|80|Pepper,Pepper|90|Pepper,KAPASKHALI|100|KAPASKHALI,Rubber|110|Rubber";
var m_Metal = ",Copper|1000|Copper,Lead|5000|Lead,Nickel|250|Nickel,Tin|50|Tin,Zinc|5000|Zinc,Aluminium|5000|Aluminium";
var m_Bullion = ",Gold|100|Gold,GoldM|10|GoldM,Silver|30|Silver,Platinum|250|Platinum";
//var m_Metal = ",Gold|10|Gold,Silver|20|Silver,Platinum|30|Platinum,Aluminium|40|Aluminium,Copper|50|Copper,Lead|60|Lead,Nickel|70|Nickel,Tin|80|Tin,Zinc|90|Zinc";
var m_Energy = ",CRUDEOIL|100|Crude Oil,NATURALGAS|1250|Natural Gas,BRENTCRUDE|100|BRENTCRUDE,COAL|100|COAL,DRB|50|DRB,FURNACEOIL|10|FURNACEOIL,COAL|100|THERMALCOAL,COALWANI|10|THERMALCOALJUNE09";

function LoadScript(pack, script)
{
	if (pack == "")
	{
		pack = document.frmQuote.cmbCallType.options[document.frmQuote.cmbCallType.selectedIndex].value;
		document.getElementById("contractMonth").value = "";
	}	
	var l_ArrayScripts;
	if (pack == "101" || pack == "107")
		l_ArrayScripts = m_Agri.split(",");
	else if(pack == "104")
		l_ArrayScripts = m_Metal.split(",");
	else if(pack == "108")
		l_ArrayScripts = m_Bullion.split(",");
	else if(pack == "103")
		l_ArrayScripts = m_Energy.split(",");	
	
	var l_Select;
	var l_Script;
	var l_ArrayScript;
	l_Select = "<select name='cmbQuote' id='cmbQuote' tabindex='3' style='background-color:#FFFFFF;' onchange='OnScriptChange(" + pack + ");'>";
	for(i=0;i<l_ArrayScripts.length;i++){
		l_Script = l_ArrayScripts[i].toUpperCase()
		l_ArrayScript = l_Script.split("|");
		l_Script = l_ArrayScript[0];
		if(script == l_Script) 
			l_Select += "<option selected>" + l_Script + "</option>";
		else
			l_Select += "<option>" + l_Script + "</option>";
	}	
	l_Select += "</select>";
	
	document.getElementById("m_DivQuote").innerHTML = l_Select;
}


function ToggleResultPrice()
{
	var cmbVal = document.frmQuote.cmbResult.options[document.frmQuote.cmbResult.selectedIndex].value;

	if (cmbVal == "0" || cmbVal == "1" || cmbVal == "8")
	{
		document.frmQuote.resultPrice.style.display = "none";
		document.frmQuote.achievedDate.style.display = "none";
	}
	else if (cmbVal == "6" )
	{
		document.frmQuote.resultPrice.style.display = "inline-block";
		document.frmQuote.achievedDate.style.display = "inline-block";
	}
	else if (cmbVal == "5" || cmbVal == "7" || cmbVal == "9")
	{
		//document.frmQuote.resultPrice.disabled = false;
		document.frmQuote.resultPrice.style.display = "inline-block";
		document.frmQuote.achievedDate.style.display = "none";
		document.frmQuote.resultPrice.select();
	}
	else
	{
		//document.frmQuote.resultPrice.disabled = true;
		document.frmQuote.resultPrice.style.display = "none";
		document.frmQuote.achievedDate.style.display = "inline-block";
	}
}

function NewWindow(url, name, width, height)
{
	win = window.open(url, name, "width= "+ width + ", height="+ height +", toolbar=0, scrollbars=1, status=0, menubar=0, resizable=0");
	win.moveTo((screen.width - width)/2,(screen.height - height)/2);
}

function OnScriptChange(pack) 
{
	var l_Quote = document.getElementById("cmbQuote");

	var l_selectedQuote = l_Quote.options[l_Quote.selectedIndex].value;
	
	var l_ArrayScripts;
	if (pack == "101" || pack == "107")
		l_ArrayScripts = m_Agri.split(",");
	else if(pack == "104")
		l_ArrayScripts = m_Metal.split(",");
	else if(pack == "108")
		l_ArrayScripts = m_Bullion.split(",");
	else if(pack == "103")
		l_ArrayScripts = m_Energy.split(",");	

	for(i=0;i<l_ArrayScripts.length;i++){
		l_Script = l_ArrayScripts[i].toUpperCase();
		l_ArrayScript = l_Script.split("|");
		l_Script = l_ArrayScript[0];
		if(l_selectedQuote == l_Script) 
		{
		    document.getElementById("hidLotSize").value = l_ArrayScript[1];
		    document.getElementById("hidCompanyName").value = l_ArrayScript[2];
		    break;
		}
	}
	
	/*var requestUrl = "/Ajax/GetContractMonth.asp?script=" + encodeURIComponent(l_selectedQuote.replace(" ", ""));
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleContractMonthResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}*/
}

function ShowTipsOnly()
{
	var e=document.getElementsByName("tipsonly");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.display = 'none';
	}
	
	e=document.getElementsByName("commentsonly");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.display = 'inline-block';
	}
}

function ShowCommentsOnly()
{
	var e=document.getElementsByName("commentsonly");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.display = 'none';
	}
	
	e=document.getElementsByName("tipsonly");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.display = 'inline-block';
	}
}

function ShowAll()
{
	var e=document.getElementsByName("commentsonly");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.display = 'inline-block';
	}
	
	e=document.getElementsByName("tipsonly");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.display = 'inline-block';
	}
}


function ValidateLogin()
{
	if(document.m_FormLogin.UserName.value=="")
	{
	alert("Enter your E-Mail Address.");
	document.m_FormLogin.UserName.focus();
	return false;
	}

	if(document.m_FormLogin.Password.value=="")
	{
	alert("Enter your password.");
	document.m_FormLogin.Password.focus();
	return false;
	}
	return true;
}

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX-400) + "px";
d.style.top = (cY+0) + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}

function SendQuickFollowUp(pkgId, chatId, callType, message)
{
	if(!confirm("Are you sure you want to submit?"))
		return false;

	//document.getElementById("Submit").value = "Processing...";
	
	var requestUrl
	requestUrl = "/Ajax/SendQuickFollowUp.asp?PkgId=" + pkgId + "&ChatId=" + chatId + "&CallType=" + callType + "&Message=" + message.replace("&", "-");
	//alert(requestUrl);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleQuickFollowUpResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);
		HideContent('uniquename' + chatId);
	}
	//document.getElementById("Submit").value = "Login";
}

//Called when response comes back from server
function HandleQuickFollowUpResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			alert("Follow-up has been sent!");
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}
