﻿// print functions
var func_before_print="";
var func_after_print="";
var PRINT_AF_DEBUG=false;


//general functions
function fn_stock(pid)
{
	var url="../../../utils/redirect/dirstock.asp?pid=" + pid + "&isltinet=1&";
	fn_jscript(url);
}

function fn_pagedemo(id)
{  
}

function fn_open_foreign_paper_info(str)
{
	window.open("../../../info/abroad/abroaddetails.asp?symbol="+str+"&", "foreign", "toolbar=no,scrollbars=no,left=0,top=0,width=800,height=550,resizable=yes");
}
 
function fn_map(url) 
{
	 window.location.href  = url + "utils/tools/map.asp"; 
}

function fn_readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function fn_logout(AspSiteUrl)
{
	var oHttp;
	var browser;
	
	// url for logout from .NET
	var url = "../../zone/logout.aspx";
	var error;
	
	if (fn_readCookie("ASP.NET_SessionId") != null )
	{
		try
		{
			// code for Mozilla
			if (window.XMLHttpRequest)
			{
				oHttp = new XMLHttpRequest();
				browser = "Mozilla";
			}
			
			// code for IE
			if (window.ActiveXObject)
			{
				oHttp = new ActiveXObject("Microsoft.XmlHttp");
				browser = "IE";
			}
			
			if (oHttp != null)
			{
				oHttp.onreadystatechange=function(){CheckResponseLogout(oHttp,browser,AspSiteUrl);};
				oHttp.open("GET",url, true);
				oHttp.send(null);
			}
			else
			{
				alert("Your browser doesn't support XMLHTTP.")
			}
		}
		catch(e)
		{ 
			error = e.description;
			window.status='הגדרות הדפדפן לא מתאימות לדרישות האתר, אנא פנה למוקד';
		}
	}
	else
		window.location.href = AspSiteUrl + 'zone/logout.asp';
}

function CheckResponseLogout(oHttp,browser,LogOutUrl)
{
	if(oHttp.readyState==4)
	{
		window.status=oHttp.status + " - " + oHttp.statusText;
		
		try
		{
			if(oHttp.status!=200) return;
				
			// logout from asp
			window.location.href = LogOutUrl + 'zone/logout.asp'; 			
		}
		catch(e)
		{
			window.status=e.description;
		}
	}
}

function fn_goto_alerts()
{ 
	window.location.href = '../../../trade/alerts/alertsmain.asp'; 
}

function fn_open_pwd_settings() 
{ 
	window.open('../../../utils/tools/setpassword.asp','secsetwin','height=500,width=620,top=0,left=0,resizeable=1'); 
}


function fn_openbursagraph(pid)
{
	fn_jscript("../../utils/redirect/dirbursa.ashx?pid=" + pid + "&t=" + new Date() + "&");
	//window.open("../../info/graph/graphbursa.asp?pid=" + pid + "&", "bursagraph","top=0,left=0,height=715px,width=810px,scrollbars=yes,resizable=yes");
}

function fn_trade(pid, cmd, trade)
{
	if(cmd==null)
	{
		cmd=(window.event.offsetX >15)?1:2;
	}
	
	var url="dirtrade.ashx?pid=" + pid + "&cmd=" + cmd;
	if(trade!=null)
	{
		url=url + "&trade=" + trade;
	}
	url=url + "&t=" + new Date() + "&";
	fn_jscript(url);
}

function fn_open_searchresult()
{
	window.open("../../utils/search/SearchResult.aspx","SearchResult","toolbar=no,left=0,top=0,width=600,height=662");
}

function fn_search(txtSearch, searchType, paperType, isMaof, RegionID, CountryID, BursaID)
{
	if(searchType==null)searchType=1;
	if(paperType==null) paperType=-1;
	if(isMaof==null)isMaof=0;
		
	if(!fn_checksearch(txtSearch)) return false;
	var txt=fn_search_encode(txtSearch);
	
	if (searchType=='5' || searchType=='6' || searchType=='7')
	{
		fn_jscript('../../net/searchengine.ashx?txt=' + txt + "&rid=" + RegionID + "&cid=" + CountryID + "&bid=" + BursaID + "&");
		return true;
	}
	if ((RegionID=='0') || (searchType!='5'))
	{
		window.open("../../utils/search/searchresults.asp?word=" + txt + "&type="+searchType+"&IsMaof="+isMaof+"&PaperType="+paperType+"&", "SrchRes", "toolbar=no,left=0,top=0,width=450,height=250");
		return true;
	}
	
	return true;
}
	
function fn_checksearch(str, fnc)
{
	if(!fnc) fnc = "alert";
	var invalidChars=".,-+_%", badchr;
	
	if (str.length==0) 
	{
		eval(fnc + "('הכנס טקסט לחיפוש');"); 
		return false;
	}
	if(str.length==1)
	{
		for(var i=0;i<invalidChars.length;i++)
		{
			badchr=invalidChars.charAt(i);
			if(str.indexOf(badchr,0) > -1)
			{
				eval(fnc + "('טקסט לא חוקי לחיפוש');")
				return false;
			}				  
		}
	}
	return true;		
}
				
function fn_searchadv()
{
	window.open('../../../utils/search/searchadv.asp', "advsrch", "toolbar=no,left=0,top=0,width=350,height=320")
}

function fn_open_search_for_calc(st, url)
{
	url = (url==undefined) ? "../../" : url;
	
	window.open(url + 'utils/search/searchcalc.asp?calc_type=' + st + '&', 'calcsearch', 'top=0,left=0');
}

function fn_search_encode(str)
{
 var enc='';
 
	for(var i=0; i<str.length; i++) { enc+=str.charCodeAt(i,1) + "_"; }
	return enc;
}

function fn_open_makam_calc(pid, url)
{
	if(!pid)
		fn_open_search_for_calc('pop_makam', url);
	else
		{window.open('../../../utils/tools/calc_makam.asp?pid=' + pid + '&', 'mk_calc', 'top=0,left=0,width=600,height=390');}
}

function fn_open_makam_calc_Net(pid, url)
{
	if(!pid)
		fn_open_search_for_calc('pop_makam', url);
	else
		window.open(url + 'utils/tools/calc_makam.asp?pid=' + pid + '&', 'mk_calc', 'top=0,left=0,width=600,height=390');
}

function fn_open_option_calc(pid, isShow, url)
{	
	if(!pid)
		fn_open_search_for_calc('pop_maof', url);
	else
		window.open('../../utils/tools/calc_option.asp?opid=' + pid + '&isShow=' + isShow + '&', 'op_calc', 'top=0,left=0,width=600,height=530');
}

function fn_open_option_calc_Net(pid, isShow, AspSiteName)
{
	if(!pid)
		fn_open_search_for_calc('pop_maof', AspSiteName);
	else
	{
		str = AspSiteName + "utils/tools/calc_option.asp?opid=" + pid + "&isShow=" + isShow + "&";		
		window.open(str, 'op_calc', 'top=0,left=0,width=600,height=530');
	}	
}

function fn_download_excel(url)
{
 if(url=='')
 {
	alert("לא נמצאו נתונים");
	return;
 }
 
 var cook=fn_get_cookie("CC_Msg");
 var IsOK;

 if(cook.toUpperCase()=="NO")
	IsOK=1;
 else
	IsOK=window.showModalDialog("../../netutils/excel/excelwarning.aspx","", "dialogWidth:600px; dialogHeight:320px; status:no; center:yes; scroll:no; help:no; resizable:yes");

	if(IsOK==1)
	window.location.href = url;
}

function fn_get_cookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return "";
}

function fn_show_ask(val)
{
	switch(val.toString())
	{
		case '0':	//	No/Time's up
			window.location.href = "../../../zone/logout.asp";
			break;
		case '1':	//	Yes
			window.location.reload(true);
			break;
		case '2':	//	X	(continue till time's up)
			return;
		default:
			return;
	}	
}

function fn_trim(st)
{
	return st.replace(/ /g, '');
}

function fn_open_declaration(base)
{
// TODO: ASPX
	var w=window.open(base + 'trade/inc/cover_declaration.asp?', 'declaration','left=0px,top=0px,width=500px,height=248px,resizable =1');	
	//var w=window.open(/LTIASP/trade/inc/cover_declaration.asp?', 'declaration','left=0px,top=0px,width=500px,height=248px,resizable =1');	
	
	w.focus();
}

function fn_help(key)
{
	var w=window.open("../../utils/redirect/dirhelp.aspx?type=2&key=" + key + "&", "itemhelp", "left=0,top=0,width=500,height=200,resizable=yes,scrollbars=yes"); 
	w.focus();
}
	
function fn_helpforpage(key)
{
	var w=window.open("../../utils/redirect/dirhelp.aspx?type=1&key=" + key + "&", "pagehelp", "left=0,top=0,width=762,height=602,resizable=yes,scrollbars=yes"); 
	w.focus();
}

function open_graph_compare(url,id, period)
{
	var str = url + "info/graph/graphcompare.asp?pid=" + id + "&pdb_cbo_prd=" + period + "&";
	window.open(str, 'graph_comp', 'top=0,left=0,width=700,height=600,status=0,scrollbars=1');
}
// TODO: remove function
function show(id, url)
{
	var str = url + "info/stock/stockdetails.asp?group=14000&menu=maof&item=mf_dt&inp_pid=" + id + "&";
	window.location.href = str;
}

function fn_popup(key)
{
	var src="../../utils/redirect/dirlink.aspx?key=" + key + "&type=4&";
	
	if(arguments.length>1)
	{
		for(var i=1; i<arguments.length; i++)
		{
			src+="p" + (i-1) + "=" + arguments[i] + "&";
		}
	}
	fn_jscript(src);	
}

function fn_link(key)
{
	var src="../../utils/redirect/dirlink.aspx?key=" + key + "&type=1&";
	fn_jscript(src);	
}

function fn_jscript(src)
{
	var j = document.createElement("script");
	j.type = "text/javascript";
	j.name="js" + Math.random();
	j.src=src;
	document.body.insertBefore(j, null);		
}

function fn_opentradeinfo(id, type)
{	
	if (window.screen.availHeight<=600)	
		window.open('../../../trade/ppr/addinfo.asp?inp_pid=' + id + '&inp_tid=' + type + '&', 'trade_info','top=0,left=0,width=365,height=510,scrollbars=yes,resizable=yes');
	else
		window.open('../../../trade/ppr/addinfo.asp?inp_pid=' + id + '&inp_tid=' + type + '&', 'trade_info','top=0,left=0,width=365,height=660,scrollbars=yes,resizable=yes');
}

function fn_openmaoftradeinfo(id,type)
{
	if (window.screen.availHeight<=600)	
		window.open('../../trade/maof/MaofAddInfo.aspx?inp_pid=' + id + '&inp_tid=' + type + '&', 'trade_info','top=0,left=0,width=365,height=510,scrollbars=yes,resizable=yes');
	else
		window.open('../../trade/maof/MaofAddInfo.aspx?inp_pid=' + id + '&inp_tid=' + type + '&', 'trade_info','top=0,left=0,width=365,height=660,scrollbars=yes,resizable=yes');
}
	
function fn_map_local(url)
{
	fn_map(url);
}

function getInternetExplorerVersion()
{
	var rv = -1;
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		var ua = navigator.userAgent;
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if(re.exec(ua)!=null)
			rv = parseFloat(RegExp.$1);
	}
	return rv;
}

function fn_identifybrowser()
{
	var browser = window.navigator.appName.toUpperCase();
		
	if(browser)
	{
		if(browser.indexOf("MICROSOFT") != -1)
			return "ie";
		if(browser.indexOf("NETSCAPE") != -1)
			return "dom";
	}
}

function fn_getxmlhttp()
{
	var browser=fn_identifybrowser();
	
	try	
	{
		switch(browser)
		{
			case "ie":
				return new ActiveXObject("Microsoft.XmlHttp");
				break;
				
			case "dom":
				return new XMLHttpRequest();
				break;
				
			default:
				return null;
		}
	}
	catch(e)
	{ 
		window.status=e.description;
		return null;
	}
}

function fn_gettimestamp()
{
	var d = new Date();
	return d.getHours() + "_" + d.getMinutes() + "_" + d.getSeconds() + "_" + d.getMilliseconds();
}

function fn_getasyncdata(method, url, params, callback)
{
	try	
	{
		var oHttp=fn_getxmlhttp();
		
		if (oHttp != null)
		{
			oHttp.onreadystatechange=function(){fn_checkresponse(oHttp, callback);};
			oHttp.open(method.toUpperCase(), url, true);
			
			if(method.toUpperCase()=="POST")
			{
				oHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				
			}
			oHttp.setRequestHeader("CharSet","windows-1255");
			oHttp.send(params);
		}
	}
	catch(e)
	{ 
		window.status=e.description;
	}
}

function fn_checkresponse(oHttp, callback)
{
	if(oHttp.readyState==4)
	{
		window.status=oHttp.statusText;
		
		//try
		{
			if(oHttp.status  == 200)
				eval(callback + "(oHttp)");
			else
			{
				//var w=window.open("", "_blank");
				//w.document.write(oHttp.responseText);
			}
		}
		//catch(e)
		//{
		//	window.status=e.description;
		//}	
	}
}

function fn_posneg(val)
{
	if(parseFloat(val)>0) return "positive";
	if(parseFloat(val)<0) return "negative";
	return "netrual";
}

function GetHtmlData(url, div, addFormValues)
{
	var e = document.getElementById("frmMain").elements;
	var browser;
	var error = "";
	
	var oHttp=null;


	if (addFormValues)
	{
		// check '?' and '&' in url
		if(url.indexOf("?")==-1)
			url+="?";
		else
			if(url.indexOf("&", url.length-1)==-1) url+="&";

		for(var i=0; i<e.length; i++) url+=(e[i].name + "=" + e[i].value + "&");
	}
	else
	{
		// if parameters were passed
		if(url.indexOf("?") != -1)
			{
				// just add & for url 
				if(url.indexOf("&", url.length-1)==-1) url+="&";
			}
	}
	

	try
	{
		oHttp = fn_getxmlhttp();
		
		if (oHttp != null)
		{
			oHttp.onreadystatechange=function(){CheckResponse(oHttp, div);};
			oHttp.open("GET",url, true);
			oHttp.send(null);
		}
		else
		{
			alert("Your browser doen't support XMLHTTP.")
		}
	}
	catch(e)
	{ 
	error = e.description;
	window.status='הגדרות הדפדפן לא מתאימות לדרישות האתר, אנא פנה למוקד';
	}
}
			
function CheckResponse(oHttp, oDiv)
{
	var error = "";
	var browser=fn_identifybrowser();
	
	if(oHttp.readyState==4)
	{
		window.status=oHttp.statusText;
		try
		{
			if(oHttp.status  == 200)
			{
				UpdateDivByXmlHttpResults(oHttp,oDiv);
			
			// on send after event
			if (document.getElementById("oDivXmlHttp"))
			{
				var onsendafter;
				if (browser.toLowerCase()=="ie")
					onsendafter = document.getElementById("oDivXmlHttp").onsendafter;
			
				if (browser == "dom")
				onsendafter = document.getElementById("oDivXmlHttp").attributes["onsendafter"].value;
				
				if(onsendafter)
					eval(onsendafter + "()");
			}
		}
			else
			{
				var w=window.open("", "_blank");
				w.document.write(oHttp.responseText);
			}
		}
		catch(e)
		{
			window.status='הגדרות הדפדפן לא מתאימות לדרישות האתר, אנא פנה למוקד';
			error = e.description;
		}
			
	}
}
		
		
function UpdateDivByXmlHttpResults(oHttp, oDiv)
{
	var parser;
	var respText;
	var doc;
	var browser=fn_identifybrowser();
		
	// IE 
	respText = oHttp.responseText.replace(/[\n\r\t]/g,"");
	respText =  "<?xml version='1.0' encoding='windows-1255'?>"+
				"<htmlsections>" +
				"<htmlsection><![CDATA[" + 
				respText + 
				"]]>" +
				"</htmlsection>" +
				"</htmlsections>";
			
	if (browser.toLowerCase() == "ie")
	{
		doc = new ActiveXObject("Microsoft.XMLDOM");
		doc.async = "false";
		doc.loadXML(respText);
	}
						
	if(browser == "dom")
	{
		parser  = new DOMParser();
		doc = parser.parseFromString(respText,"text/xml");
	}
	
	var docElem = doc.documentElement;
	if (docElem != null)
	{
		if (docElem.childNodes[0] != null)
		{
			if (docElem.childNodes[0].childNodes[0] != null)
			{
				if (oDiv && docElem.childNodes[0].childNodes[0].nodeValue != null )
				oDiv.innerHTML = docElem.childNodes[0].childNodes[0].nodeValue;
			}
		}
	}			
}
	
// function added for Mozilla compatibility
// 16/04/2007	
modalWin = null;
function xShowModalDialog( sURL, vArguments, sFeatures ) 
    { 
    if (sURL==null||sURL=='') 
    { 
        alert ("Invalid URL input."); 
        return false; 
    } 
    if (vArguments==null||vArguments=='') 
    { 
        vArguments=''; 
    } 
    if (sFeatures==null||sFeatures=='') 
    { 
        sFeatures=dFeatures; 
    } 
    
    sFeatures = sFeatures.replace(/ /gi,''); 
    aFeatures = sFeatures.split(";"); 
    sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,"; 
    
    for ( x in aFeatures ) 
    { 
        aTmp = aFeatures[x].split(":"); 
        sKey = aTmp[0].toLowerCase(); 
        sVal = aTmp[1]; 
        switch (sKey) 
        { 
            case "dialogheight": 
                sWinFeat += "height="+sVal+","; 
                pHeight = sVal; 
                break; 
            case "dialogwidth": 
                sWinFeat += "width="+sVal+","; 
                pWidth = sVal; 
                break; 
            case "dialogtop": 
                sWinFeat += "screenY="+sVal+","; 
                break; 
            case "dialogleft": 
                sWinFeat += "screenX="+sVal+","; 
                break; 
            case "resizable": 
                sWinFeat += "resizable="+sVal+","; 
                break; 
            case "status": 
                sWinFeat += "status="+sVal+","; 
                break; 
            case "center": 
                if ( sVal.toLowerCase() == "yes" ) 
                { 
                    sWinFeat += "screenY="+((screen.availHeight-pHeight)/2)+","; 
                    sWinFeat += "screenX="+((screen.availWidth-pWidth)/2)+","; 
                } 
                break; 
        } 
    } 
    modalWin=window.open(String(sURL),"",sWinFeat); 
    if (vArguments!=null&&vArguments!='') 
    { 
        modalWin.dialogArguments=vArguments; 
    } 
 }
 
 // Function added  for Mozilla use
// 16/04/2007
function checkFocus() 
{ 
    if(window.focus)
    {
		if (modalWin!=null)
		{
			if (!modalWin.closed) 
			{ 
				self.blur(); 
				try
				{
					modalWin.focus(); 
				}
				catch(e)
				{
				}
			}
		}
	} 
} 

function fn_isnumeric(value)
{
	if(!value)return false;
	// I use this function like this: if (isNumeric(myVar)) { } 
	// regular expression that validates a value is numeric 
	var RegExp = /^[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?$/; 
	// compare the argument to the RegEx 
	// the 'match' function returns 0 if the value didn't match 
	var result = value.match(RegExp);
	if ((!result) ||(!result[0]))
		return false;
	else
		return result[0]!= "0";
}

function fn_cboonchange(cbo)
{
	if(cbo.issend==1 || cbo.issend==null)
	{
		if(cbo.onchangeaction)
			eval(cbo.onchangeaction);
		else
			eval(cbo.value);
			
		if(cbo.isreset) cbo.options[0].selected=true;
	}
	else
		cbo.issend=1;
}

function fn_cbokeypressed(cbo)
{
	if(event.keyCode==13)
	{
		cbo.issend=1;
		fn_cboonchange(cbo);
	}
	else
		cbo.issend=0;
}

function fn_get(id)
{
	return document.getElementById(id);
}

function fn_checkinteger(event, oTxt)
{
 var browser = fn_identifybrowser();
 var KeyCode;
 var unsigned;

	switch(browser)
	{
	case "ie":
		KeyCode=event.keyCode;
		unsigned = oTxt.unsigned;
		break;

	case "dom":
		KeyCode = event.charCode;
		if (KeyCode == 0) KeyCode = event.keyCode;
		unsigned = oTxt.attributes["unsigned"].nodeValue;
		break;
	}
	
	//Don't change order of the if operators !!!!
	//delete or backspace pressed
	if(KeyCode==8) return;
		
	//prevet zero on the first position									
	if(KeyCode==48 && (oTxt.value=='' || oTxt.value=='-')) 
	{
		switch(browser)
		{
		case "ie":
			event.returnValue=false;
			return;
		
		case "dom":
			event.preventDefault();
			return;
		}
	}
		
	if((unsigned + '').toLowerCase()=='true' && KeyCode==45)
	{
		switch(browser)
		{
		case "ie":
			event.keyCode=0;
			return;

		case "dom":
			event.preventDefault();
			event.stopPropagation();
			return;
		}
	}
	else
	{
		//prevent minus on the middle place and more than one minus
		if((oTxt.value!='' || oTxt.value.indexOf('-',0)!=-1) && KeyCode==45)
		{
			switch (browser)
			{
			case "ie":
				event.keyCode=0;
				return;
				
			case "dom":
				event.preventDefault();
				event.stopPropagation();
				return;
			}
		}
	}
		
	//prevent non-numeric symbols
	if((KeyCode<48 || KeyCode >57) && KeyCode !=45)
	{
		switch (browser)
		{
		case "ie":
			event.returnValue=false;
			return;
			
		
		case "dom":
			event.preventDefault();
			return;
		}
	}
}
	
function fn_checkpasteinteger(event,evtElement)
{
	var CBData=window.clipboardData.getData("Text");
	var unsigned;
	var browser = fn_identifybrowser();
	
	switch(browser)
	{
	case "ie":
		unsigned = evtElement.unsigned;
		break;

	case "dom":
		unsigned = evtElement.attributes["unsigned"].nodeValue;
		break;
	}
	 
	if(!parseFloat(CBData) || CBData.length > this.maxLength)
	{
		window.clipboardData.clearData("Text");
		return;
	}

	var val=Math.round(CBData);
	
	if ((unsigned + '').toLowerCase()=='true' && isNaN(val))
	{
		window.clipboardData.clearData("Text");
		return
	}
	
	if((unsigned + '').toLowerCase()=='true' && val<0)
		window.clipboardData.clearData("Text");
	//else
		//window.clipboardData.setData("Text", val.toString());	
}

function fn_checkfloat(event, oTxt)
{
	var browser = fn_identifybrowser();
	var KeyCode;
	var unsigned;

	switch(browser)
	{
	case "ie":
		KeyCode=event.keyCode;
		unsigned = oTxt.unsigned;
		break;

	case "dom":
		KeyCode = event.charCode;
		if (KeyCode == 0) KeyCode = event.keyCode;
		unsigned = oTxt.attributes["unsigned"].nodeValue;
		break;
	}
	

	//Don't change order of the if operators !!!!

	//delete or backspace pressed
	if(KeyCode==8) return;									
	
	//prevent number of zero before point
	if((oTxt.value=='0' || oTxt.value=='-0') && KeyCode!=46)
	{
		event.keyCode=0;
		return;
	}
	
	//prevent point on the first place and more than one point
	if((oTxt.value=='' || oTxt.value.indexOf('.',0)!=-1) && KeyCode==46)
	{
		event.keyCode=0;
		return;
	}

	if((unsigned + '').toLowerCase()=='true' && KeyCode==45)
	{
		event.keyCode=0;
		return;
	}
	else
	{
		//prevent minus on the middle place and more than one minus
		if((oTxt.value!='' || oTxt.value.indexOf('-',0)!=-1) && KeyCode==45)
		{
			event.keyCode=0;
			return;
		}
	}
	
	//prevent non-numeric symbols
	if((KeyCode<48 || KeyCode >57) && KeyCode !=46 && KeyCode !=45)
	{
		event.keyCode=0;
		return;
	}
}

function fn_checkpastefloat(event, evtElement)
{
	var CBData=window.clipboardData.getData("Text");
	var unsigned;
	var browser = fn_identifybrowser();
	
	switch(browser)
	{
	case "ie":
		unsigned = evtElement.unsigned;
		break;

	case "dom":
		unsigned = evtElement.attributes["unsigned"].nodeValue;
		break;
	}
	
	if(!parseFloat(CBData) || CBData.length>9)
		window.clipboardData.clearData("Text");
	//else
		//window.clipboardData.setData("Text", parseFloat(CBData).toString());
}
	
function fn_search_main(str, RegionID)
{
	if(fn_checksearch(str))
	{
		var result = fn_search_encode(str);
		fn_jscript('../../utils/searchengine.ashx?txt=' + result + "&rid=" + RegionID + "&");
	}
	else
		return false;
}

function fn_asproot()
{
	return "../../../";
}

function fn_netroot()
{
	return "../../";
}

var var_stock_func="fn_stock";
var var_open_search_result="fn_open_searchresult";

function setPaperData(pid, cmd)
{

}
function fn_trade_new(pid,cmd)
{	
	if(cmd==null)
	{
		if(window.event.offsetX >15)
			cmd=1;
		else
			cmd=2;
	}
		
	window.location.href="../../../utils/redirect/dirtrade.asp?pid=" + pid + "&cmd=" + cmd + "&";
}
	
//region for trade
function ShowFltr(win)
{
	SetCntrVis("hidden",document.getElementsByTagName("select"));
	SetCntrVis("hidden",window.parent.document.getElementsByTagName("select"));
	var d = win.document.getElementById("FltrDiv");
	if(d) return;
	d = win.document.createElement("div");
	d.id = "FltrDiv";
	var h = win.document.body.scrollHeight;
	//if(h < win.screen.height) h = win.screen.height;
	
	d.style.height = h + "px";
	d.className = "fltr";
	var i = win.document.createElement("img");
	i.src = "../../images/btn_buysell/progressbar.gif";
	i.id = "PrgImg";
	i.className = "IgnoreScroll";
	i.attachEvent("onclick",CancelProgress);
	with(i.style)
	{
		cursor = "pointer";
		zIndex = "101";
		position = "absolute";
		width = "120px";
		height = "22px";
		left = (win.screen.width / 2 - parseInt(width) / 2) + "px";
	}
	win.document.body.appendChild(d);
	win.document.body.appendChild(i);
	
	//win.document.body.scroll = "no";
}

function HideFltr(win)
{	
	SetCntrVis("",document.getElementsByTagName("select"));
	SetCntrVis("",window.parent.document.getElementsByTagName("select"));
	var d = win.document.getElementById("FltrDiv");
	if(d) d.outerHTML = "";
	win.document.body.scroll = "yes";
	HidePrgImg(win);
}

function CancelProgress()
{
	top.location.href = top.location.href;
}

function HidePrgImg(win)
{
	if(!win) win = top;
	var i = win.document.getElementById("PrgImg");
	if(i) i.outerHTML = "";
}

function SetIfrSz(win,IfrId,ElId)
{		
	var d = win.document.getElementById(IfrId);
	var r = document.getElementById(ElId);
	if(!d || !r) return;
	r = r.getBoundingClientRect();
	var w = r.right - r.left;
	var h = r.bottom - r.top;
	with(d.style)
	{
		width = w + "px";
		height = h + "px"
		left = (win.screen.width / 2 - w / 2) + "px";
		top = win.document.body.scrollTop + 30 + "px";
	}
}

function SetCntrVis(val,ar)
{
	if(!ar) ar = document.getElementsByTagName("select");
	for(var i = 0;i < ar.length;i++)
		ar[i].style.visibility = val;
}

function GetAlertAsync(oHttp)
{
	if(typeof(oHttp) == "string")
	{
		GetAlertIframe(oHttp);
		return;
	}
	var w = window.parent;
	if(w.document.getElementById("ermsg")) return;
	var oRs = new ActiveXObject("Adodb.Recordset");
	oRs.Fields.Append("he", 200, 100000);
	oRs.Open();
	oRs.AddNew();
	oRs(0).AppendChunk(oHttp.responseBody);
	var d = w.document.createElement("div");
	d.id = "ermsg";
	d.innerHTML = oRs(0);
	d.style.position = "absolute";
	d.style.zIndex = 1001;
	d.className = "IgnoreScroll";
//	d.style.top = (w.screen.height + w.document.body.scrollTop) / 2;
	d.style.left = (w.screen.width - 250) / 2;
	w.document.body.appendChild(d);
	HidePrgImg();
}

function GetAlertIframe(url)
{
	if(top.document.getElementById("ermsg")) return;
	var d = top.document.createElement("div");
	d.id = "ermsg";
	d.style.position = "absolute";
	d.style.zIndex = 1001;
	d.className = "IgnoreScroll";
	d.style.left = (top.screen.width - 250) / 2;
	var ifr = top.document.createElement("iframe");
	ifr.setAttribute("frameBorder","0");
	ifr.setAttribute("scrolling","no");
	url += "ifr=1&";
	ifr.setAttribute("src",url);
	ifr.setAttribute("id","errifr");
	d.appendChild(ifr);
	top.document.body.appendChild(d);
	HidePrgImg();	
}

function GetHorizCenter(el)
{
	var r = el.getBoundingClientRect();
	var w = r.right - r.left;
	return (screen.width - w) / 2;
}

//end region for trade
