/****
 *These functions are used by the software download registration page.
 *Author:  Michael Walker
 *Last edited Feb 3, 2003
 */
function sendMail() {
    features = "width=150,"
             + "height=50,"
             + "toolbar=no,"
             + "location=no,"
             + "status=no,"
             + "menubar=no,"
             + "scrollbars=no,"
             + "top="+(window.screen.height-50)/2+","
             + "left="+(window.screen.width-150)/2;
    window.open('/etaf/thanks.html','swd_form',features);
}

function sendRmReg(fnam,lnam,lang,emal,whpr,ctry){
    features = "width=150,"
             + "height=50,"
             + "toolbar=no,"
             + "location=no,"
             + "status=no,"
             + "menubar=no,"
             + "scrollbars=no,"
             + "top="+(window.screen.height-50)/2+","
             + "left="+(window.screen.width-150)/2;
             url='/support/app/rm_reg.jsp?FNAM='+fnam+'&LNAM='+lnam+'&EMAL='+emal+'&LANG='+lang+'&WHPR='+whpr+'&CTRY='+ctry;
    window.open(url,'swd_form',features);
}

function SetCookie( strName, strValue ){
  var strCookie = strName + "=" + escape( strValue )
  // 1 year before expiry should be enough!
  var dtExpire = new Date()
  dtExpire.setTime( dtExpire.getTime() + (365 * 24 * 60 * 60 * 1000 * 1 ) )
  strCookie += "; expires=" + dtExpire.toGMTString()
  document.cookie = strCookie
  }//end function SetCookie

  function GetCookie( strName )  {
  var dc = document.cookie
  var prefix = strName + "="
  var begin = dc.indexOf( "; " + prefix )
  if( begin == -1 ){
    begin = dc.indexOf( prefix )
    if( begin != 0 )
    return null
  }//end if( begin == -1 )
  else
    begin += 2
    var end = document.cookie.indexOf( ";", begin )
  if( end == -1 )
    end = dc.length
  return unescape( dc.substring( begin + prefix.length, end ) )
  }//end function GetCookie

  function loadCV() {
  data="";
  tempCTRY="";
  str=GetCookie ('IOdata');
  if (str != null) {data+=str;}
    if (data != "") {
      splitter="&";
      dataArray = data.split(splitter);
      splitPair="=";
      document.main.FNAM.value = dataArray[0].split(splitPair);
      document.main.LNAM.value = dataArray[1].split(splitPair);
      document.main.EMAL.value = dataArray[2].split(splitPair);
      tempCTRY= dataArray[3].split(splitPair);
      document.main.WHPR.options[dataArray[4].split(splitPair)].selected=true;
      parent.FNAM = document.main.FNAM.value;
      parent.LNAM = document.main.LNAM.value;
      parent.EMAL = document.main.EMAL.value;
      for(var c=0; c<document.main.CTRY.options.length; c++){
        if(document.main.CTRY.options[c].value==tempCTRY){
          document.main.CTRY.options[c].selected=true;
          break;
        }//end if
      }//end for

    }else {
      if(lang=='EN'){
        for(var c=0; c<document.main.CTRY.options.length; c++){
          if(document.main.CTRY.options[c].value=='USA'){
            document.main.CTRY.options[c].selected=true;
            break;
          }//end if
        }//end for
      }//end if
    }//end else
  }//end function loadCV

  function setCV() {
  SetCookie ('IOdata',document.main.FNAM.value+"&"+document.main.LNAM.value+"&"+document.main.EMAL.value+"&"+document.main.CTRY.options[document.main.CTRY.selectedIndex].value+"&"+document.main.WHPR.selectedIndex);
  }//end function setCV

//

  function update_body (sv1){

  if (sv1==null) sv1="";

//alert("inside update body ff is ");
//alert("number of forms is "+document.forms.length);
//alert(document.main.name);
  currCountryVal = document.main.CTRY.options[document.main.CTRY.selectedIndex].value;

  var ff=0;
//alert("moving into if's");
  if (!document.main.PRIV.checked){ff=1; alert(req_priv); document.main.PRIV.focus();}
  if (document.main.FNAM.value==""&&ff==0) { ff=1; alert(req_edt+"\n"+req_gen); window.scroll(0,0); document.main.FNAM.focus();}
  if (document.main.LNAM.value==""&&ff==0) { ff=1; alert(req_edt+"\n"+req_gen); window.scroll(0,0); document.main.LNAM.focus();}
  if (document.main.EMAL.value==""&&ff==0) { ff=1; alert(req_edt+"\n"+req_gen); window.scroll(0,0); document.main.EMAL.focus();}
  if (document.main.WHPR.options[document.main.WHPR.selectedIndex].value==""&&ff==0) { ff=1; alert(req_sel_prod+"\n"+req_gen); window.scroll(0,0);  document.main.WHPR.focus();}
  if (document.main.CTRY.options[document.main.CTRY.selectedIndex].value==""&&ff==0) { ff=1; alert(req_sel_ctry+"\n"+req_gen); window.scroll(0,0);  document.main.CTRY.focus();}
  if (document.main.EMAL.value.length>0&&(document.main.EMAL.value.indexOf("@",0)==-1
                                                         ||document.main.EMAL.value.indexOf(".",0)==-1
                                                         ||document.main.EMAL.value.indexOf(" ",0)>-1
                                                         ||document.main.EMAL.value.indexOf("!",0)>-1
                                                         ||document.main.EMAL.value.indexOf("#",0)>-1
                                                         ||document.main.EMAL.value.indexOf("$",0)>-1
                                                         ||document.main.EMAL.value.indexOf("%",0)>-1
                                                         ||document.main.EMAL.value.indexOf("&",0)>-1
                                                         ||document.main.EMAL.value.indexOf("*",0)>-1
                                                         &&ff==0)) {
      ff=1;
      alert(req_valid_email);
      window.scroll(0,0);
      document.main.EMAL.focus();
  }

  if (ff==0) {

  NEMAval="";
  NMKTval="";
  if (document.main.NEMA.checked) {NEMAval=1;}
  if (document.main.NMKT.checked) {NMKTval=1;}

  document.SendForm.body.value="";
  document.SendForm.body.value+="&MFGR="+"IOMG"
    + "&PROD="+"IOSD"
    + "&PRNM="+"Software Download"
    + "&RSrc="+"WEB"
    + "&BlVr="+"I212005MEW"
    + "&FNAM="+document.main.FNAM.value
    + "&LNAM="+document.main.LNAM.value
    + "&EMAL="+document.main.EMAL.value
    + "&LANG="+document.main.LANG.value
    + "&OSYS="+document.main.OSYS.value
    + "&SWDL="+document.main.SWDL.value
    + "&NEMA="+NEMAval
    + "&NMKT="+NMKTval
    + "&THANKSPAGE="+document.main.THANKSPAGE.value+sv1
    + "&WHPR="+document.main.WHPR.options[document.main.WHPR.selectedIndex].value
    + "&CTRY="+document.main.CTRY.options[document.main.CTRY.selectedIndex].value
    ;
//alert(document.SendForm.body.value);
   setCV();
  if(NEMAval==1 || NMKTval==1){
   sendMail();
    if (lang=='EN'){
      if(currCountryVal=='USA' || currCountryVal == 'Canada') {
        if (document.main.SWDL.value=='AUTOBACKUP'){//pep and rm_reg
          sendRmReg(document.main.FNAM.value,document.main.LNAM.value,document.main.LANG.value,document.main.EMAL.value,document.main.WHPR.value,document.main.CTRY.value);
          return true;
        } // end if (document.main.SWDL.value=='AUTOBACKUP')
      } // end if(currCountryVal=='USA' || currCountryVal == 'Canada')
    }//end if (lang=='EN')
  }//end if(NEMAval==1 || NMKTval==1)
   return true;
  } else {
   return false;
  }
}

function warnPrivacyPolicy(){
    alert(document.main.PRIV.checked);
}

function downloadHandler(ftpUrl) {
 var isSV1 = (window.navigator.userAgent.indexOf("SV1") != -1);
 if (isSV1 && (ftpUrl!=null && ftpUrl!='')) {
  //check for valid fields prior to popping downloader window
  var ff2=0;
	if (!document.main.PRIV.checked){ ff2=1; }
  if (document.main.FNAM.value==""&&ff2==0) { ff2=1; }
  if (document.main.LNAM.value==""&&ff2==0) { ff2=1; }
  if (document.main.EMAL.value==""&&ff2==0) { ff2=1; }
  if (document.main.WHPR.options[document.main.WHPR.selectedIndex].value==""&&ff2==0) { ff2=1; }
  if (document.main.CTRY.options[document.main.CTRY.selectedIndex].value==""&&ff2==0) { ff2=1; }
  if (document.main.EMAL.value.length>0&&(document.main.EMAL.value.indexOf("@",0)==-1
                                                         ||document.main.EMAL.value.indexOf(".",0)==-1
                                                         ||document.main.EMAL.value.indexOf(" ",0)>-1
                                                         ||document.main.EMAL.value.indexOf("!",0)>-1
                                                         ||document.main.EMAL.value.indexOf("#",0)>-1
                                                         ||document.main.EMAL.value.indexOf("$",0)>-1
                                                         ||document.main.EMAL.value.indexOf("%",0)>-1
                                                         ||document.main.EMAL.value.indexOf("&",0)>-1
                                                         ||document.main.EMAL.value.indexOf("*",0)>-1
                                                         &&ff2==0)) { ff2=1; }

	if (ff2==0) {
		// if no invalid fields
	  window.open(ftpUrl,'sv1PopWin','directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,width=1,height=1,top=0,left=0');
	  window.focus();
	      // append the value of "THANKSPAGE" with "?SV1=1"
	      if (navigator.appName.indexOf("Netscape",0) >= 0) {
	      	return update_body('?sv1=1');
	      } else {
	      	event.returnValue = update_body('?sv1=1');
	      }
	} else {
		// append the value of "THANKSPAGE" with "?SV1=1"
		if (navigator.appName.indexOf("Netscape",0) >= 0) {
    	return update_body('?sv1=1');
    } else {
    	event.returnValue = update_body('?sv1=1');
    }
	}
 } else {
      // leave "THANKSPAGE" unchanged
      if (navigator.appName.indexOf("Netscape",0) >= 0) {
      	return update_body();
      } else {
      	event.returnValue = update_body();
      }

 }
}
