var iTimeout;
var iTimeoutInterval;

document.__ValJsLoaded = true;
function createReqObj(){
	var C=null;
	try 
	{
		C = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			C = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(sc)
		{
			C = null;
		}
	}
	if (!C && typeof XMLHttpRequest != "undefined"){
		C=new XMLHttpRequest();
	}
	return C;
}

function LoadUsingXMLHttpRequest(url)
{
	responseText = true;
	try {
  	var oXmlRequest ;
  	
  	oXmlRequest = createReqObj() ;
  	if (oXmlRequest == null) return false;

  	oXmlRequest.open( "GET", url, true) ;
  	oXmlRequest.send( null ) ;
  	
  	oXmlRequest.onreadystatechange = function () {
  		if (oXmlRequest.readyState == 4) eval(oXmlRequest.responseText);
  	}
  	return true;
  }catch(e) {
  	//alert('error loading using xmlhttprequest:'+e.toString());
  	result = false;
  }
  return result;
}

function LoadUsingJsHttpRequest(url) 
{
	result = true;
	try {
		with (document) {
			var e = createElement("script");
			e.type = "text/javascript";
			e.src = url;
			body.appendChild(e);
		}
	}catch(e) {	
		result = false;
	}
	return result;
}
function printTimeOut() {
	iTimeout--;
	if (iTimeout == 0) {
		window.clearInterval(iTimeoutInterval);
		document.getElementById('OSScLoginForm').submit();
	}
	if (null != (	doc_login_error = document.getElementById('login_error'))) {
		doc_login_error.innerHTML += "<b>.</b>";	
	}
}

function onLoadDone() {
	window.clearInterval(iTimeoutInterval);
}

function ValidateLoginEx() {
	return ValidateLogin();
}

function ValidateLogin(){
 	iTimeout = 10;
 	iTimeoutInterval = window.setInterval("printTimeOut()",1000);

	if (null != (	doc_login_error = document.getElementById('login_error'))) {
		doc_login_error.innerHTML = "<b>Checking login, please wait.. </b>";
	}
	if (null != (doc_login_button = document.getElementById('LoginButton'))) {
		doc_login_button.disabled = true;
	}
 	_username = escape(document.getElementById('f_username').value).replace(new RegExp('\\+','g'), '%2B');
	_password = escape(document.getElementById('f_password').value).replace(new RegExp('\\+','g'), '%2B');
	
	host = document.location.host;
 	//href = "http://"+host+"/oss_forms/users/login.php?ce=0&clogin=1&group=-1&FormID=1&username="+_username+"&password="+_password+"&method=jshttp&rand="+Math.random();
 	href = "http://www.insight-trader.com/oss5/users/login.php?ce=0&group=-1&FormID=1&clogin=1&username="+_username+"&password="+_password+"&method=jshttp&rand="+Math.random();
  result = LoadUsingXMLHttpRequest(href);
  if (result == false) result = LoadUsingJsHttpRequest(href);
  return !result;
}

function popUp(URL)
{
	window.open(URL,10, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=270,height=62,left ='+((screen.width-270)/2)+',top ='+((screen.height-100)/2));
}
