var vsuite4 = 34.95;
var vsuite3 = 17.95;
var vcal = 9.95;
var vclk = 9.95;
var vsld = 9.95;
var vsch = 26.95;

var errorstr = 'Please specify a quantity.\n\nQuantities greater than 1 will automatically qualify for pricing discounts!';

function GetSign(c){
  var s = '';
  switch(c) {
  case "USD": {s='$ '; break}
  case "GBP": {s='£ '; break}
// code for euro  case "EUR": {s='&#128; '; break}
  case "EUR": {s='€ '; break}
  case "CAD": {s='C$ '; break}
  case "JPY": {s='&yen; '; break}
  case "CHF": {s='SFr '; break}
  case "AUD": {s='A$ '; break}
  case "ARP": {s='Peso '; break}
  case "BRL": {s='Real '; break}
  case "CNY": {s='Yuan '; break}
  case "DKK": {s='Dkr '; break}
  case "HKD": {s='HK$ '; break}
  case "HUF": {s='Forint '; break}
  case "IDR": {s='Rupiah '; break}
  case "ILS": {s='Shekel '; break}
  case "MYR": {s='M$ '; break}
  case "MXP": {s='Peso '; break}
  case "NZD": {s='NZ$ '; break}
  case "PLZ": {s='Zloty '; break}
  case "RUR": {s='Rouble '; break}
  case "SGD": {s='s$ '; break}
  case "ZAR": {s='Rand '; break}
  case "SEK": {s='Skr '; break}
  case "TWD": {s='NT$ '; break}
  case "THB": {s='Baht '; break}
  default: s=''
  }
  return s;
}

function qchg (ctl){

  switch(ctl.name) {
  case "psuite4q": {p = vsuite4; o = psuite4t; break}
  case "psuite3q": {p = vsuite3; o = psuite3t; break}
  case "pcalq": {p = vcal; o = pcalt; break}
  case "pclkq": {p = vclk; o = pclkt; break}
  case "psldq": {p = vsld; o = psldt; break}
  case "pschq": {p = vsch; o = pscht; break}
  }
  
  q = parseInt(ctl.value, 10);

  if ( isNaN(q) ){
	ctl.value = 1;
	q = 1;
    alert (errorstr);
	}
  
  pct = GetQDisc (q);

  if (q > 1) {
  //  alert(dstr);
	}
    
  o.innerHTML = GetSign(c) + (CorrectPrices(c, v, q * p * pct, 'val'));
  return false;

  }

function GetQDisc (q){
  if(q == 1){ pct = 1 }
  else if(q > 1 && q < 6){ pct = .85 }
  else if(q > 5 && q < 10){ pct = .73 }
  else if(q > 9 && q < 25){ pct = .67 }
  else if(q > 25 && q < 50){ pct = .64 }
  else if(q > 50){ pct = .60 }
  else{ pct = 0 }
  return pct;
}  
  
function gobuy (ctl){

  switch(ctl) {
  case "psuite4q": {p = vsuite4; id='4752suite4'; d='VB Source Code Suite 4'; break}
  case "psuite3q": {p = vsuite3; id='4752suite3'; d='VB Source Code Suite 3'; break}
  case "pcalq": {p = vcal; id='4752cldr16'; d='VB Calendar Control v1.6'; break}
  case "pclkq": {p = vclk; id='4752clck12'; d='VB Clock Control v1.2'; break}
  case "psldq": {p = vsld; id='4752sldr11'; d='VB Slider Control v1.1'; break}
  case "pschq": {p = vsch; id='4752schd20'; d='VB Scheduler Control v2.0'; break}
  }

//  q = parseInt(ctl.value, 10);

//  if ( o.innerHTML.lastIndexOf(" 0.00") )  {
//    qchg(ctl);
//  }
  
//  if ( isNaN(q) || q == 0){
//    alert(errorstr);
//    }
//  else {
//    location.href="checkout.php?c="+c+"&v="+v+"&id="+id+"&desc="+escape(d)+"&q=1"
    location.href="https://www.wolfebyte.com/checkout.php?c="+c+"&v="+v+"&id="+id+"&desc="+escape(d)+"&q=1"
//  }

}


function CorrectPrices(local_cur, cur_var, thisvalue, flg){
    var dec = true;

    if(!thisvalue) {
	thisvalue = 0
    }

    var nvalue=thisvalue
    if (1 * nvalue == nvalue) {
    nvalue = eval(nvalue)

    var lvalue = nvalue * cur_var

    if (dec) {
    	nvalue = (Math.round(nvalue * 100)) / 100
    	lvalue = (Math.round(lvalue * 100)) / 100

    	if (Math.floor(nvalue) == nvalue) {
  	    nvalue = nvalue + '.00'
    	} else if (Math.floor(nvalue*10) == (nvalue*10)) {
  	    nvalue = nvalue + '0'
    	}
    	if (Math.floor(lvalue) == lvalue) {
  	    lvalue = lvalue + '.00'
    	} else if (Math.floor(lvalue*10) == (lvalue*10)) {
  	    lvalue = lvalue + '0'
    	}
    } else {
	nvalue = Math.round(nvalue)
	lvalue = Math.round(lvalue)
    }

    if (cur_var != 1) {
	nvalue = '<nobr>' + lvalue + ' ' + local_cur + ' </nobr>'
    } else {
	nvalue = c + nvalue
    }
    }
	
	if (flg == 'val'){
      nvalue = lvalue;
	}
	
    return nvalue
}

function validate_form(btn) {

      if (document.custForm.f_strFirstName.value == "")
         {
         alert("Please enter your First/Given name.");
         document.custForm.f_strFirstName.focus();
         return false;
         }
      else if (document.custForm.f_strLastName.value == "")
         {
         alert("Please enter your Last/Sir name.");
         document.custForm.f_strLastName.focus();
         return false;
         }
      else if (document.custForm.f_strAddress1.value == "")
         {
         alert("Please enter your Address.");
         document.custForm.f_strAddress1.focus();
         return false;
         }
      else if (document.custForm.f_strCity.value == "")
         {
         alert("Please enter your City.");
         document.custForm.f_strCity.focus();
         return false;
         }
      else if (document.custForm.f_strRegion.value == "")
         {
         alert("Please enter your State, Region, or Province.");
         document.custForm.f_strRegion.focus();
         return false;
         }
      else if (document.custForm.f_strPostalCode.value == "")
         {
         alert("Please enter your Postal Code.");
         document.custForm.f_strPostalCode.focus();
         return false;
         }
      else if (document.custForm.f_strCountry.value == "")
         {
         alert("Please enter your Country.");
         document.custForm.f_strCountry.focus();
         return false;
         }
      else if (document.custForm.f_strPhone.value == "")
         {
         alert("Please enter your Phone Number.");
         document.custForm.f_strPhone.focus();
         return false;
         }
      else if ((document.custForm.f_strEmail.value == "") ||
               (!document.custForm.f_strEmail.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi)))
         {
         alert("Please enter a valid Email Address.\n\nThe password to unzip the Source Code file will be delivered to the email address you provide here.");
         document.custForm.f_strEmail.focus();
         return false;
         }
      else if (btn != "paypal" && document.custForm.csc.value == "")
         {
         alert("Please enter the CSC or CVV2 number located on the back of your card.");
         document.custForm.csc.focus();
         return false;
         }
      else if (btn != "paypal" && !check_card(document.custForm.cn.value)) {
	  	 alert('The credit card number provided appears to be invalid.\n\nPlease check and try again.');
         return false;
		 }		
//	  else if (get_cookie('DC') == 'yes') {
//		 if (!confirm('You have used a Diners Club card - a surcharge of 4% will be added to your order.\n\nDo you want to continue with the order?')) {
//		    ret = false
//		}

    if (btn != "paypal") {
       if (document.custForm.ordercc.value == "Pay via Credit Card"){
	     alert("Please do one final check to make sure all information is\ncorrect - and remember - you must supply a valid email\naddress in order to receive the password to unlock your\nsource code file!\n\nWhen ready - press the \"Submit Credit Card Order\" button\nto complete your order and begin credit card processing.\n");
		 document.custForm.ordercc.value = "Submit Credit Card Order";
		 document.custForm.ordercc.disabled = false;
		 document.custForm.ordercc.focus();
		 return false;
		 }
	  else {
		document.custForm.ordercc.disabled = true;
		return true;
		}
    }
    else {return true;}
}


function reset_submit(){
		document.custForm.ordercc.value = "Pay via Credit Card";
		document.custForm.ordercc.disabled = false;
}


function check_card (st) {
    var sum = 0
    var mul = 1
    var l = st.length

    if (l > 19) { return true } else if (l < 5) { return false }

//    var dc = st.substring(0,2)
//    if (dc == '30' || dc == '36' || dc == '38') {
//	set_cookie('DC', 'yes')
//    } else {
//	set_cookie('DC', '')
//    }

    for (var i = 0; i < l; i++) {

	digit = st.substring(l-i-1,l-i)
	tproduct = parseInt(digit ,10) * mul
	if (tproduct >= 10) {
	    sum += (tproduct % 10) + 1
	} else {
	    sum += tproduct
	}
	if (mul == 1) {
	    mul++
	} else {
	    mul--
	}
    }

    if ((sum % 10) == 0) {
	return (true)
    } else {
	return (false)
    }
}

function submitPayPal(){
  document.custForm.action="send_paypal.php";
  //custForm.cn.value = "55555555555555555555";
  if (validate_form('paypal')){ document.custForm.submit() }
}

function dscmsg(){
  alert('Due to address validation requirements, orders placed with Discover Cards are\nprocessed manually by our Credit Card processor.\n\nThis can create a delay in the processing of your order and Orders placed on a\n weekend or holiday will be processed during the next regular business day.');
}
