function showWin(opt,site)
{	
        $.ajax(
        {
		url: 'http://www.cxotoday.com/cxo/jsp/displayLayer.jsp?opt='+opt+'&site='+site+'&tm='+new Date().getTime(),
	        error: function()
                {
                        alert('Error : please try again  ');
                },
                success: function(data)
                {
			if (opt.indexOf('Profile') != -1)
			{
				$('div#dvTopCFish2').html(data).hide().slideDown('slow');
			}
			else
			{
				$('div#dvlogon').html(data).css(
				{
					display:'none',	left:530, top:145, position:'absolute'
				}).slideDown('slow');
			}
                }
        });
}
function closeTopWin(id)
{
        if(document.getElementById(id))
        {
                $("#"+id).slideUp('slow');
        }
}
function invokeLogout()
{
        $("#dvWithLogin").hide();
        $("#dvWithLogout").show();
}


function invokeLogin()
{
        $.get(mainUrlRg + "xyz.jsp?tm=" + new Date().getTime(),{},function(data)
        {});

        $("#dvWithLogout").hide();
        $("#dvWithLogin").show();

//      document.getElementById("dvregister").style.display="none";
}
function validate()
{
	Username = document.formId1.userName.value;
	Password = document.formId1.password.value;

	if (!chkSpaces(Username))
	{
		hideAllErrors();
		document.getElementById("unameError").style.display = "inline";
		document.formId1.userName.value = "";
		document.formId1.userName.focus();
		return false;
	}
	if (document.formId1.userName.value.length < 3 )
	{
		hideAllErrors();
		document.getElementById("unameError").style.display = "inline";
		document.formId1.userName.value = "";
		document.formId1.userName.focus();
		return false;
	}
	if (!specialChar(document.formId1.userName.value))
	{
		hideAllErrors();
		document.getElementById("unameError").style.display = "inline";
        	document.formId1.userName.value = "";
	        document.formId1.userName.focus();
	        return false;
	}
	if (!chkSpaces(Password))
	{
		hideAllErrors();
		document.getElementById("pwdError").style.display = "inline";
		document.formId1.password.value = "";
		document.formId1.password.focus();
		return false;
	}
	if(document.formId1.password.value.length < 4 )
	{
		hideAllErrors();
		document.getElementById("pwdError").style.display = "inline";
		document.formId1.password.value = "";
		document.formId1.password.focus();
		return false;
	}
	if (!specialChar(document.formId1.password.value))
	{
		hideAllErrors();
		document.getElementById("pwdError").style.display = "inline";
		document.formId1.password.value = "";
		document.formId1.password.focus();
		return false;
	}
	return true;
}
function trim(s) 
{
	while (s.substring(0,1) == ' ') 
	{
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') 
	{
		s = s.substring(0,s.length-1);
	}
	return s;
}

function hideAllErrors() 
{
	document.getElementById("unameError").style.display = "none"
	document.getElementById("pwdError").style.display = "none"
}


var req =false;
var tag_name="";

function submitForm1(tag_obj)
{
	var userName=document.getElementById("userName");
	var password=document.getElementById("password");

	if (!chkSpaces(userName.value))
	{
		hideAllErrors();
		document.getElementById("unameError").style.display = "inline";
		userName.value="";
		userName.focus();
		return false;
	}
	if (!specialChar(userName.value))
	{
		hideAllErrors();
		document.getElementById("unameError").style.display = "inline";
        	userName.value="";
		userName.focus();
	        return false;
	}
	if (!chkSpaces(password.value))
	{
		hideAllErrors();
		document.getElementById("pwdError").style.display = "inline";
		password.value="";
		password.focus();
		return false;
	}
	if (!specialChar(password.value))
	{
		hideAllErrors();
		document.getElementById("pwdError").style.display = "inline";
		password.value="";
		password.focus();
		return false;
	}
	hideAllErrors();
	
	tag_name =tag_obj;
	url="http://www.cxotoday.com/cxo/jsp/login/validateLogin.jsp?userName="+userName.value+"&password="+password.value;
	
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open('GET', url + '', true);
		req.send(null);
		// branch for IE/Windows ActiveX version
	}
	else if (window.ActiveXObject)
	{
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req)
		{
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}
// handle onreadystatechange event of req object
function processReqChange()
{
	// only if req shows "loaded"
	if (req.readyState == 4)
	{
		// only if "OK"
		if (req.status == 200)
		{
			document.getElementById(tag_name).style.display="block";
			document.getElementById(tag_name).innerHTML=req.responseText;
			//document.getElementById("dvWithLogin").style.display="none";
			//document.getElementById("dvWithLogout").style.display="block";
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}

