﻿
var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(agt.indexOf("opera/5")!=-1||agt.indexOf("opera 5")!=-1){op5=1;}
	if(agt.indexOf("opera/6")!=-1||agt.indexOf("opera 6")!=-1){op6=1;}
	if(agt.indexOf("opera/7")!=-1||agt.indexOf("opera 7")!=-1){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function SetCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
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));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
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";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixdate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function GetPwds()
{
	var pwds = new Array();
	var idx = y001kb.substring(0,2);
	var j = 0;
	while (idx != '')
	{
	    if (idx.substring(0,1) == '0')
		    idx = idx.substring(1);
		var pwd0 = '';
		for (var i = 0; i < parseInt(idx); i++)
		{
			j += 2;
			pwd0 += y001kb.substring(j, j+2);
		}
		var pwd = ConvertPwd(pwd0);
        pwds[pwds.length] = pwd;
		j += 2;
		idx = y001kb.substring(j,j+2);
	}
	return(pwds);
}

function ConvertPwd(pwd0)
{
    var pwd = "";
	for (var i1 = 0; i1 < pwd0.length; i1 += 2)
    {
       var h1 = pwd0.charAt(i1);
       var h2 = pwd0.charAt(i1 + 1);
       c = String.fromCharCode(parseInt(h1 + h2,16) - 1);
       pwd += c;
    }
    return (pwd);
}

function CheckPwd(pwd)
{
    var pwds = GetPwds();
    for (var i = 0; i < pwds.length; i++)
    {
        if (pwd == pwds[i])
            return(true);
    }
    return(false);
}

function CheckPassword()
{
    pwd = GetCookie("passphrase");
    if (!pwd)
    {
        var pwd;
//        if (window.showModalDialog)
//            pwd = window.showModalDialog('http://www.ytimes.net/taste/login.html',null,'dialogHeight=100px; dialogWidth=200px; scroll=yes; resizable=yes');
//        else
            pwd = prompt("Enter password:","");

        if (!pwd || pwd == '')
        {
            alert("Access denied");
            return;
        }
        if (!CheckPwd(pwd))
        {
            alert("Sorry, invalid password");
            return;
        }
        else
        {
            SetCookie("passphrase",pwd);
            return(true);
        }
    }
    else
    {
        if (!CheckPwd(pwd))
        {
            alert("Sorry, invalid password");
            DeleteCookie("passphrase");
            return(false);
        }
        return(true);
    }
}

var encodedSource = "";
var Generating = false;
var HTMLResult = "";
var currentIndex = 0;
var generatorTI;

function generateHTML()
{
    if (Generating)
        return;
    
    Generating = true;
    if (currentIndex >= encodedSource.length)
    {
        Generating = false
        self.clearTimeout(generatorTI);
        var e = document.getElementById("encodedBody");
        if (e)
        {
            e.innerHTML = HTMLResult;
        }
        return;
    }    
    else
    {
        self.clearTimeout(generatorTI);
        var nextJ = currentIndex + 7500;
        for (j = currentIndex; j < nextJ && j < encodedSource.length; j +=2, currentIndex +=2)
        {
            //e.innerHTML += currentIndex + "<br>"
            var h1 = encodedSource.charAt(j);
		    var h2 = encodedSource.charAt(j+1);
		    HTMLResult += (String.fromCharCode(parseInt(h1 + h2,16)));
        }
    }
    generatorTI = self.setTimeout(generateHTML, 1);
    Generating = false;
}
function ydecode(src)
{
    if (CheckPassword())
    {
        if (!ie)
        {
	        for (var i = 0; i < src.length; i += 2)
	        {
		        var h1 = src.charAt(i);
		        var h2 = src.charAt(i+1);
		        document.write (String.fromCharCode(parseInt(h1 + h2,16)));
	        }
	    }
	    else
	    {
            var e = document.getElementById("encodedBody");
            if (e && src.length > 10000)
            {
                e.innerHTML = "Please wait...";
            }
	        encodedSource = src;
	        generatorTI = self.setTimeout(generateHTML, 1);
	    }
    }
    else
    {
        document.write("<font color=#ff0000>Sorry, this page is for authorized " + parentPage + " customers only and is password protected. Hit the Refresh button to be prompted again.</font>");
        if (typeof(signupPage) != 'undefined' && signupPage != '')
        {
            document.write("<br><br>To become an authorized user, please <a href=" + signupPage + ".html>click here</a> and fill out the application.");
        }
        document.write("<form method=post action=http://store.yahoo.com/cgi-bin/pro-forma id=emailform>  \
                            <input type=hidden name=from id=from>   \
                            <input type=hidden name=subject value='" + parentPage + " - Forgot Password'>   \
                            <input type=hidden name=owner value=gabikhaled@yahoo.com> \
                            <br><b>Password Help</b><br>                            \
                            If you forgot your password, please fill out and submit the following form.<br> \
                            <table><tr> \
                            <td>Account Name:</td><td><input type=text name=account_name></td></tr>   \
                            <tr><td>Email:</td><td><input type=text name=email id=email></td></tr>             \
                            <tr><td><input type=submit value='Submit' onclick='");
        document.write('document.getElementById("from").value = document.getElementById("email").value' + "'></td></tr></table>");
        document.write("</form>");
    }
}