//<!-- 03/03/03; 11:11:44 AM -->
//<!-- Begin


// temp intercept
function tempintercept() {
	var cookies = document.cookie;
	var popup_win = 0; // 0 = No Popup  1 = Popup Window
	var test_mode = 1; // 0 = Live Mode 1 = Test Mode 
	
	theDate = new Date();
	
	// the start variables are the day that the intercept will begin			
	var startMonth = 3; // Month Offset where 0 = January
	var startDay = 1;
	var startYear = 2003;
	var startDate = new Date(startYear,startMonth,startDay);
				
	// the end variables are the day that the intercept will end
	var endMonth = 4; // Month Offset where 0 = January
	var endDay = 31;
	var endYear = 2003;
	endDate = new Date(endYear,endMonth,endDay);
	
	// pageIntercept is a quoted, comma-seperated list of variables
	// that are the pages that when the user goes to one of these pages
	// that a possible intercept could occur on
	var pageIntercept = ["http://www.macworld.com/", "http://www.macworld.com/magazine/", "http://www.macworld.com/reviews/", "http://macworld.pricegrabber.com/index.php", "http://www.macworld.com/forums/ubbthreads/ubbthreads.php"];
	
	// ratio is the ratio of users to be intercepted
	// the sample below is 20:1 which are the odds of a user
	// begin intercepted
	var ratio = 50;
	
	// These variables come out of Intercept_Main in the database
	var interceptid = 23;
	var intercept_name = "mw255";
	
	// this is location that the page will goto when an intercept occurs
	var window_location = "http://www.rsch.com/mw255/invitation.cfm?interceptid=" + interceptid + "&intercept_name=" + intercept_name + "&ratio=" + ratio + "&location_intercept=" + window.location;
	
	// This is used for when someone selected later, this should be the URL to the first page
	var survey_location = "http://www.rsch.com/mw255/survey.cfm?";
	
	// this is the location of the test code for logging without intercepting
	var test_location = "http://www.rsch.com/mw255/test.cfm?interceptid=" + interceptid + "&intercept_name=" + intercept_name + "&ratio=" + ratio;
	
	var cookie_value; 
	
	function readCookie(name)
	{
	
		var start = cookies.indexOf(name + "=");
		
		if (start == -1)
		{
			//alert("Cookie Not Found");
			return false;
		}
		
		start = cookies.indexOf("=",start) + 1;
		
		var end = cookies.indexOf(";",start);
		
		if (end == -1)
		{
			end = cookies.length;
		}
		
		var value = unescape(cookies.substring(start,end));
		
		if (value == null)
		{
			//alert("No cookie found");
			return false;
		}
		else
		{
			//alert("Cookie value is: " + value);
			cookie_value = value;
			return true;
			
		}
		
	}
	
	function writeCookie(name,value)
	{
		var exp = new Date();
		var tenyears = exp.getTime() + (365 * 10 * 24 * 60 * 60 * 1000);
		exp.setTime(tenyears);
		
		document.cookie = name + "=" + value + ";path=/; expires=" + exp.toGMTString();
	}
	
	function killCookie(name)
	{
		var exp = new Date();
		var tenyears = exp.getTime() - (365 * 10 * 24 * 60 * 60 * 1000);
		exp.setTime(tenyears);
		
		document.cookie = name + "= 0;path=/; expires=" + exp.toGMTString();
	}
	
	function intercept()
	{
			
			if ((readCookie("mw255_t") == false) & (readCookie("mc255_t") == false))
			{
				if (theDate.getTime() >= startDate.getTime() && theDate.getTime() <= endDate.getTime())
				{
					for (x=0;x<pageIntercept.length;x++)
					{
						if (window.location == pageIntercept[x])
							{
								var choice = Math.round(ratio * Math.random());
								// this is the calculated middle between the ratio rounded up
								var middle_num = Math.round(ratio / 2);
								if (choice == middle_num)
								{
									writeCookie("mw255_t","1");
									if (test_mode == 0)
									{
										if (popup_win == 1)
										{
											window.open(window_location,"Survey", 'toolbar=no,width=400,height=430,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,location=no,copyhistory=no');					
										}
										else
										{
											//document.write(window_location)
											//alert(window_location + " NEW VER 11")
											window.location = window_location;
											//top.location = "http://www.rsch.com/";
											//alert(top.location)
											
										}
									}
									else
									{
										document.all.intercept_image.src = test_location;
									}
								}
							}
						}
					}
				}
				else
				{
					if(readCookie("MW255_T_LATER") == true)
					{
						temp_date = new Date(cookie_value);
						if (theDate.getTime() >= temp_date.getTime())
						{
							test = readCookie("MW255_T_LATER_INDIVID");
							var temp_individ = cookie_value;
							test = readCookie("MW255_T_LATER_INTERCEPTID");
							var temp_interceptid = cookie_value;
							killCookie("MW255_T_LATER");
							
							if (popup_win == 1)
							{
								window.open(survey_location + "individ=" + temp_individ + "&interceptid=" + temp_interceptid + "&location_intercept=" + window.location,"Survey", 'toolbar=no,width=400,height=430,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,location=no,copyhistory=no');					
							}
							else
							{
								window.location = survey_location + "individ=" + temp_individ + "&interceptid=" + temp_interceptid + "&location_intercept=" + window.location + "&later=1";
							}
						}
						
					}
				}
	}
return false;
}
// end temp intercept

function GetCookie(name) {
        var result = null;
        var cookies = " " + document.cookie + ";";
        var searchName = " " + unescape(name) + "=";
        var startOfCookie = cookies.indexOf(searchName);
        var endOfCookie;
        if (startOfCookie == -1) {return "none";}
        if (startOfCookie !=1) {
         // skip past cookie name
    startOfCookie += searchName.length;
      endOfCookie = cookies.indexOf(";", startOfCookie);
        result = unescape(cookies.substring(startOfCookie, endOfCookie));

        }
        return result;

}


//MAG SUB
function checkform() {
    var namemsg = "Please enter your name.\n Your order cannot be processed without this information.";
    var streetmsg = "Please enter your street address.\n Your order cannot be processed without this information.";
    var citymsg = "Please enter your city.\n Your order cannot be processed without this information.";
    var statemsg = "Please enter your state.\n Your order cannot be processed without this information.";
    var zipmsg = "Please enter your zip/postal code.\n Your order cannot be processed without this information.";

    if(document.forms["mwembeddedform"].Name.value == "") {
        alert(namemsg);
        return false;
    } else if(document.forms["mwembeddedform"].Address1.value == "") {
        alert(streetmsg);
        return false;
    } else if(document.forms["mwembeddedform"].City.value == "") {
        alert(citymsg);
        return false;
    } else if(document.forms["mwembeddedform"].State.value == "") {
        alert(statemsg);
        return false;
    } else if(document.forms["mwembeddedform"].Zip.value == "") {
        alert(zipmsg);
        return false;
    } else {
        return true;
    }
}

function commit() {

    var msg = "Click Ok and we'll send you a TRIAL ISSUE of Macworld and start your trial subscription. ";
    msg += 'If you like what you get, pay just $19.97 for ';
    msg += "11 more issues (12 in all) and save 79% off the newsstand rate.  If you're not completely satisfied with the ";
    msg += 'trial issue, write "cancel" on your invoice and return it, owe nothing at all and keep the first issue free!';

    if (checkform()) {
        return true;
    } else {
        return false;
    }//end if
} //end fn
//MAG SUB ENDS


function jumptourl(myvalue) {
    var mylink;
    mylink = myvalue.options[myvalue.selectedIndex].value;
    if (mylink != "") {
        myvalue.selectedIndex=0;
        window.open(mylink,"_self");
    }
}

//***** TOP NAV

var numImages = 7;    // total number of images count from zero
var i = 0;
var nimageOffArray = new Array();   // for arrays of images
var nimageOverArray = new Array();


// populate arrays of numeric images with regard to image naming convention
if (document.images) {
    for (i = 0; i <= numImages; i++) {
        nimageOffArray[i] = new Image();
        nimageOffArray[i].src="/images/nav/nbutt" + i + "off.gif";
        nimageOverArray[i] = new Image();
        nimageOverArray[i].src="/images/nav/nbutt" + i + "over.gif";
    }
}

function nswapMulti(imgName, state) {      // state is boolean--1 is Over, 0 is off
    if (document.images) {
        var imageNum = 0;
        for (i = 0; i <= numImages; i++) {               // parse imgName, use total number of images
            if (imgName == "nbutt" + i)
                imageNum = i;            // hold it
        }
        if (state)
            document[imgName].src = nimageOverArray[imageNum].src;
        else
            document[imgName].src = nimageOffArray[imageNum].src;
    }
}

function resetImages (rstImgName) {
    for (i = 0; i <= numImages; i++) {
        temp = rstImgName + i;
        if(nimageOffArray[i].src)
            document[temp].src = nimageOffArray[i].src;
        else
            document[temp].src = nimageOffArray[i].src;
    }
}



function initscripts(){
    //<!-- onload initscript -->
  return;
}



function unloadscripts(){
    //<!-- onunload initscript -->
    resetImages('nbutt');
	tempintercept();
}

// End -->

