//Begin client 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_isNS6 = (TICM_isGecko && TICM_nu.indexOf("/6.") != -1)? true: false;
var TICM_isNS7 = (TICM_isGecko && TICM_nu.indexOf("/7.") != -1)? 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_isIE5up || TICM_isOpera5up || TICM_isNS6 || TICM_isDom);

var TICM_rows=2;
var TICM_cols=30;
var TICM_inpWidthLg=13; 
var TICM_inpWidthSm=5;

var tableBG = (TICM_isNN4) ? 'bgcolor="#FFFFFF"':'background="http://i.timeinc.net/subs2/images/td/td_ofie0303_bg.gif"';

if (TICM_isWin){
  if (TICM_isIE4up||TICM_isOpera5up) {TICM_cols=50; TICM_inpWidthLg=20;}
  if (TICM_isGecko){TICM_cols=44; TICM_rows=1; TICM_inpWidthLg=20;}
  if (TICM_isNS6){TICM_cols=48; TICM_rows=1; TICM_inpWidthLg=20; TICM_inpWidthSm=6;}
  if (TICM_isNS7){TICM_cols=48; TICM_rows=1; TICM_inpWidthLg=20; TICM_inpWidthSm=6;}
}
else if(TICM_isMac){
  if (TICM_isIE5up||TICM_isOpera5up) {TICM_cols=36; TICM_inpWidthLg=14; TICM_inpWidthSm=6; }
  if (TICM_isNN4){TICM_cols=35; TICM_rows=1; TICM_inpWidthLg=14;}
  if (TICM_isGecko){TICM_cols=14; TICM_inpWidthLg=14; TICM_inpWidthSm=6;}
  if (TICM_isNS6){TICM_cols=36; TICM_rows=1; TICM_inpWidthLg=18;}
  if (TICM_isNS7){TICM_cols=36; TICM_rows=1; TICM_inpWidthLg=18;}
}


//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

var CM_copy="After the free trial period, you\'ll receive 52 more issues - 56 in all - for $29.95." +
            "That's 86% off the cover price! *You\'ll also receive the Touchscreen organizer with full payment." +
            "If you don\'t want to continue with TIME after your trial period, simply return your bill marked \"cancel\" and owe nothing." +
            "Offer is valid in the US Only. *Cover price is $3.95. TIME is published weekly, except for two issues combined periodically into one and occasional extra, expanded, or premium issues." +
            "Combined, expanded, and premium issues count as two subscription issues." +
            "Subscribers: if the Post Office alerts us that your magazine is undeliverable, we have no further obligation unless we receive a corrected address within two years.";

var details = '<textarea readonly cols="'+TICM_cols+'" rows="'+TICM_rows+'" onChange="this.value=CM_copy;" style="font-family:Arial,Helvetica,sans-serif; font-size:11px;" wrap>'+CM_copy+'</textarea>';

function CM_send(f){
  var winName = "ofie";
  var h = 420;
  var w = 319;
  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','NF','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.fullName.value == null) || (f.fullName.value == '') || isblank(f.fullName.value)) msg += "Please enter your Name.\n";
  else if (f.fullName.value.search(/^[\S]+([ ]{1}[\S]+)+$/) == -1) msg += "Please enter your First and Last 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.\n"

  good=1; t=f.email.value;
  if (t != null && t != '' && !isblank(t)){
    good=(t.search(/^(\w|-)+(\.(\w|-)+)*@((\w|-)+\.)+[a-zA-Z]{2,3}$/)==-1)?0:1;
  }
  else good = 0;

  if(!good)msg+="Please enter a valid E-Mail Address.\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 code is blank or incorrect,\nor it doesn't match the State you selected.\n";

  if (!f.consent.checked){msg+='Please confirm that you have read and accept the Offer Terms.\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 form_body = '<form name="td_ofie0303_form" method="post" action="https://subs.timeinc.net/ProcessorServlet.jhtml" onsubmit="return CM_send(this);">' +
'<input type="hidden" name="per_name" value="td_ofie0303">' +
'<input type="hidden" name="directory" value="TD">' +
'<input type="hidden" name="personality_resource_dir" value="TD">' +
'<input type="hidden" name="processorName" value="/net/timeinc/subs/user/controller/handler/curtain/BasicValetCurtainOFIE">' +
'<input type="hidden" name="campaign_name" value="tdofie">' + 
'<input type="hidden" name="source_id" value="2">' +
'<input type="hidden" name="passVariables" value="MSCSIGTP_E">' +
'<input type="hidden" name="delayLiveFulfillment" value="true">' + 
'<table border="0" cellspacing="0" cellpadding="0" width="359" ' + tableBG + '>' +
'<tr>' +
'<td colspan="5" width="359"><img src="http://i.timeinc.net/subs2/images/td/td_ofie0303_title_bar.gif" width="359" height="16" /></td>' +
'</tr>' +
'<tr>' +
'<td colspan="5" width="359"><img src="http://i.timeinc.net/subs2/images/shared/spacer.gif" width="359" height="8" /></td>' +
'</tr>' +
'<tr valign="top">' +
'<td width="5" rowspan="2"><img src="http://i.timeinc.net/subs2/images/shared/spacer.gif" width="5" height="203" /></td>' +
'<td width="70" class="input">' +
'<img src="http://i.timeinc.net/subs2/images/td/td_ofie0303_cover.gif" width="70" height="90" /><br />' +
'<span style="color:#990000; font-family:Arial,Helvetica,sans-serif; font-size:11px; font-weight:bold;">If you like TIME you\'ll pay just $29.95 for 56 issues</span><br />' +
'</td>' +
'<td width="5" rowspan="2"><img src="http://i.timeinc.net/subs2/images/shared/spacer.gif" width="5" height="203" /></td>' +
'<td width="276">' +
'<table border="0" cellspacing="0" cellpadding="0" width="100%">' +
'<tr valign="top">' +
'<td class="input" width="50%">' +
'Name:<br />' +
'<input type="text" size="' + TICM_inpWidthLg + '" maxlength="30" name="fullName" class="input" tabindex="1" /><br />' +
'</td>' +
'<td class="input" colspan="2" width="50%">' +
'City:<br />' +
'<input type="text" size="13" maxlength="20" name="city" class="input" tabindex="4" /><br />' +
'</td>' +
'</tr>' +
'<tr valign="top">' +
'<td class="input" width="50%">' +
'Address:<br />' +
'<input type="text" size="' + TICM_inpWidthLg + '" maxlength="30" name="address1" class="input" tabindex="2" /><br />' +
'<input type="text" size="' + TICM_inpWidthLg + '" maxlength="30" name="address2" class="input" tabindex="3" /><br />' +
'</td>' +
'<td class="input" width="30%">' +
'State:<br />' +
'<select name="state" class="input" tabindex="5">' +
'<option value="">--</option>' +
'<option value="AA">AA</option>' +
'<option value="AE">AE</option>' +
'<option value="AK">AK</option>' +
'<option value="AL">AL</option>' +
'<option value="AP">AP</option>' +
'<option value="AR">AR</option>' +
'<option value="AS">AS</option>' +
'<option value="AZ">AZ</option>' +
'<option value="CA">CA</option>' +
'<option value="CO">CO</option>' +
'<option value="CT">CT</option>' +
'<option value="DC">DC</option>' +
'<option value="DE">DE</option>' +
'<option value="FL">FL</option>' +
'<option value="GA">GA</option>' +
'<option value="GU">GU</option>' +
'<option value="HI">HI</option>' +
'<option value="IA">IA</option>' +
'<option value="ID">ID</option>' +
'<option value="IL">IL</option>' +
'<option value="IN">IN</option>' +
'<option value="KS">KS</option>' +
'<option value="KY">KY</option>' +
'<option value="LA">LA</option>' +
'<option value="MA">MA</option>' +
'<option value="MD">MD</option>' +
'<option value="ME">ME</option>' +
'<option value="MI">MI</option>' +
'<option value="MN">MN</option>' +
'<option value="MO">MO</option>' +
'<option value="MS">MS</option>' +
'<option value="MT">MT</option>' +
'<option value="NC">NC</option>' +
'<option value="ND">ND</option>' +
'<option value="NE">NE</option>' +
'<option value="NH">NH</option>' +
'<option value="NJ">NJ</option>' +
'<option value="NM">NM</option>' +
'<option value="NV">NV</option>' +
'<option value="NY">NY</option>' +
'<option value="OH">OH</option>' +
'<option value="OK">OK</option>' +
'<option value="OR">OR</option>' +
'<option value="PA">PA</option>' +
'<option value="PR">PR</option>' +
'<option value="RI">RI</option>' +
'<option value="SC">SC</option>' +
'<option value="SD">SD</option>' +
'<option value="TN">TN</option>' +
'<option value="TX">TX</option>' +
'<option value="UT">UT</option>' +
'<option value="VA">VA</option>' +
'<option value="VI">VI</option>' +
'<option value="VT">VT</option>' +
'<option value="WA">WA</option>' +
'<option value="WI">WI</option>' +
'<option value="WV">WV</option>' +
'<option value="WY">WY</option>' +
'</select><br />' +
'</td>' +
'<td class="input" width="20%">' +
'Zip:<br />' +
'<input type="text" size="' + TICM_inpWidthSm + '" maxlength="5" name="zipCode" class="input" tabindex="6" /><br />' +
'</td>' +
'</tr>' +
'<tr valign="top">' +
'<td class="input" width="50%">' +
'E-mail:<br />' +
'<input type="text" size="' + TICM_inpWidthLg + '" maxlength="50" name="email" class="input" tabindex="7" /><br />' +
'</td>' +
'<td class="input" colspan="2" width="50%" valign="bottom">' +
'For non-U.S. orders<br />' +
'<a href="http://www.pathfinder.com/subs/time/land/int_land.html" target="_blank" style="color:#990000;">click here</a>|<a href="http://cgi.timeinc.net/cgi-bin/mail/dnp/privacy_centralized.cgi/time?dnp_source=I" target="_blank" style="color:#990000;">Privacy Policy</a><br />' +
'</td>' +
'</tr>' +
'<tr>' +
'<td colspan="3" width="100%"><img src="http://i.timeinc.net/subs2/images/shared/spacer.gif" width="276" height="6" /></td>' +
'</tr>' +
'<tr valign="top">' +
'<td colspan="3" class="input" width="100%">' +
'<font face="Arial,Helvetica,sans-serif" size="1"><textarea readonly cols="'+TICM_cols+'" rows="'+TICM_rows+'" onChange="this.value=CM_copy;" wrap class="input">'+
CM_copy +
'</textarea></font>'+
'</td>' +
'</tr>' +
'<tr>' +
'<td colspan="3" width="100%">' +
'<span style="font-family:Arial,Helvetica,sans-serif; font-size:11px;"><input type="checkbox" name="consent" class="input"> I agree to the terms and conditions listed above.</span><br />' +
'</td>' +
'</tr>' +
'</table>' +
'</td>' +
'<td width="3" rowspan="2"><img src="http://i.timeinc.net/subs2/images/shared/spacer.gif" width="3" height="203" /></td>' +
'</tr>' +
'<tr bgcolor="#FFFFFF">' +
'<td colspan="3" align="right"><input type="image" src="http://i.timeinc.net/subs2/images/td/td_ofie0303_button.gif" width="186" height="16" border="0" /></td>' +
'</tr>' +
'</table>' +
'</form>';

if (TICM_goodClient) document.write(form_body);
