var export_text = "\nThe FastSafePills free offer will soon expire, don't delay in getting in this special program! \n\nAll you pay is the postage to test out this potent new formula! \n";
var export_link = 'https://fastsafepills.com/order';
var exit=true;

function doExit(){
        if(exit){
                window.location.href = newloc;
                return false;
        }
}
function DontShowWin_upsell(){
	exit = false;
	return true;
}
var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 45;

var usa_ship = 12.95;

function process_contact(){
	var country = document.contact.contact_country.options[document.contact.contact_country.selectedIndex].value;
	if(country == 1){
		document.getElementById('inside').style.display = '';
		document.getElementById('outside').style.display = 'none';
	} else {
		document.getElementById('inside').style.display = 'none';
		document.getElementById('outside').style.display = '';
	}
	return true;
}
function combo_country_change(my_order_value){
        var country = document.order.order_country.options[document.order.order_country.selectedIndex].value;
	if(country == 1){
		document.getElementById('shipping_us').style.display = '';
		document.getElementById('shipping_non_us').style.display = 'none';
	} else {
		if(country == 2){
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_non_us').style.display = '';
		} else {
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_non_us').style.display = 'none';
		}
	}
}
function country_change(my_order_value){
        var country = document.order.order_country.options[document.order.order_country.selectedIndex].value;
	if(country == 1){
		document.getElementById('shipping_us').style.display = '';
		document.getElementById('shipping_non_us').style.display = 'none';
		document.order.order_shipping.selectedIndex = 0;
	} else {
		if(country == 2){
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_non_us').style.display = '';
		} else {
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_non_us').style.display = 'none';
		}
		document.order.order_shipping.selectedIndex = 1;
	}
	exchange(my_order_value);
}
function bcountry_change(my_order_value){
        var country = document.order.order_bcountry.options[document.order.order_bcountry.selectedIndex].value;
	if(country == 1){
		document.getElementById('billing_us').style.display = '';
		document.getElementById('billing_non_us').style.display = 'none';
	} else {
		if(country == 2){
			document.getElementById('billing_us').style.display = 'none';
			document.getElementById('billing_non_us').style.display = '';
		} else {
			document.getElementById('billing_us').style.display = 'none';
			document.getElementById('billing_non_us').style.display = 'none';
		}
	}
}
function aff_country_change(){
        var country = document.edit_affiliate.aff_country.options[document.edit_affiliate.aff_country.selectedIndex].value;
	if(country == 1){
		document.getElementById('shipping_us').style.display = '';
		document.getElementById('shipping_non_us').style.display = 'none';
	} else {
		if(country == 2){
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_non_us').style.display = '';
		} else {
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_non_us').style.display = 'none';
		}
	}
}

function exchange(my_order_value){
        var rate = document.order.order_currency.options[document.order.order_currency.selectedIndex].value;
        var rate_label = document.order.order_currency.options[document.order.order_currency.selectedIndex].text;
        var quantity = document.order.order_quantity.options[document.order.order_quantity.selectedIndex].value;
        var shipping = document.order.order_shipping.options[document.order.order_shipping.selectedIndex].value;
        var shipping_label = document.order.order_shipping.options[document.order.order_shipping.selectedIndex].text;

	if(shipping < 100){
		if(shipping == 1){
			document.order.order_country.selectedIndex = 0;
              		document.getElementById('shipping_us').style.display = '';
	                document.getElementById('shipping_non_us').style.display = 'none';
		} else {
			var country = document.order.order_country.options[document.order.order_country.selectedIndex].value;
			if(country == 1){
				document.order.order_country.selectedIndex = 1;
	       		        document.getElementById('shipping_non_us').style.display = '';
			} else {
				if(country == 2){
		       		        document.getElementById('shipping_non_us').style.display = '';
				} else {
		       		        document.getElementById('shipping_non_us').style.display = 'none';
				}
			}
	                document.getElementById('shipping_us').style.display = 'none';
		}
	} else {
		combo_country_change(my_order_value);
	}

	bcountry_change(my_order_value);

        var order_value = parseFloat(my_order_value*rate);
        var order_value = order_value.toFixed(2);

        element = document.getElementById("order_value");
        element.innerHTML = '<strong>'+order_value+'</strong>';

	var new_shipping = my_shipping[shipping]*rate;
	new_shipping = new_shipping.toFixed(2);

	var brokenstring=shipping_label.split(" "); 
	var new_shipping_label = brokenstring[0]+' '+brokenstring[1]+' '+brokenstring[2]+' ('+new_shipping+' '+rate_label+')';

	document.order.order_shipping.options[document.order.order_shipping.selectedIndex].text = new_shipping_label;

        var order_subtotal = order_value*quantity;
        order_subtotal = order_subtotal.toFixed(2);

        element = document.getElementById("order_subtotal");
        element.innerHTML = '<strong>'+order_subtotal+' '+rate_label+'</strong>';

        element = document.getElementById("order_shipping_l");
	element.innerHTML = '<strong>'+new_shipping_label+'</strong>';

	var order_total = parseFloat(order_subtotal);
	order_total += parseFloat(new_shipping);
	order_total = order_total.toFixed(2);

        element = document.getElementById("order_total");
        element.innerHTML = '<strong>'+order_total+' '+rate_label+'</strong>';

        if(document.order.billing[1].checked){
                document.getElementById('show_billing').style.display = '';
	        var bcountry = document.order.order_bcountry.options[document.order.order_bcountry.selectedIndex].value;

		if(bcountry > 1){
			document.order.order_bstate.selectedIndex = 0;
		}

       	} else {
               	document.getElementById('show_billing').style.display = 'none';
        }
	return true;
}
function popUp(URL) {
	left = (screen.width - 240) / 2;
	topp = (screen.height - 124) / 2;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=240,height=124,left = "+left+",top = "+topp+"');");
}
function process_affiliates(){
        var payment = document.edit_affiliate.aff_payment.options[document.edit_affiliate.aff_payment.selectedIndex].value;
	if(payment == 'paypal'){
		document.getElementById('paypal').style.display = '';
		document.getElementById('check').style.display = 'none';
	} else {
		document.getElementById('paypal').style.display = 'none';
		document.getElementById('check').style.display = '';
	}
	aff_country_change();
}
function show_billing(dis){
	document.getElementById('show_billing').style.display = dis;
}

function order(){
	var ship_state_id = document.order_form.order_ship_state.options[document.order_form.order_ship_state.selectedIndex].value;
	var ship_country_id = document.order_form.order_ship_country.options[document.order_form.order_ship_country.selectedIndex].value;
	if(ship_country_id > 1){
		document.order_form.order_ship_state.selectedIndex = 0;
		document.order_form.shipping_id.selectedIndex = 1;
		var ship_state_id = document.order_form.order_ship_state.options[document.order_form.order_ship_state.selectedIndex].value;
	} else {
		document.order_form.shipping_id.selectedIndex = 0;
	}
	if(ship_state_id > 1){
		document.order_form.order_ship_country.selectedIndex = 0;
		document.order_form.shipping_id.selectedIndex = 0;
		var ship_country_id = document.order_form.order_ship_country.options[document.order_form.order_ship_country.selectedIndex].value;
	} else {
		document.order_form.shipping_id.selectedIndex = 1;
	}
	var bill_state_id = document.order_form.order_bill_state.options[document.order_form.order_bill_state.selectedIndex].value;
	var bill_country_id = document.order_form.order_bill_country.options[document.order_form.order_bill_country.selectedIndex].value;
	if(bill_country_id > 1){
		document.order_form.order_bill_state.selectedIndex = 0;
		var bill_state_id = document.order_form.order_bill_state.options[document.order_form.order_bill_state.selectedIndex].value;
	} 
	if(bill_state_id > 1){
		document.order_form.order_bill_country.selectedIndex = 0;
		var bill_country_id = document.order_form.order_bill_country.options[document.order_form.order_bill_country.selectedIndex].value;
	} 
	var prod_id = document.order_form.product_id.options[document.order_form.product_id.selectedIndex].value;
	document.getElementById('product_price').innerHTML = prices[prod_id] + ' '+currency;
	var shipping_id = document.order_form.shipping_id.options[document.order_form.shipping_id.selectedIndex].value;
	document.getElementById('shipping_fee').innerHTML = shipping[shipping_id] + ' '+currency;
	document.getElementById('shipping_fee').innerHTML = shipping[shipping_id] + ' '+currency;
	var quantity_id = document.order_form.quantity.options[document.order_form.quantity.selectedIndex].value;
	//not ready yet
	switch(prod_id){
		case '1':
			//to be continued
			var subtotal = parseFloat(prices[prod_id]*quantity[quantity_id]);
			break;
		case '2':
			var subtotal = parseFloat(prices[prod_id]*quantity[quantity_id]);
			break;
		case '3':
			var subtotal = parseFloat((prices[1]*quantity[quantity_id])+(1*prices[2]));
			break;
		case '4':
			var subtotal = parseFloat(prices[prod_id]*quantity[quantity_id]);
			break;
		case '5':
			var subtotal = parseFloat((prices[1]*quantity[quantity_id])+(1*prices[4]));
			break;
	}
	var total =  parseFloat((1*subtotal) + (1*shipping[shipping_id]));
	if(subtotal < 100){
		var tval = subtotal+'';
		tval = tval.substring(0,5);
		if(tval.length < 5){
			tval += '0';
		}
	} else {
		var tval = subtotal+'';
		tval = tval.substring(0,6);
		if(tval.length < 6){
			tval += '0';
                }
        }
	subtotal = tval;
	if(total < 100){
		var tval = total+'';
		tval = tval.substring(0,5);
		if(tval.length < 5){
			tval += '0';
		}
	} else {
		var tval = total+'';
		tval = tval.substring(0,6);
		if(tval.length < 6){
			tval += '0';
                }
        }
	total = tval;
	document.getElementById('subtotal').innerHTML = subtotal + ' '+currency;
	document.getElementById('total').innerHTML = total + ' '+currency;
	if(document.order_form.billing[1].checked){
		document.getElementById('show_billing').style.display = '';
	} else {
		document.getElementById('show_billing').style.display = 'none';
	}
}

function disableSubmit(whichButton)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        document.getElementById(whichButton).disabled = true;
    }
    else if (document.all)
    {
        // this is the way old msie versions work
        document.all[whichButton].disabled = true;
    }
    else if (document.layers)
    {
        // this is the way nn4 works
        document.layers[whichButton].disabled = true;
    }
}

function verifyform(frm){
	return true;
}

function loadme(){
        var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
        var nso = isInternetExplorer ? document.all.signature : document.signature;
        if (nso){
                nso.setVariable('loadpoints', '0');
        }
}

function test(){
        var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
        var f = isInternetExplorer ? document.all.order : document.order;
        var nso = isInternetExplorer ? document.all.signature : document.signature;
        f.points.value = nso.GetVariable('points');
}

function checkUsername()
{
	document.getElementById('initial_fname_error').style.display = 'none';
	var username = document.getElementById('username').value;
	var ok = username.match(/^[a-zA-Z0-9_]{4,16}$/);
	
	if (ok)
	{
		popUp('check.php?user=' + username );
	}
	else
	{
		alert('Username should be 4-16 characters long, letters, numbers and underscores only');
	}
}

function searchValidate()
{
	var value = document.getElementById('search-anything').value;
	if (value != 'Search Anything' && value.length > 0) 
	{
		return true;
	}
	else
	{
		alert('Please input a keyword'); 
		return false;
	};
}
