//Begin detection
var TICM_na = parseFloat(navigator.appVersion);	
var TICM_napN = navigator.appName.toLowerCase();
var TICM_nu = navigator.userAgent.toLowerCase();

var TICM_isIE=((document.all)&&(TICM_nu.indexOf('opera')==-1))?true:false;
var TICM_isNN4=((document.layers)&&(TICM_na >= 4.03))?true:false;
var TICM_isOpera5up=(TICM_nu.indexOf('opera 5')!=-1)?true:false;
var TICM_isGecko=(TICM_nu.indexOf('gecko')!=-1)?true:false;
var TICM_isDom = document.getElementById?true:false;

var TICM_GeckoMinor=(TICM_isGecko && TICM_nu.indexOf("rv:") > 0)?TICM_nu.slice(TICM_nu.indexOf('rv:')+3,TICM_nu.indexOf('rv:')+8):0;
var TICM_isNS62up=(TICM_GeckoMinor>='0.9.4')?true:false;
var TICM_ieMajor=TICM_isIE?parseInt(TICM_nu.slice(TICM_nu.indexOf('msie')+4)):0;
var TICM_isIE4up=TICM_ieMajor >= 4;
var TICM_isIE5up=TICM_ieMajor >= 5;

var TICM_isWin=(TICM_nu.indexOf('win')!=-1)?true:false;
var TICM_isWin98=(TICM_nu.indexOf('windows nt')!=-1)?true:false;
var TICM_isWinNT=(TICM_nu.indexOf('windows 98')!=-1)?true:false;
var TICM_isMac=(TICM_nu.indexOf('mac')!=-1)?true:false;

var TICM_goodClient = (TICM_isNN4 || TICM_isIE4up || TICM_isOpera5up || TICM_isNS62up || TICM_isDom);
//End client detection

//this code is called on submit of form, and turns off popups for 
//24 hours.
function TICM_SetCookie (name,value,expires,path,domain,secure){
        document.cookie = name + escape (value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "; expires=Thu, 01-Jan-1970 00:00:01 GMT") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : ""); 
}
var TICM_day = 86400000; //one day in milliseconds
var TICM_date = new Date();
var TICM_popup2ON = new Date(TICM_date.getTime()+TICM_day);
//End of code for popups

//width of input type=text
var inpWidthLg=17;
var inpWidthSm=9; 

if (TICM_isNS62up){ 
    inpWidthLg=15; 
    inpWidthSm=7;
}

/*
function  TICM_submit(winName,f,h,w){
	if(TICM_check(f)){
       var features = "height=" + h + ",width=" + w + ",scrollbars=yes,location=no"
                   + ",menubar=no,resizable=no,status=yes,directories=no,toolbar=no";
        window.open("",winName,features);
		f.target = winName;
        TICM_SetCookie('popup2OFF','',TICM_popup2ON,'/');
		if(typeof P_isLoaded != "undefined")P_isLoaded = false;
        return true;
	}
    return false;
}
*/
if(document.cookie.indexOf('popup2OFF')!=-1){
	if(typeof P_isLoaded != "undefined")P_isLoaded = false;
}


// Form Validation Script
function TICM_check(f){
var states = f.state;
var state;
var canstates = ['AB','BC','MB','NB','NL','NS','NT','ON','PE','QC','SK','YT']

	//t:temporary field value, msg:concatenated error message, good: boolean error tracker	
	var t, msg, good;
   	state = states.options[states.selectedIndex].value;  
	msg = "";
	if ((f.name.value.search(/[A-Za-z]\s[A-Za-z]/) == -1) || (f.name.value == null) || (f.name.value == '') || isblank(f.name.value)) msg += "Please enter your Name.\n";
	if ((f.address1.value == null) || (f.address1.value == '') || isblank(f.address1.value)) msg += "Please enter your Address.\n";	
	if ((f.city.value == null) || (f.city.value == '') || isblank(f.city.value)) msg += "Please enter your City.\n";	
	if (state=='')msg+="Please enter your State/Province.\n"
		
	t = f.zipCode.value;
	good=1;
	if (t==null || t=='' || isblank(t) || t.length<5 || t.length>6 )good=0;
	else{if (state!=''){
			if (t.length==5 && (t.search(/^\d{5}$/) != -1)){ 
				for (d = 0; d<canstates.length;d++){
					if (state==canstates[d])good=0;
				}
			}else good=0;
			if (t.length==6 && t.search(/^[a-zA-Z]\w{5}$/)!=-1){
				good=0;
				for (d = 0; d<canstates.length;d++){
					if (state == canstates[d])good=1;
				}
			}
		}
	}

	if (!good)msg+="Zip/Postal code is blank or incorrect,\nor it doesn't match the State/Province you selected.\n";

    good=1; t=f.email.value;
    if (t != null && t != '' && !isblank(t)){
        good=(t.search(/^(\w|-)+(\.(\w|-)+)?@((\w|-)+\.){1,}[a-zA-Z]{2,3}$/)==-1)?0:1;
    }
    
	if(!good)msg+="Please enter a valid E-Mail Address.\n";
   
	if (msg.length) {
		alert ("The form was not submitted because of the following error(s):\n\n" + msg +
			"\n\nPlease correct these error(s) and resubmit your form.\n\nThank you,\nTime Inc. Consumer Services");
		return false;
	}
	return true;
}
// End Form Validation Script

// Utility function to check for blanknocity
function isblank(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
return true;
}


// begin html for subscription form 
var sFormPath = "https://subs.timeinc.net/"
sPgLoc = document.location.href
//if (sPgLoc.indexOf("/develop/subs2") !=-1) sFormPath = "https://dev.subs.timeinc.net/" //vk - local dev
if (sPgLoc.indexOf("timeinc.net/subs2/dev/") !=-1) sFormPath = "https://dev.subs.timeinc.net/"
if (sPgLoc.indexOf("timeinc.net/subs2/stage/") !=-1) sFormPath = "https://stage.subs.timeinc.net/"


function submitContinue(f) {
  if (TICM_check(f)) {
  	var ofieWin;

//50% split to a different form:	
if ((Math.random() * 100) <= 50) f.action = sFormPath+"SI/si_ofie0305sicom.jhtml";	
    
	ofieWin = window.open('','si_ofie0305sicom','width=370,height=610,scrollbars=1,status=1,resizable=0,top=50,left=100');		
	f.target = 'si_ofie0305sicom';
    return true;
  }
  else return false;
}



var styles = '<STYLE TYPE="TEXT/CSS">.si_ofie04_copy {font-family: Verdana, Arial, sans-serif; font-size: 10px} .si_ofie04_form {height: 18px}</STYLE>';

var form_body = '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="LEFT" bgcolor="#ffffff">'+
'<form method="post" action="'+sFormPath+'SI/si_ofie0405sicom.jhtml" onsubmit="return submitContinue(this);">'+
'<input type="hidden" name="magCode_Option" value="SI_2" >'+
'<input type="hidden" name="per_name" value="si_ofie0405sicom"><input type="hidden" name="passVariables" value="MSCSIGTP_E"><input type="hidden" name="emailEC" value="CHECK_ON_REQUIRED_OFF">'+
'<TR> '+
'<TD COLSPAN="3"><IMG SRC="http://i.a.cnn.net/si/.element/img/2.0/story/ofie/si_ofie04_01a.gif" WIDTH="291" HEIGHT="21"><a href="https://subs.timeinc.net/CampaignHandler/sigftblnkt?source_id=20" target="_blank"><IMG SRC="http://i.a.cnn.net/si/.element/img/2.0/story/ofie/si_ofie04_01b.gif" WIDTH="129" HEIGHT="21" BORDER="0"></a></TD>'+
'</TR>'+
'<TR> '+
'<TD BACKGROUND="http://i.a.cnn.net/si/.element/img/2.0/story/ofie/si_ofie04_06.gif" WIDTH="3"><IMG SRC="http://i.cnn.net/si/images/1.gif" WIDTH="3" HEIGHT="1"></TD>'+
'<TD WIDTH="414"> '+
'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">'+
'<TR> '+
'<TD><IMG SRC="http://i.a.cnn.net/si/.element/img/2.0/story/ofie/si_ofie04_03a.gif" WIDTH="97" HEIGHT="91"></TD>'+
'<TD VALIGN="TOP"><IMG SRC="http://i.a.cnn.net/si/.element/img/2.0/story/ofie/si_ofie04_04.gif" WIDTH="317" HEIGHT="16"> '+
'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">'+
'<TR> '+
'<TD ALIGN="right" CLASS="si_ofie04_copy">Name: </TD>'+
'<TD> '+
'<INPUT TYPE="text" NAME="name" SIZE="10" MAXLENGTH="30" CLASS="si_ofie04_form" tabindex="1">'+
'</TD>'+
'<TD ALIGN="right" CLASS="si_ofie04_copy">State/Province: </TD>'+
'<TD> '+
'<SELECT NAME="state" CLASS="form" tabindex="4"><OPTION>--<OPTION VALUE=AA>AA<OPTION VALUE=AB>AB<OPTION VALUE=AE>AE<OPTION VALUE=AK>AK<OPTION VALUE=AL>AL<OPTION VALUE=AP>AP<OPTION VALUE=AR>AR<OPTION VALUE=AS>AS<OPTION VALUE=AZ>AZ<OPTION VALUE=BC>BC<OPTION VALUE=CA>CA<OPTION VALUE=CO>CO<OPTION VALUE=CT>CT<OPTION VALUE=DC>DC<OPTION VALUE=DE>DE<OPTION VALUE=FL>FL<OPTION VALUE=GA>GA<OPTION VALUE=HI>HI<OPTION VALUE=IA>IA<OPTION VALUE=ID>ID<OPTION VALUE=IL>IL<OPTION VALUE=IN>IN<OPTION VALUE=KS>KS<OPTION VALUE=KY>KY<OPTION VALUE=LA>LA<OPTION VALUE=MA>MA<OPTION VALUE=MB>MB<OPTION VALUE=MD>MD<OPTION VALUE=ME>ME<OPTION VALUE=MI>MI<OPTION VALUE=MN>MN<OPTION VALUE=MO>MO<OPTION VALUE=MP>MP<OPTION VALUE=MS>MS<OPTION VALUE=MT>MT<OPTION VALUE=NB>NB<OPTION VALUE=NC>NC<OPTION VALUE=ND>ND<OPTION VALUE=NE>NE<OPTION VALUE=NH>NH<OPTION VALUE=NJ>NJ<OPTION VALUE=NL>NL<OPTION VALUE=NM>NM<OPTION VALUE=NV>NV<OPTION VALUE=NS>NS<OPTION VALUE=NT>NT<OPTION VALUE=NY>NY<OPTION VALUE=ON>ON<OPTION VALUE=OH>OH<OPTION VALUE=OK>OK<OPTION VALUE=OR>OR<OPTION VALUE=PA>PA<OPTION VALUE=PE>PE<OPTION VALUE=PR>PR<OPTION VALUE=QC>QC<OPTION VALUE=RI>RI<OPTION VALUE=SC>SC<OPTION VALUE=SD>SD<OPTION VALUE=SK>SK<OPTION VALUE=TN>TN<OPTION VALUE=TX>TX<OPTION VALUE=UT>UT<OPTION VALUE=VA>VA<OPTION VALUE=VI>VI<OPTION VALUE=VT>VT<OPTION VALUE=WA>WA<OPTION VALUE=WI>WI<OPTION VALUE=WV>WV<OPTION VALUE=WY>WY<OPTION VALUE=YT>YT</OPTION></SELECT>'+
'</TD>'+
'</TR>'+
'<TR> '+
'<TD ALIGN="right" CLASS="si_ofie04_copy">Address: </TD>'+
'<TD> '+
'<INPUT TYPE="text" NAME="address1" SIZE="10" MAXLENGTH="30" CLASS="si_ofie04_form" tabindex="2">'+
'</TD>'+
'<TD ALIGN="right" CLASS="si_ofie04_copy">Zip/Postal Code: </TD>'+
'<TD> '+
'<INPUT TYPE="text" NAME="zipCode" SIZE="10" MAXLENGTH="6" CLASS="si_ofie04_form" tabindex="5">'+
'</TD>'+
'</TR>'+
'<TR> '+
'<TD ALIGN="right" CLASS="si_ofie04_copy">City: </TD>'+
'<TD> '+
'<INPUT TYPE="text" NAME="city" SIZE="10" MAXLENGTH="20" CLASS="si_ofie04_form" tabindex="3">'+
'</TD>'+
'<TD ALIGN="right" CLASS="si_ofie04_copy">E-mail: </TD>'+
'<TD>'+
'<INPUT TYPE="text" NAME="email" SIZE="10" MAXLENGTH="50" CLASS="si_ofie04_form" tabindex="6">'+
'</TD>'+
'</TR>'+
'</TABLE>'+
'<FONT FACE="Verdana, Arial, Helvetica" SIZE="1"> </FONT> '+
'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="317">'+
'<TR ALIGN="CENTER" VALIGN="MIDDLE"> '+
'<TD CLASS="si_ofie04_copy">&nbsp;</TD>'+
'<TD align="center"><INPUT TYPE="image" SRC="http://i.a.cnn.net/si/.element/img/2.0/story/ofie/si_ofie04_10.gif" WIDTH="115" HEIGHT="20" BORDER="0">'+
'</TD>'+
'</TR>'+
'</TABLE>'+
'</TD>'+
'</TR>'+
'</TABLE>'+
'</TD>'+
'<TD BACKGROUND="http://i.a.cnn.net/si/.element/img/2.0/story/ofie/si_ofie04_06.gif" WIDTH="3"><IMG SRC="http://i.cnn.net/si/images/1.gif" WIDTH="3" HEIGHT="1"></TD>'+
'</TR>'+
'<TR> '+
'<TD BGCOLOR="#000066" WIDTH="3"><IMG SRC="http://i.cnn.net/si/images/1.gif" WIDTH="1" HEIGHT="1"></TD>'+
'<TD BACKGROUND="http://i.a.cnn.net/si/.element/img/2.0/story/ofie/si_ofie04_14.gif" HEIGHT="3"><IMG SRC="http://i.cnn.net/si/images/1.gif" WIDTH="1" HEIGHT="3"></TD>'+
'<TD BGCOLOR="#000066" WIDTH="3"><IMG SRC="http://i.cnn.net/si/images/1.gif" WIDTH="1" HEIGHT="1"></TD>'+
'</TR>'+
'</form>'+
'</TABLE>'

if (TICM_goodClient){ 
	document.write(styles);
	document.write(form_body);
}
