//<!--
//turn off error messages
window.onerror=function(){return true;}
//killclicks();


var closed_flag = false;
var agt=navigator.userAgent.toLowerCase();
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie4 = (agt.indexOf("msie 4.") != -1);
var is_ie6 = (agt.indexOf("msie 6.") != -1);
var is_opera   = (agt.indexOf("opera") != -1);
var is_nets  = (document.layers ? true : false);
var is_nets7 = (agt.indexOf("netscape/7") != -1);
var is_gecko   = (agt.indexOf("gecko") != -1);
var is_chrome = (agt.indexOf("chrome") != -1);
var is_firefox = (agt.indexOf("firefox") != -1);
var is_firefox15 = (agt.indexOf("firefox/1.5") != -1);
var is_firefox3 = (agt.indexOf("firefox/3") != -1);
var is_firefox20 = (agt.indexOf("firefox/2.0") != -1);
var is_firefox10 = (agt.indexOf("firefox/1.0") != -1);
var is_mac = (navigator.appVersion.indexOf("Mac") != -1);
var is_WinXP = (navigator.appVersion.indexOf("NT 5.1") != -1);
var is_Win2k = (navigator.appVersion.indexOf("NT 5.0") != -1);
var is_aol = (agt.indexOf("aol") != -1);
var openwidth;
var openheight;

var here = new String(window.location.href.toLowerCase());
var cookie_acc = new String(get_cookie("&acc"));
var cookie_sub = new String(get_cookie("sub"));
var cookie_branded = new String(get_cookie("branded"));
var cookie_AMSflag = new String(get_cookie("AMSflag"));
var querystring = top.location.search;
var queryacc = new String();
var querysub = new String();
var plprefix = new String();
var expDate = new Date();
if (expDate.getMonth()>8){
  expDate.setFullYear(expDate.getFullYear() + 1);
  expDate.setMonth(expDate.getMonth() - 9);
}else{
  expDate.setMonth(expDate.getMonth() + 3);
}

/*set FFA flag*/
var isFFA;
if(cookie_acc == "131808" || cookie_acc == "133670")
  isFFA = true;
else
  isFFA = false;


/*begin newsletter subscribe functions*/
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;
}

function badmail(s){
/*
  Email address must be at least 5 characters long.
  It must contain both "@" and "." neither of which can be the last character.
  The "@" must  not be adjacent to a "." and not be the first character.
  There must be a "." after the first three characters.

  while (s.lastIndexOf(" ") == s.length-1)
    s = s.slice(0,s.length-1);
  var at = s.indexOf("@");
  if( (s.length < 5) || (s.indexOf(" ") != -1) || (s.indexOf(".",3) == -1) || (s.indexOf(".") == 0)  || (at < 1) || (s.lastIndexOf("@") == (s.length - 1)) || (s.lastIndexOf(".") == (s.length - 1))  || (s.charAt(at-1) == ".") || (s.charAt(at+1) == ".") ){
    return true;
  }
  else return false;
*/
var reEmail = /^(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)?$/;

  if (reEmail.test(s))
    return false
  else
    return true;
}


function verify(){
 
 var error = 0;
 var msg = new String("Please ");
  if((document.subscribe.email.value==null)||(document.subscribe.email.value=="")||(isblank(document.subscribe.email.value))){
    error=1;
    msg +="enter your e-mail address.\n";
  }else{
    if(badmail(document.subscribe.email.value.toLowerCase())){
    error=1;
    msg +="correct your e-mail address.\n";
    }
  }
  if(error == 0){
    //document.support.submit();
    document.subscribe.success.value="1";
    cmCreateConversionEventTag ("Tax Tips Newsletter","2","NEWS"); //Coremetrics conversion tag (completion)
    alert("Thank you.  You will receive the newsletter at " + document.subscribe.email.value + ".");
    return true;
  }else{
    document.subscribe.success.value="0";
    alert(msg);
    return false;
  }
}
/*end newsletter subscribe functions*/

/*set pl prefix*/
plprefix="";
if((here.indexOf('internet-taxprep') != -1) || get_cookie('branded')!= "0" ) plprefix = "pl";

/*
IP subnets for testing by IP
development = 165.181
test1 = 172.19
test2 = 10.200
stage  = 10.204
production = 10.204
*/
function closed_condition(){
  var on_test = (here.indexOf("test1") != -1 || here.indexOf("stage") != -1 || here.indexOf("test2") != -1)
  var test_IP = (here.indexOf("165.181") != -1 || here.indexOf("172.19") != -1 || here.indexOf("10.204") != -1 || here.indexOf("10.200") != -1)
  //on_test = false;
  if (closed_flag && !test_IP){
    return(true);
  }
  return(false);
}

function NoCookie () {  
  var allcookies = document.cookie
  var nosessioncookie = (allcookies.indexOf("ASPSESSION") == -1);
  var nopersistentcookie = (allcookies.indexOf("accdata") == -1);
  
  if (allcookies.length == 0 || nosessioncookie || nopersistentcookie)
    return true;
  return false;
}


function restore_frames(){
  var development = '';
  var plprefix = '';
  var ctprefix = '';
  var lastslash,mypath;
  var here = new String(window.location.href.toLowerCase());
  if (here.indexOf('tnct') != -1){
    if (here.indexOf('tnct2009_ct_Release') != -1)
      development = '/tnct2009_ct_Release';
    else
      development = '/tnct2009_ct';
  }
  
  if ((here.indexOf('internet-taxprep') != -1) || get_cookie('branded')!= "0" ){
    plprefix = 'pl';
  }else{
    ctprefix = 'CT';
  }

  lastslash = window.location.pathname.lastIndexOf('/',window.location.pathname.length-2);
  
  if (lastslash == -1 || here.indexOf('pl') != -1 || here.indexOf('faq_files') != -1 || here.indexOf('taxguide') != -1)
    mypath = window.location.pathname;
  else
  mypath = window.location.pathname.substring(0,lastslash+1) + plprefix + window.location.pathname.substring(lastslash+1,window.location.pathname.length);

  if (document.location == top.document.location){
    if (window.location.href.replace)
      window.location.replace('http://' + window.location.host + development + '/' + plprefix + ctprefix + 'index.asp?page=http://' + window.location.host + mypath);
    else
      // causes problems with back button, but works
      window.location.href = 'http://' + window.location.host + development + '/' + plprefix + ctprefix + 'index.asp?page=http://' + window.location.host + mypath;
  }
}

function dosearch(){
  var url = new String();
  var here = new String();
  var here = new String(window.location.href.toLowerCase());
//  var searchstring = new String(document.search.searchfor.value);
  var searchstring = new String(cleanString(document.search.searchfor.value));
  if(!(document.search.searchfor.value == "") && !(document.search.searchfor.value == "?")){
    searchstring = searchstring.replace(/ /g, "%20");
    url = "faqs/search.asp?browsestring=&category=All&searchstring=" + searchstring;
    if (here.indexOf("tnct2009_ct") != -1)
        url = "/tnct2009_ct/" + url;
      else
        url = "/" + url;

    url = "http://" + document.location.host + url;

    if (document.location == top.location)
      document.location = url;
    else
      top.main.location = url;
  }
}

function pldosearch(){
  var url = new String();
  var here = new String(window.location.href.toUpperCase());
//  var searchstring = new String(document.plsearch.searchfor.value);
  var searchstring = new String(cleanString(document.plsearch.plsearchfor.value));
  if(!(document.plsearch.plsearchfor.value == "") && !(document.plsearch.plsearchfor.value == "?")){
    searchstring = searchstring.replace(/ /g, "%20");
    url = "faqs/plsearch.asp?browsestring=&category=All&searchstring=" + searchstring;
//    if (here.indexOf("TAXGUIDE") != -1){
//      url = "../" + url;
//    }
      if (here.indexOf("tnct2009_ct") != -1)
        url = "/tnct2009_ct/" + url;
      else
        url = "/" + url;
    if (document.location == top.location)
      document.location = url;
    else
      top.main.location = url;
  }
}

function get_cookie(name){
var allcookies = document.cookie;
pos = allcookies.indexOf(name);
var end
if(pos != -1){
  var start = pos + name.length + 1;
  var end1 = allcookies.indexOf(";", start);
  var end2 = allcookies.indexOf("&", start);
  ((end1 < end2)||(end2 == -1)) ? end=end1 : end=end2;
  if (end == -1){
    end = allcookies.length;
  }
  if(start == end)
    var value = "";
  else
    var value = allcookies.substring(start,end);
 }
return(value);
}

/* Lycos functions*/
function isIE4() {
  return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}

function launchHelp(helpurl) {
  HelpWin = window.open(helpurl, 'HelpWindow','toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=500');
    if( ! isIE4() ) {
      if (HelpWin.focus) {
        HelpWin.focus();
      }
    }
    if (HelpWin.focus!=null  &&  !isIE4()) 
      {
        HelpWin.focus();
      }
    if (HelpWin.opener == null) HelpWin.opener = window;
      HelpWin.opener.name = "LycosMain";
}
/* end Lycos functions*/

function equiz_next(next_url){
	if(q1 && q2 && q3 && q4){
		window.document.location = next_url;
	}
	else{
	  alert("Please answer Yes or No to all questions before pressing \"Next.\"");
	}
}

function NetsopenAWindow( pageToLoad, winName, width, height, center) {
  /* Opens a new window on the users desktop.

     Arguments:
     pageToLoad - The URL of a page to load in the browser window.
                  This can be a relative URL or fully qualified.
     winName -    Name of the new window.  NO SPACES!
     width -      The horizontal size of the new window.
     height -     The vertical size of the new window.
     center -     toggle centering on 4.0 browsers.
                  1=centered window 0=no centering

     Values in the "args" section below can all be toggled in the
     same fashion as the center toggle.  Just modify the appropriate
     value in the args section to be either 0 or 1.

     A call to this function might look like this:
     <a href="javascript:openAWindow('ice.html','ice',375,250,1)">Ice</a>

     */
                                         
     xposition=0; yposition=0;
     if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
          xposition = (screen.width - width) / 2;
          yposition = (screen.height - height) / 2;
     }
     if (center == 2){
          xposition = 0;
          yposition = 0;
     }
     args = "width=" + width + "," 
             + "height=" + height + "," 
             + "location=0," 
             + "menubar=0,"
             + "resizable=0,"
             + "scrollbars=1,"
             + "status=0," 
             + "titlebar=0,"
             + "toolbar=1,"
             + "hotkeys=0,"
             + "screenx=" + xposition + ","  //NN Only
             + "screeny=" + yposition + ","  //NN Only
             + "left=" + xposition + ","     //IE Only
             + "top=" + yposition;           //IE Only 

      return (window.open( pageToLoad,winName,args ));
}

function openAWindow( pageToLoad, winName, width, height, center) {
  /* Opens a new window on the users desktop.

     Arguments:
     pageToLoad - The URL of a page to load in the browser window.
                  This can be a relative URL or fully qualified.
     winName -    Name of the new window.  NO SPACES!
     width -      The horizontal size of the new window.
     height -     The vertical size of the new window.
     center -     1=centered window 0=no centering 2= top left corner

     Values in the "args" section below can all be toggled in the
     same fashion as the center toggle.  Just modify the appropriate
     value in the args section to be either 0 or 1.

     A call to this function might look like this:
     <a href="javascript:openAWindow('ice.html','ice',375,250,1)">Ice</a>
     */
                                         
     xposition=0; yposition=0;
     if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
          xposition = (screen.width - width) / 2;
          yposition = (screen.height - height) / 2;
     }
     if (center == 2){
          xposition = 0;
          yposition = 0;
     }
     args = "width=" + width + "," 
             + "height=" + height + "," 
             + "location=0," 
             + "menubar=0,"
             + "resizable=0,"
             + "scrollbars=1,"
             + "status=0," 
             + "titlebar=0,"
             + "toolbar=0,"
             + "hotkeys=0,"
             + "screenx=" + xposition + ","  //NN Only
             + "screeny=" + yposition + ","  //NN Only
             + "left=" + xposition + ","     //IE Only
             + "top=" + yposition;           //IE Only 

      return (window.open( pageToLoad,winName,args ));
}

//code to disable right clicks
function right(e) {
  if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2 || (e.modifiers & Event.SHIFT_MASK))){
    status='Special clicks disabled.';
    status='';
    return false;
  }
  else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3 || (event.button == 1 && event.shiftKey))) {
    status="Special clicks disabled.";
    alert("Special clicks disabled.");
    status='';
    return false;
  }
return true;
}

function killclicks(){
  document.onmousedown=right;
  document.onmouseup=right;
  if (document.layers) 
    window.captureEvents(Event.MOUSEDOWN);
  if (document.layers)
    window.captureEvents(Event.MOUSEUP);
  window.onmousedown=right;
  window.onmouseup=right;
}

function noquotes(line){
//removes quotes marks
  var s = new String();
  var i;

  for (i=0;i<line.length;i++){
    //if not a quote
    if(line.charAt(i)!='\"'){
        //then write this character to output string
        s = s + line.charAt(i);
    }
    else
      s = s + "\'";
  }
  return (s);
}

function cleanString(line){
//removes illegal characters and compresses multiple spaces
  var s = new String();
  var i;

  for (i=0;i<line.length;i++){
    //if not an illegal character
    if((line.charAt(i)!='?') && (line.charAt(i)!='\"') && (line.charAt(i)!=';') && (line.charAt(i)!='!') && (line.charAt(i)!=',') && (line.charAt(i)!='.') && (line.charAt(i)!='%') && (line.charAt(i)!='*') && (line.charAt(i)!='<') && (line.charAt(i)!='>') && (line.charAt(i)!='&') && (line.charAt(i)!='#') && (line.charAt(i)!='(') && (line.charAt(i)!=')') && (line.charAt(i)!=']') && (line.charAt(i)!='[') && (line.charAt(i)!='\\') && (line.charAt(i)!='+') && (line.charAt(i)!='^') && (line.charAt(i)!='\"')){
      //if not consecutive space or last character is not space
      if((i==0) || !(line.charAt(i)==' ' && s.charAt(s.length-1)==' ') || !(line.charAt(i)==' ' && i == line.length-1))
        //then write this character to output string
        s = s + line.charAt(i);
    }
  }
  return (s);
}

function RemoveCommonWords(words){
  var i;

  for(i=0;i<words.length;){
    if(
        /*words to ignore*/
       (words[i].toUpperCase() == "THIS") || 
       (words[i].toUpperCase() == "THAT") || 
       (words[i].toUpperCase() == "DOES") ||
       (words[i].toUpperCase() == "YOUR") || 
       (words[i].toUpperCase() == "BOTH") || 
       (words[i].toUpperCase() == "HAVE") || 
       (words[i].toUpperCase() == "COMPLETETAX") || 
       (words[i].toUpperCase() == "HELP") || 
       (words[i].toUpperCase() == "WHEN") || 
       (words[i].toUpperCase() == "WHERE") || 
       (words[i].toUpperCase() == "WHAT") || 
       (words[i].toUpperCase() == "ISN'T") || 
       (words[i].toUpperCase() == "THANKS") || 
       (words[i].toUpperCase() == "THANK") || 
       (words[i].toUpperCase() == "PROBLEM") || 
       (words[i].toUpperCase() == "PROGRAM") || 
       (words[i].toUpperCase() == "SUPPORT") ||
        /*ignore words less than 3 letters unless it is in this list*/
      ((words[i].length < 4) && 
       (words[i].toUpperCase() != "IRS") && 
       (words[i].toUpperCase() != "ID") && 
       (words[i].toUpperCase() != "W2") && 
       (words[i].toUpperCase() != "800") && 
       (words[i].toUpperCase() != "600") && 
       (words[i].toUpperCase() != "AGI"))
      )
      words = DeleteElement(words, i);
    else
//not removing word
      i++;
  }
  return(words);
}

function DeleteElement(a,i){
var temp = new Array();
  if (i == 0)
  //removing first element
    return (a.slice(1));
  else
    if (a.length == i+1)
    //removing last element
      return (a.slice(0, i));
    else{
    //removing element in middle of array
      temp = a.slice(i+1);
      a = a.slice(0,i);
//alert("beginning of array to keep" + temp);
//alert("end of array to keep" + a);
      a = a.concat(temp);
      return (a);
    }
}

function WeightWords(stRaw){
  var words = new Array();
  var stResults = new String();

  stRaw = cleanString(stRaw);
  words = RemoveCommonWords(stRaw.split(" "));

  stResults = words.toString();
  stResults = stResults.replace(/[,]/g, " ");
  while((stResults.lastIndexOf(" ") != -1) && (stResults.lastIndexOf(" ") == stResults.length-1)){
    stResults = stResults.slice(0,-1);
  }
//alert("!!" + stResults + "!!");
  return stResults;
}
function go_tvcalc(type){/*open calculators in a new window for Netscape 4*/
var strURL;
switch(type){
    case 1:  //All Calculators
      strURL = "http://www.tcalc.com/tvwww.dll?user?tmplt=usertool.htm&cstm=completetax2";
      break;
    case 2:  //Home Financing
      strURL = "http://www.tcalc.com/tvwww.dll?user?tmplt=homesuite.htm&cstm=completetax2";
      break;
    case 3:  //Personal Finance
      strURL = "http://www.tcalc.com/tvwww.dll?user?tmplt=persfin.htm&cstm=completetax2";
      break;
    case 4:  //Investment
      strURL = "http://www.tcalc.com/tvwww.dll?user?tmplt=investsuite.htm&cstm=completetax2";
      break;
    case 5:  //Retirement
      strURL = "http://www.tcalc.com/tvwww.dll?user?tmplt=retsuite.htm&cstm=completetax2";
      break;
    case 6:  //Lease
      strURL = "http://www.tcalc.com/tvwww.dll?user?tmplt=leasesuite.htm&cstm=completetax2";
      break;
    default:  //All Calculators
      strURL = "http://www.tcalc.com/tvwww.dll?user?tmplt=usertool.htm&cstm=completetax2";
      break;
  }
    window.open(strURL,"tvcalc","top=0,left=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=580,height=520");
}

function go_taxes_UID(username){
go_taxes02();
}

function go_taxes02(type, optout){
  var strURL;
  var newwin = null;
  var closehost = document.location.host;
  var developmentpath = here.substr(0,here.lastIndexOf("/"));
  developmentpath = "http://165.181.97.140/tnct2009_ct_release/";

  if (closed_condition()){
    if (document.location.host.toLowerCase() == "localhost")
      closehost = document.location.host + "/tnct2009_ct";
    strURL = "http://" + closehost + "/" + plprefix + "unavailable.asp";
    document.location = strURL;
    return;
  }

  if (NoCookie()){top.window.location = plprefix + "nocookies.asp";}
  if (document.location.host.toLowerCase() == "localhost" || document.location.host.toLowerCase() == "165.181.96.169") 
    strURL = developmentpath + "/CT/Login/CTBegin.aspx";
  else
    strURL = "https://" + document.location.host + "/CT/Login/CTBegin.aspx";
  
  if(isFFA){
    strURL = strURL + "?el=P";
  }else{ 
  switch(type){
    case 1:  //Free
      strURL = strURL + "?el=F";
      break;
    case 2:  //Basic
      strURL = strURL + "?el=B";
      break;
    case 3:  //Deluxe
      strURL = strURL + "?el=D";
      break;
    case 4:  //Premium
      strURL = strURL + "?el=P";
      break;
    default:  //Default to Free
      strURL = strURL + "?el=F";
      break;
    }
  }

  if (document.layers){	
    openwidth = (screen.availWidth - 12);
    openheight = (screen.availHeight - 33);
  }else{
	if (is_aol){
		openwidth = (screen.availWidth - 50);
	}else{
	    openwidth = (screen.availWidth - 10);
	}
    openheight = (screen.availHeight - 49);  
    if (is_WinXP){
        openheight = (screen.availHeight - 62); 
    }
  }
  if (is_gecko){
    openwidth = openwidth +3;
  }


//check for cookies before opening a new window
  if (NoCookie()){
    top.window.location = plprefix + "nocookies.asp";
  }else{  //only open login window if cookies exist
    newwin = window.open(strURL,"OnlineTax","width="+openwidth+",height="+openheight+",top=0,left=0,scrollbars=1,status=1");
//alert(strURL);
    //if window.open didn't return a value then a pop-up blocker has been detected (doesn't always detect pop-up blocker)
    if (newwin == null || newwin.closed){
      alert('There was an error opening the program window.  A pop-up blocker may be in use. Change the settings on your pop-up blocker and try again.');
    }else{
      newwin.focus();
    }
  }
}
/*Verisign function*/
function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=715,height=450');
//self.name = "mainWin";
}
/*Better Business Bureau function*/
function Pcertify(){
popupWin = window.open('http://www.bbbonline.org/cks.asp?id=108010318817 ', 'Participant','location=yes,scrollbars=yes,width=797,height=470'); 
//window.name = 'opener';
} 
function Rcertify() {
popupWin = window.open('http://www.bbbonline.org/cks.asp?id=10211051319427423', 'Participant','location=yes,scrollbars=yes,width=450,height=370'); 
//window.name = 'opener';
}


//-->

