﻿function fn_checkphone(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 minus on the first place
		if(oTxt.value=='' && 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_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()
	{
		try	
		{
			if (window.XMLHttpRequest)
				return new XMLHttpRequest();
	        
			if (window.ActiveXObject)
				return new ActiveXObject('Msxml2.XMLHTTP');
	     
			return new ActiveXObject('Microsoft.XMLHTTP');
		}
		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, errorfunc)
	{
		try	
		{
			var oHttp=fn_getxmlhttp();
			
			if (oHttp != null)
			{
				oHttp.onreadystatechange=function(){fn_checkresponse(oHttp, callback, errorfunc);};
				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.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
				oHttp.send(params);
			}
		}
		catch(e)
		{ 
			window.status=e.description;
		}
	}

	function fn_checkresponse(oHttp, callback, errorfunc)
	{
		if(oHttp.readyState==4)
		{
			window.status=oHttp.status + "-" + oHttp.statusText;
			
			try
			{
				if(oHttp.status  == 200)
					eval(callback + "(oHttp)");
				else
				{
					eval(errorfunc + "(oHttp)");
					//var w=window.open("", "_blank");
					//w.document.write(oHttp.responseText);
				}
			}
			catch(e)
			{
				window.status=oHttp.status + "-" + e.description;
			}	
		}
	}
    function fn_alert(title, message)
	{
		var w=document.getElementById("AlertWindow");
	    if(title!="") document.getElementById("MsgTitle").innerText=title;
	    document.getElementById("MsgText").innerHTML=message;
	    w.style.left=Math.round((window.screen.width-345)/2) + "px";
	    w.style.top=Math.round(window.screen.height/2-265) + "px";
	    w.style.visibility="visible";
	    var div=document.getElementById('div_mask');
	    div.style.width=document.body.scrollWidth; //window.screen.width;
	    div.style.height=document.body.scrollHeight; //window.screen.height;
	    div.style.display="inline";
	}
	
	function fn_closealert(id)
	{
		document.getElementById(id).style.visibility='hidden';
		document.getElementById('div_mask').style.display='none';
	}
	
	function fn_getnodetext(node)
	{
	    var browser = fn_identifybrowser();
	    
	    switch (browser)
		{
		case "ie":
			return node.text;
			
		case "dom":
			return node.textContent;
			
		default:
		    return "";
		}
	}
	
