﻿function bookmark(title, href)
{
	if( window.sidebar && window.sidebar.addPanel ) 
	{    
		window.sidebar.addPanel( title, href, '' );
	} 
	else if( window.external && ( navigator.platform == 'Win32' || ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) 
	{   
	      
		window.external.AddFavorite(href,title);		
		return false;
	} 
	else if( window.opera && window.print ) 
	{ 
		return true;
	} 
	else if( document.layers ) 
	{ 
		window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
	}
	else 
	{
		window.alert( 'Please use your browser\'s bookmarking facility to create a bookmark' );
	} 
	return false;	
}

function revealModal(divID)
{    
   
    window.onscroll = function () { document.getElementById(divID).style.top = document.body.scrollTop; };
    document.getElementById(divID).style.display = "block";
    document.getElementById(divID).style.top = document.body.scrollTop;
    document.getElementById(divID).style.visibility = "visible";     
}
            
function hideModal(divID)
{
    document.getElementById(divID).style.display = "none";
    document.getElementById(divID).style.visibility = "hidden";    
}
    
    
function chklogin(uname, pwd)
{
    
    var params = "username=" + uname + "&password=" + pwd;   
    var url = globalURL + "services/ajaxlogin.asmx/logincheck";    
    var xmlhttp = getxmlhttp();
    openloadpleasewait('logindiv');        
    if (xmlhttp!= null)
    {
        xmlhttp.onreadystatechange = function() { chkloginresponse(xmlhttp); };
        xmlhttp.open("POST", url,true);
        xmlhttp.setRequestHeader("Host","http://www.pinokey.com");                
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");                
        xmlhttp.send(params);        
    }
}

function chkloginresponse(xmlhttp)
{    
    var xmldoc = xmlhttp.responseXML; 
    var stringcontent = '';        
    if(xmlhttp.readyState == 4)
    {                
       var recordset = xmldoc.getElementsByTagName("user");
       if (recordset.length == 0)
       {     
           document.getElementById('errormessage').innerHTML='Login incorrect, try again.';                 
           closeloadpleasewait('logindiv');  
       }   
       else
       {            
            var secret = recordset[0].getElementsByTagName('secret')[0].firstChild.nodeValue;                                                
            closeloadpleasewait('logindiv');  
            hideModal('showIA');
            document.location.href = globalURL + 'pinokeystamp.aspx?pinokeystamp=loginsuccess&pkey=' + secret;
        }
    }
   
}

function newusersignup(loginid,pwd,retypepwd)
{
    if (!ValidateEmailAddress(loginid))
    {
        document.getElementById('errormessage').innerHTML='Please enter a valid email id as login id.';     
        return false;
    }
    if (pwd!= null  && pwd.length < 5)
    {
        document.getElementById('errormessage').innerHTML='Password should be of minimum length 5.';     
        return false;
    }
    if (pwd!= retypepwd)
    {
        document.getElementById('errormessage').innerHTML='Password and Re-Type Password should be same.';     
        return false;
    }
    var params = "username=" + loginid + "&role=webuser&password=" + pwd;   
    var url = "/services/ajaxlogin.asmx/newusersignup";    
    var xmlhttp = getxmlhttp();
    openloadpleasewait('newuserpleasewait');        
    if (xmlhttp!= null)
    {
        xmlhttp.onreadystatechange = function() { newuserresponse(xmlhttp); };
        xmlhttp.open("POST", url,true);
        xmlhttp.setRequestHeader("Host","http://www.pinokey.com");                
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");                
        xmlhttp.send(params);        
    }
}

function newuserresponse(xmlhttp)
{    
    var xmldoc = xmlhttp.responseXML;     
    var stringcontent = '';        
    if(xmlhttp.readyState == 4)
    {                
       var recordset = xmldoc.getElementsByTagName("user");
       if (recordset.length == 0)
       {     
           document.getElementById('errormessage').innerHTML='User of this login id already exist.';                 
           closeloadpleasewait('newuserpleasewait');  
       }   
       else
       {            
            var secret = recordset[0].getElementsByTagName('secret')[0].firstChild.nodeValue;                                                
            closeloadpleasewait('newuserpleasewait');  
            hideModal('showIA');
            document.location.href ='/pinokeystamp.aspx?pinokeystamp=loginsuccess&pkey=' + secret;
        }
    }
   
}