

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function checkCookie(name){
    if(getCookie(name))
    {
    	alert("Cookie Exists");
    	return true;
    }
    else
    {
    	alert("Cookie Does NOT Exist");
    	return false;
    }
	
}

function checkAndPass(destination, defaultDestination){
	
	cookieName = "LAST_VISIT";
	chkPassword = "paradise";
	//----Check If Cookie exist
	if(getCookie(cookieName))
	{
		//--If exist then Redirect to the destination---
		//alert(destination);
		top.frames['info'].window.location=destination;
	}
	else
	{
	      //--If cookie does not exist then POP-UP the password form
	      passPhrase=prompt("Enter The Password"," ");
              //alert('PassWord entered is ' + passPhrase)	;
	
	
	//---Collect the password
		//----If Password matches then Redirect to destination--
		if(passPhrase == chkPassword)
		{
		     //----Set the Cookie	
		    	var value = new Date();
		    	var expires = new Date(value.getTime() + (30*24*60*60*1000));
		    	setCookie(cookieName, value, expires);
		    	//alert("Set New Cookie");
		top.frames['info'].window.location=destination;

		}
		else
		{		
			//--- Password does not match then Redirect to defaultDestination
		top.frames['content'].window.location=destination;
		}
		 
	}
}
