var nhomedisplay=1;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function showpaymentinfo(nrgindex) {
switch(nrgindex)
{
case 1:
  smessage = "On submitting your order, you will be prompted to log in to your Paypal account to complete payment.";
  break;
case 2:
  smessage = "On submitting your order you will be directed to a secure page where payment can be completed using your credit card.";
  break;
case 3:
  smessage = "You will emailed with details of the bank account to which you should transfer funds.";
  break;
case 4:
  smessage = "Cheques should be made payable to Codepath Ltd.  You will emailed with the postal address to which the cheque should be forwarded.";
  break;
}
smessage = "<br>" + smessage;
if (nrgindex <3)
  document.getElementById('mail_redirect2').value = "http://www.codepath.co.uk/nonindexed/paypal-payment.htm"; <!--!!! -->
else
  document.getElementById('mail_redirect2').value = "http://www.codepath.co.uk/nonindexed/thankyou_order.htm"; <!--!!! -->

document.getElementById('tPaymentAdvice').innerHTML = smessage;
}

function wopen(url, w, h){
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  if (wleft < 0) {w = screen.width; wleft = 0;}
  if (wtop < 0)  {h = screen.height;wtop = 0;}
  var optionslist = 'width=' + w + ', height=' + h + ', location=no, menubar=no,status=no, toolbar=no, scrollbars=no, resizable=no';
  var win = window.open(url, null, optionslist);
}

function getprice() {
var pricemessage = 0;
pricemessage = Number(document.pricingcalcform.tOrdercount.value);
pricemessage = Math.max(pricemessage-200,0);
pricemessage = 1000 + (pricemessage * 4);
alert(pricemessage);
}

function showaotpricing() {
window.open("/nonindexed/web_ordertracking_pricing.htm", "aotpricing", "width=220,height=340,left=70,top=130");
}

function showaotfaq() {
window.open("/nonindexed/AOT_FAQ.htm", "aotfaq",  "scrollbars=yes,width=700,height=540,left=50,top=80");
}

function showdataflowdiagram() {
window.open("/nonindexed/dataflow.htm", "dataflow", "scrollbars=yes,width=700,height=540,left=50,top=80");
}

function spamContent(){
var sEnq = document.getElementById('tEnquiry').value.toUpperCase();  
var sEmail = document.getElementById('tEmail').value.toUpperCase();  
var nLinkCount = 0;

if (sEmail.substr(sEmail.length-3, sEmail.length) == '.RU')
  {return 1}
else  
{
  for (var ii=1;ii<=sEnq.length;ii++) {
    if (sEnq.substr(ii, 5) == 'HTTP:')
      nLinkCount++;
  }
}
if (nLinkCount>5) 
  return 2
else
  return 0;
}

function verifyfields() {
var themessage = "";

document.getElementById('mail_from').value = getadrs(1);
if (spamContent()>0){
  //document.feedbackform.action = '';
  document.getElementById('mail_to').value = 'j6ri@gy08r66fy8.com';
  return true;
} else {
  document.getElementById('mail_to').value = getadrs(2);
}

if (document.feedbackform.tName.value=="") {
themessage = themessage + "Name, ";
}
if (document.feedbackform.tEmail.value=="") {
themessage = themessage + "e-mail address, ";
}
if (document.feedbackform.tEnquiry.value=="") {
themessage = themessage + "Enquiry, ";
}

if (themessage.length > 1) {
  themessage = themessage.substr(0, themessage.length-2);
  themessage = "Please complete the following field(s): " + themessage + '.';
  alert(themessage);
  return false;
}
else
{
  if (document.feedbackform.tEmail.value != document.feedbackform.tEmailconf.value) {
    alert("The 'e-mail' and 'e-mail Confirmation' fields must match");
    return false;
  }
}
}

function verifyfields_payment() {
var themessage = "";

if (document.orderform.tName.value=="") {
themessage = themessage + "Name, ";
}
if (document.orderform.tEmail.value=="") {
themessage = themessage + "e-mail address, ";
}

//if (document.orderform.tSiteKey.value=="") {
//themessage = themessage + "Site Key/Submit Code, ";
//}

if (document.getElementById('tPaymentAdvice').innerHTML == "&nbsp;") {
  themessage = themessage + "Payment Method, ";
}

if (themessage.length > 1) {
  themessage = themessage.substr(0, themessage.length-2);
  themessage = "Please complete the following field(s): " + themessage + '.';
  alert(themessage);
  return false;
}
else
{
  if (document.orderform.tEmail.value != document.orderform.tEmailconf.value) {
    alert("The 'e-mail' and 'e-mail Confirmation' fields must match");
    return false;
  }
}
}

function getadrs(nType) {
  var ad1='';
  if (nType==1) 
    ad1='website_contact'
  else	
    ad1='enquiry'
  var ad2='@';
  var ad3='codepath'
  var ad4='.';
  var ad5='b';
  var ad6='i';
  var ad7='z';
  return ad1+ad2+ad3+ad4+ad5+ad6+ad7;
}

function test() {
var sfull = 'abc100.51';
var nqty = 3;
sfull = sfull.substr(3);
alert(((Math.round(nqty*sfull*100))/100));
}

function keepMePostedAlert(){
  alert('Please complete our contact form to be kept informed about the progress of this plug-in and be sure to tell us on the form which plug-in(s) you are interested in...');
}

function setPaymentCookie(pluginName, pluginPrice, pluginKeyType){ 
  document.cookie = 'pluginName=' + pluginName +' ; path=/';
  document.cookie = 'pluginPrice=' + pluginPrice + '; path=/';		  
  document.cookie = 'pluginKeyType=' + pluginKeyType + '; path=/';		   // site key or auth key security model
}

function getCookie ( cookie_name, defaultReturn ){
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if (results)
    return (unescape(results[2]));
  else
    return defaultReturn;
}

function setPaymentParams(){ // called on load of the plugin-buynow page to set plugin sepcific parameters for name, price and key instructions
  document.getElementById('pluginPrice').innerHTML = getCookie('pluginPrice', 149);
  document.getElementById('pluginName').innerHTML = getCookie('pluginName', 'Soapbox - Product Reviews');
  document.getElementById('tPluginNameId').value = getCookie('pluginName', 'Soapbox - Product Reviews');
  if (getCookie('pluginKeyType') == 'sitekey') {  
    document.getElementById('keyHelp').innerHTML = "the 9-digit code generated when you installed the trial, available from within the Actinic Settings option."
  } else if (getCookie('pluginKeyType') == 'authkey') {
    document.getElementById('keyHelp').innerHTML = "the 16-digit number that will either be displayed when you run the software or, if you are already using the free trial, can be generated by selecting Configure | Enter New License key from the application menu.";
  } else
    document.getElementById('keyHelp').innerHTML = "";
  if (document.getElementById('keyHelp').innerHTML != "")
    document.getElementById('keyHelp').innerHTML = "Leave blank if you have not yet installed the software. Otherwise, please enter " + document.getElementById('keyHelp').innerHTML;
  else	
    document.getElementById('keyHelp').innerHTML = "Leave blank for this plug-in";
}	

function setPaypalParams(){ // set on the onload event of the paypal-payment page to ensure the right button html is displayed as this determines the price paid.

  if (getCookie('pluginPrice', 149)==149){
      document.getElementById('codepathPaypalButton').value = "6637197"; // £149 button
  } else if (getCookie('pluginPrice', 149)==99){
      document.getElementById('codepathPaypalButton').value = "6637204"; // £99 button
  } else if (getCookie('pluginPrice', 149)==49){
      document.getElementById('codepathPaypalButton').value = "6999487"; // £49 button
  } else {
      document.getElementById('codepathPaypalButton').value = "6637197"; // £149 button - default high in case of error
  }
}

function downloadMessage(helpId){
var sMessage = "About to download:  Simply save the file to your computer then double-click it to install...";

switch (helpId){
  case 1: sMessage +=  "\n\nOnce installed, see the 'Help menu' within the software to get started."; break; // Soapbox
  case 2: sMessage +=  "\n\nOnce installed, see the 'Help menu' within the software to get started.  A 'Site Key' of TRIAL can be used for evaluation purposes."; break; // AOT 
  case 3: sMessage +=  "\n\n\** EXISTING USERS PLEASE NOTE ** If you are already using v1.x or v2.x of this plug-in, this version is a chargable upgrade at a cost of £39.  You will receive payment information when we receive your site key request the first time you run the software."; break; // Soapbox
}
sMessage += "\n\nFor free trial support, just call 0161 870 6355 or use our Contact Page.\n\n"
alert(sMessage);
}