function popaway(){
window.close();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function embedObject(flash_file, width, height) {
	document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"'+width+'\" height=\"'+height+'\">' +
	'    <param name=\"movie\" value=\"'+flash_file+'\" />' +
	'    <param name=\"quality\" value=\"high\" />' +
	'	 <param name=\"wmode\" value=\"transparent\" />' +
	'    <embed src=\"'+flash_file+'\" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"'+width+'\" height=\"'+height+'\"></embed>' +
	'  </object>');
}

function validateCart() {

    total = parseInt($('#quantity1').val()) + parseInt($('#quantity2').val()) + parseInt($('#quantity3').val());
    
    if (total>0) {
        $('#add_cart').submit();
    } else {
        alert('Please select at least one product to add to your cart.');        
    }
}

function validateCartSingleItem(item) {

    total = parseInt($(item).val());
    
    if (total>0) {
        $('#add_cart').submit();
    } else {
        alert('Please select at least one product to add to your cart.');        
    }
}

function validateContact() {
    
    valid_email_reg =  /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if (document.contact.name.value == 'Contact Name *' || document.contact.name.value == '') {
        alert('Please enter your name.');
    } else if (document.contact.number.value == 'Contact Number *' || document.contact.number.value == '') {
        alert('Please enter your number.');
    } else if (valid_email_reg.test(document.contact.email.value) == false) {
        alert('Please enter a valid email address.');
    } else if (document.contact.enquiry.value == 'Question *' || document.contact.enquiry.value == '') {
        alert('Please enter your comments.');
    } else {
        document.contact.submit();
    }
}

function validateReview() {
    
    valid_email_reg =  /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if (document.freview.name.value == 'Contact Name *' || document.freview.name.value == '') {
        alert('Please enter your name.');
    } else if (document.freview.number.value == 'Contact Number *' || document.freview.number.value == '') {
        alert('Please enter your number.');
    } else if (valid_email_reg.test(document.freview.email.value) == false) {
        alert('Please enter a valid email address.');
    } else if (document.freview.enquiry.value == 'Review *' || document.freview.enquiry.value == '') {
        alert('Please enter your Review.');
    } else {
        document.freview.submit();
    }
}

function validateSnoringStory() {
    
    valid_email_reg =  /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if (document.snoringstoryform.name.value == 'Name *' || document.snoringstoryform.name.value == '') {
        alert('Please enter your name.');
    } else if (valid_email_reg.test(document.snoringstoryform.email.value) == false) {
        alert('Please enter a valid email address.');
    } else if (document.snoringstoryform.enquiry.value == 'Your Snoring Story *' || document.snoringstoryform.enquiry.value == '') {
        alert('Please enter your snoring story.');
    } else if (document.snoringstoryform.terms.checked == false) {
        alert('Please accept the terms and conditions.');
    } else {
        document.snoringstoryform.submit();
    }
}

function validate_forgotten_password(form) {
    valid_email_reg =  /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    
    if (valid_email_reg.test(document.verification.email.value) == false) {
        alert('Please enter a valid email address.');	
    } else if(document.verification.img_text.value == "Verification *" ){
		alert("Please type in the verification code.");			
	}else{
		document.verification.submit();
	}
}

function printWindow(orientation) {
	alert('Please set your printer orientation to ' + orientation + ' and your paper size to A4.');
	window.print();
}

function AjaxDeleteSession(id, msg){
	$.post('/ajax/delsess/'+id+'/', function(data){
		if(data != 'none'){
			alert(data);
		}
	});
}
function updateBillingInfo() {
    if ($('#billing-is-shipping').is(':checked')) {
        $('#id_billing_name').val($('#id_shipping_name').val());
        $('#id_billing_address').val($('#id_shipping_address').val());
        $('#id_billing_city').val($('#id_shipping_city').val());
        $('#id_billing_state').val($('#id_shipping_state').val());
        $('#id_billing_zip').val($('#id_shipping_zip').val());
        $('#id_billing_country').val($('#id_shipping_country').val());
    } else {
        $('#id_billing_name').val('');
        $('#id_billing_address').val('');
        $('#id_billing_city').val('');
        $('#id_billing_state').val('');
        $('#id_billing_zip').val('');
        $('#id_billing_country').val('');
    }
}
