﻿var xmlHttp= null;
        function $get(obj)
        {
            return document.getElementById(obj);
        }
        function getXMLHTTPRequest()
        {
	        var xRequest=null;
	        if (window.XMLHttpRequest)
	        {
		        xRequest = new XMLHttpRequest();
	        }
	        else if (typeof ActiveXObject != "undefined")
	        {
		        xRequest = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        return xRequest;
        }
        function ShowPopUp_Login()
{
    var statusPopUpDiv = document.getElementById('statusPopUpDiv');
    statusPopUpDiv.style.visibility = 'visible';
    statusPopUpDiv.style.position='absolute';
    statusPopUpDiv.style.top = _getScrollPositionY() + "px";
    statusPopUpDiv.style.left='40%';
    statusPopUpDiv.style.width='50%';
    statusPopUpDiv.style.zIndex='1001';
    
    var bgDisableDiv = document.getElementById('bgDisableDiv');
    bgDisableDiv.style.visibility = 'visible';
    bgDisableDiv.style.top='0px';
    bgDisableDiv.style.left='0px';
    bgDisableDiv.style.width=_getDocWidth(document) + 'px';
    bgDisableDiv.style.zIndex='1000';
    bgDisableDiv.style.height=_getDocHeight(document) + 'px'; 
    $get('UserName2TextBox').focus();
}
// top search.......
function TopSearch(IsAuthenticated)
{
    if($get('ctl00_UFindProfile1_SearchLastnameTextbox').value == '' || $get('ctl00_UFindProfile1_SearchLastnameTextbox').value == 'Enter name')
    {
        $get('requiredFieldValidator').style.display = 'block';
        return false;
    }
    else
    {
       return true;      
    }
}
function AnimationLoading() {

    var popUpGlobal = document.getElementById('popUpGlobal');
    popUpGlobal.style.display = "block";
    popUpGlobal.style.position='absolute';
    popUpGlobal.style.top = _getScrollPositionY() + "px"; 
    popUpGlobal.style.left='35%';
    popUpGlobal.style.width='30%';
    popUpGlobal.style.zIndex='1001';
    
    var popUpGlobalDisable = document.getElementById('popUpGlobalDisable');
    popUpGlobalDisable.style.display = "block";
    popUpGlobalDisable.style.top='0px';
    popUpGlobalDisable.style.left='0px';
    popUpGlobalDisable.style.width=_getDocWidth(document) + 'px';
    popUpGlobalDisable.style.zIndex='1000';
    popUpGlobalDisable.style.height=_getDocHeight(document) + 'px'; 
}
function AnimationAfterLoading()
{
    var popUpGlobal = document.getElementById('popUpGlobal');
    popUpGlobal.style.display = "none";
    var popUpGlobalDisable = document.getElementById('popUpGlobalDisable');
    popUpGlobalDisable.style.display = "none";
}
var WATERMARKCOLOR ;
function watermarkEnter(obj, wm) 
{
	if (obj.value == wm) 
	{
		obj.value = '';
		obj.style.color = '#000000';
	}
}
function watermarkLeave(obj, wm) 
{
	if (obj.value == '') 
	{
		obj.value = wm;
		obj.style.color = '#808080';
	}
}
function _getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}
function _getDocWidth(doc) {
  var docWt = 0, sw, ow;
  if (doc.width) docWt = doc.width;
  else if (doc.body) {
    if (doc.body.scrollWidth) docWt = sw = doc.body.scrollWidth;
    if (doc.body.offsetWidth) docWt = ow = doc.body.offsetWidth;
    if (sw && ow) docWt = Math.max(sw, ow);
  }
  return docWt;
}
function _getScrollPositionY() 
{
	var y = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		y = window.pageYOffset;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		y = document.documentElement.scrollTop;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		y = document.body.scrollTop;
	}
	return y + 200;
}
function _getScrollPositionY_Arg(len) 
{
	var y = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		y = window.pageYOffset;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		y = document.documentElement.scrollTop;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		y = document.body.scrollTop;
	}
	return y + len;
}
function CloseLoginDiv()
{
    $get('bgDisableDiv').style.visibility = 'hidden';
    $get('statusPopUpDiv').style.visibility = 'hidden';
    $get('statusPopUpDiv').style.top = '100px';
    $get('statusPopUpDiv').style.left = '100px';
    $get('errorDiv').style.display = 'none';
    $get('savingDiv').style.display = 'none';
    $get('statusDescriptionLabel').innerHTML = "";
    
}
    
function OnClickLogin() 
{  
    SetDefaultLoginCompletedCallBack();
    SetDefaultLogoutCompletedCallBack();
    SetDefaultFailedCallBack();

    Sys.Services.AuthenticationService.login($get('UserName2TextBox').value, 
    $get('Password2TextBox').value, false,null,null,null,null,"User Context");
}



function OnClickLogout () 
{       
        xmlHttp=getXMLHTTPRequest();
        xmlHttp.onreadystatechange = OnLogoutCompleted;
	    var URL="MyAuthenticationService.asmx/Logout?tm="+new Date().getTime();
	    var values= '{"v":"'+0+'"}';
		xmlHttp.open("POST",URL,true);
		xmlHttp.setRequestHeader ("Content-type", "application/json");
		xmlHttp.send(values);
}
      

function OnLogoutCompleted () 
{
    if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			 window.location = "Redirect.aspx?logout=croot";
		}
	}
} 

function ProcessLogin()
{
    xmlHttp=getXMLHTTPRequest();
    $get('bgDisableDiv').style.visibility = 'visible';
    $get('statusPopUpDiv').style.visibility = 'visible';
    $get('loginTable2').style.display = 'block';
    if(isValidLogin())
    {
        $get('errorDiv').style.display = 'block';
        $get('savingDiv').style.display = 'block';
        $get('statusDescriptionLabel').innerHTML ="validation in progress...";
        $get('loginTable2').style.display = 'none';
        xmlHttp.onreadystatechange = processResponse;
	    var URL="MyAuthenticationService.asmx/Login?tm="+new Date().getTime();
	    var values= '{"userName":"'+$get('UserName2TextBox').value+'","password":"'+$get('Password2TextBox').value+'","createPersistentCookie":"0"}';
		xmlHttp.open("POST",URL,true);
		xmlHttp.setRequestHeader ("Content-type", "application/json");
		xmlHttp.send(values);
    }
    else
    {
       $get('UserName2TextBox').style.display = 'block';
       $get('UserName2TextBox').focus();
       $get('UserName2TextBox').setFocus =true; 
    }
    return false;
}
function processResponse()
{
    
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
		    var data = eval('('+xmlHttp.responseText+')');
			if(data.d)
			{
                CloseLoginDiv();
			    window.location = "Redirect.aspx?userName=" + $get('UserName2TextBox').value +"&password="+$get('Password2TextBox').value;
			}
			else
			{
                $get('errorDiv').style.display = 'block';
                $get('savingDiv').style.display = 'none';
                $get('statusDescriptionLabel').innerHTML ="Login Credentials Invalid. Could not login.";
                $get('loginTable2').style.display = 'block';
            }
		}
	}
}   
function GoToControlPanel()
{
    xmlHttp=getXMLHTTPRequest();
    xmlHttp.onreadystatechange = OnLogoutCompleted;
    var URL="Home.asmx/ProcessUserRoles?tm="+new Date().getTime();
	xmlHttp.open("POST",URL,true);
	xmlHttp.setRequestHeader ("Content-type", "application/json");
	xmlHttp.send(null);
}
function OnSuccessGetUserRoles()
{
    if (xmlHttp.readyState == 4)
    {
	    if (xmlHttp.status == 200)
	    {
	        var data = eval('('+xmlHttp.responseText+')');
	        if(data.d == "N")
                window.location = "myportal";
            else
                window.location = data.d ;
	    }
    }	
        
}
function isValidLogin()
{
   var val1=$get('val1');
   var val2=$get('val2');
   val1.innerHTML = "";
   val2.innerHTML = "";
       var status = true;
       if($get('UserName2TextBox').value == "")
       {
            val1.innerHTML = "*";
            status = false;
       }
       if($get('Password2TextBox').value == "")
       {
            val2.innerHTML = "*";
            status = false;
       }
   return status;
}