
var requestLoginVerfiy;
var requestLoginVerfiy1;

function getRequestOBJ() {
	if (window.ActiveXObject) {
		return(new ActiveXObject("Microsoft.XMLHTTP"));
			} else if (window.XMLHttpRequest) {
				return(new XMLHttpRequest());
			} else {
	return(null);
	}
}
function getRequestLoginSession(sendURL,profileIDparameter,message1) {
       globalprofileidurl=profileIDparameter;
       requestLoginVerfiy1="";
       if (window.XMLHttpRequest){     // Object of the current windows
    requestLoginVerfiy1=new XMLHttpRequest();
   } 
   else if (window.ActiveXObject){   // ActiveX version
    requestLoginVerfiy1=   new ActiveXObject("Microsoft.XMLHTTP");//cj month//viewer choice//dedate (skype)
    }
    
		//requestLoginVerfiy1 = getRequestOBJ();
		pathtopopup=sendURL;
        globalmess=message1;
		
		
		requestLoginVerfiy1.open("POST", "/loginCheckAJAX.do", true);
		requestLoginVerfiy1.onreadystatechange = showchecklog;
		requestLoginVerfiy1.setRequestHeader("Connection", "close");
	    requestLoginVerfiy1.send(null);
	    //alert('k');
}
function showchecklog() {	    
	 if ((requestLoginVerfiy1.readyState == 4) && (requestLoginVerfiy1.status == 200)) {
            var responseText = requestLoginVerfiy1.responseText;
             popupalreadyShownLog=false;
             //alert(responseText);
             if (responseText!='true'){
                  showLoginBox();
             }else if (responseText=='true' && globalmess=='redirecttonewpage'){
               window.location=pathtopopup;
             }else{
          showdarklayer11();
          
                if (window.XMLHttpRequest){     // Object of the current windows
    requestMypagePopups=new XMLHttpRequest();
   } 
   else if (window.ActiveXObject){   // ActiveX version
    requestMypagePopups=   new ActiveXObject("Microsoft.XMLHTTP");//cj month//viewer choice//dedate (skype)
    }
      	   //requestMypagePopups = getRequestObjectPopUPs();
		//alert(pathtopopup);
		requestMypagePopups.open("POST", pathtopopup, true);
		requestMypagePopups.onreadystatechange = showMYPOPUPLL;
		requestMypagePopups.setRequestHeader("Connection", "close");
	    requestMypagePopups.send(null);
             }
             //return responseText;
     } 

}
function showMYPOPUPLL() {
	if ((requestMypagePopups.readyState == 4) && (requestMypagePopups.status == 200)) {
       
	var responseText = requestMypagePopups.responseText;
	
	//alert(responseText);
    var newdivMY=document.createElement("div");
    newdivMY.className="vclass";
    newdivMY.id="showPOPUPLAYER";
    newdivMY.innerHTML=responseText;
    document.getElementById("addPOPUPHERE").appendChild(newdivMY);
    popupalreadyShown=true;
    center_box(document.getElementById("addPOPUPHERE"),100,100);
} 
}
var has_inner = typeof(window.innerWidth) == 'number';  
var has_element = document.documentElement  
     && document.documentElement.clientWidth;  
 function center_box(box, width, height)  
 {  
     cleft = has_inner  
         ? pageXOffset +   
           (window.innerWidth - width)/2  
         : has_element  
           ? document.documentElement.scrollLeft +   
             (document.documentElement.clientWidth - width)/2  
           : document.body.scrollLeft +   
             (document.body.clientWidth - width)/2;  
   
     ctop = has_inner  
         ? pageYOffset + (window.innerHeight - height)/2  
         : has_element  
           ? document.documentElement.scrollTop +   
             (document.documentElement.clientHeight - height)/2  
           : document.body.scrollTop +   
             (document.body.clientHeight - height)/2;  
   
     cleft=cleft-150;
     ctop=ctop-170;
     box.style.left = cleft > 0 ? cleft + 'px' : '0px';  
     box.style.top = ctop > 0 ? ctop + 'px' : '0px';  
 }
	



function validate()
{
 if(removeAllSpaces(document.form1.userID.value)=="")
 {
  alert("Please enter your User Name");
  document.form1.userID.focus();
  return false;
 }
 if(removeAllSpaces(document.form1.password.value)=="")
 {
  alert("Please enter your password");
  document.form1.password.focus();
  return false;
 }
checkLoginData();
 
}
function removeAllSpaces(str)
{
   str = removeLeadingSpaces(str); //Remove Leading Spaces
   str = removeTrailingSpaces(str); //Remove Trailing Spaces
   return str;
}
// This method is used to remove Leading spaces.
// It takes argument of the string which Leading Spaces has to removed.
function removeLeadingSpaces(str)
{
   var whitespace = new String(" \\t\\n\\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1)
    {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)  j++;
      s = s.substring(j, i);
    }
   return s;
}
//######################################################################################################
// This method is used to remove Trailing spaces.
// It takes argument of the string which Trailing Spaces has to removed.
function removeTrailingSpaces(str)
{
   var whitespace = new String(" \\t\\n\\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
   {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;
      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }
   return s;
}
//######################################################################################################
//send data login
function checkLoginData(){

       if (window.XMLHttpRequest){     // Object of the current windows
    requestLoginVerfiy=new XMLHttpRequest();
   } 
   else if (window.ActiveXObject){   // ActiveX version
    requestLoginVerfiy=   new ActiveXObject("Microsoft.XMLHTTP");//cj month//viewer choice//dedate (skype)
    }

//requestLoginVerfiy = getRequestOBJ();

 var formdata22="userID="+encodeURI( document.getElementById("userID").value );
      formdata22=formdata22+"&password="+encodeURI( document.getElementById("password").value );
      formdata22=formdata22+"&profileID="+encodeURI( document.getElementById("profileID").value );
 
		requestLoginVerfiy.open("GET", "/newLogin.do?Method=LoginExistingUserMypage&"+formdata22, true);
 		requestLoginVerfiy.onreadystatechange = isDetailvalid;
 		requestLoginVerfiy.setRequestHeader("Connection", "close");
	    requestLoginVerfiy.send(null);
	    
	    //isDetailvalid();

}


function isDetailvalid(){
	if ((requesthere.readyState == 4) && (requesthere.status == 200)) {

             var responseText = requesthere.responseText;
             //alert(responseText);
             if(responseText=='false'){
              alert('Invalid username/ password');
              
              return false;
              }
              else{
             // window.location=responseText;
              //alert('j');
              
             var  location1=location+"";
             var pen1=location1.split("?");
             if (pen1.length>1){
             window.location=location.pathname+"?"+pen1[1];
             //alert(location.pathname+"?"+pen1[1]);
             }else {
             window.location=location.pathname;
             //alert(location.pathname);
             }
             //alert(window.location);
            //  window.location.reload(true);
              //hidePOPUPLAYER();
              //document.getElementById("signinsignout").innerHTML="<div class='top-right-icon2' ><a href='#' onclick='showLogout()' class='horos1' >Sign out</a></div>";
            
              }
              
           }
             
    
}


/*
function isDetailvalid() {
	if ((requestLoginVerfiy.readyState == 4) && (requestLoginVerfiy.status == 200)) {

            var responseText = requestLoginVerfiy.responseText;
             //alert(responseText.substring(0,3));
            if (responseText=='true' && globalmess=='redirecttonewpage'){
            document.getElementById("signinsignout").innerHTML="<div class='top-right-icon2' ><a href='#' onclick='showLogout()' class='horos1' >Sign out</a></div>"
            verifiedLogin=true;
           window.location=pathtopopup;
            }else if(responseText=='true'){
            verifiedLogin=true;
            //alert('h');
            document.getElementById("signinsignout").innerHTML="<div class='top-right-icon2' ><a href='#' onclick='showLogout()' class='horos1' >Sign out</a></div>"
            getMyPagePopupDataAfterverify();
            }
           else if(responseText=='false'){
           alert('Invalid username/ password');
           }else if(responseText.substring(0,3)=='/cj'){
                    window.location=responseText;
           }
             return responseText;
   } 
}

*/
