function loadvideo()
  {
  var so = new SWFObject("http://www.wellenex.com/Videos/player.swf", "wellenex", "268", "180", "9", "#ffffff");
  so.addVariable("quality", "high");
  so.addVariable("duration", "1800");
  so.addVariable("bufferlength", "5");
  so.addVariable("fullscreen", "true");
  so.addVariable("screencolor", "#000000");
  so.addVariable("scale", "noscale");
  so.addVariable("file", "http://www.wellenex.com/Videos/wellenex_newvideo.flv");
  //so.addVariable("image", "imgurl");
  so.addVariable("wmode", "transparent");
  so.addVariable("allowScriptAccess", "always");
  so.addVariable("type", "video");
  so.addVariable("stretching", "uniform");
  //so.addVariable("skin", "skinurl");
  so.addVariable("pluginspage", "http://www.macromedia.com/go/getflashplayer");
  so.addVariable("autostart", "true");

  so.write("videos");
  }
  


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function changeValues(obj) {
	var ship_container = document.getElementById("ship_container");
	if(!obj.checked) 
	  {
		ship_container.style.display="block";
	  }
	 else{ ship_container.style.display="none";}
}

function validateForm(thisform) {
	var return_status	= true;
	var field_names		= {	fname: "first name", surname: "surname", fname_ship: "first name (shipping)", surname_ship: "surname (shipping)", 
					address1_ship: "address1 (shipping)", city_ship: "city (shipping)", county_ship: "county (shipping)", postal_ship: "postal (shipping)", 
					 email_ship: "email (shipping)", cnumber: "card number", month: "expiration month", 
					phone_ship: "phone (shipping)", year: "expiration year", type: "card type" };
	var required_input_ids	= ['fname', 'surname', 'address1', 'city', 'county', 'postal', 'email', 'phone','type','cnumber', 'cvc2','month','year' ];
	var shipsame		= document.getElementById('shipsame');
	var errors		= [];

	if(shipsame && !shipsame.checked) 	        	
		required_input_ids = required_input_ids.concat( [ 'fname_ship', 'surname_ship', 'address1_ship', 'city_ship', 'county_ship', 'postal_ship',  'email_ship', 'phone_ship'] );

	var required_inputs = required_input_ids.length;
	
	for(var idx=0; idx < required_inputs; idx++) {
		var e = document.getElementById(required_input_ids[idx]);

		//select inputs
		if( !e || ( (required_input_ids[idx] == 'country' || required_input_ids[idx] == 'country_ship' || 
		    required_input_ids[idx] == 'type' || required_input_ids[idx] == 'month' || 
		    required_input_ids[idx] == 'year') && !e.options[e.selectedIndex].value ) || !e.value
		) 
			errors.push(required_input_ids[idx]);

	}

	var error_msg = "Please make sure you fill out all required fields, including: \n\n";
	if(errors.length > 0) {
		return_status = false;
		
		var errors_length = errors.length;
		for(var idx=0; idx < errors_length; idx++)
			if(field_names[errors[idx]])
				error_msg += field_names[errors[idx]] + "\n";
			else
				error_msg += errors[idx] + "\n";

		window.alert(error_msg);	
	}	


	return return_status;
}

var xmlHttp = null;
function billingsameasshipping() {
	var billing_input_ids	= ['bill_first_name', 'bill_surname', 'bill_address1','bill_city', 'BILL_county', 'bill_postal', 'BILL_COUNTRY' ];
	var shipping_input_ids	= ['ship_first_name', 'ship_surname', 'ship_address1','ship_city', 'SHIP_county', 'ship_postal', 'SHIP_COUNTRY' ];
	var shipping_urlvars	= '';
	var sameflag		= document.getElementById('billisship');
	
	if( sameflag && sameflag.checked ) {
		var num_of_fields = shipping_input_ids.length;

		for(var idx=0; idx < num_of_fields; idx++)
			if(idx == 5 || idx == 7) {
				document.getElementById(billing_input_ids[idx]).selectedIndex = document.getElementById(shipping_input_ids[idx]).selectedIndex;
				shipping_urlvars += '&' + shipping_input_ids[idx] + '=' + 
						  document.getElementById(shipping_input_ids[idx]).options[document.getElementById(shipping_input_ids[idx]).selectedIndex].value;
			}
			else {
				document.getElementById(billing_input_ids[idx]).value = document.getElementById(shipping_input_ids[idx]).value;		
				shipping_urlvars += "&" + shipping_input_ids[idx] + "=" + document.getElementById(shipping_input_ids[idx]).value;

			}	
			
	}

	var shipping_method	= '';
	var form_inputs	= document.getElementsByTagName('input');
	form_inputs_length = form_inputs.length;

	for(var idx=0; idx < form_inputs_length; idx++) {
		if(form_inputs[idx].type == 'radio' && form_inputs[idx].name == 'shipping_menu[0_customer]' )
			shipping_method = form_inputs[idx].value;		

	}

	var return_status = false;

	var phone = document.getElementById('phone');
	var email = document.getElementById('emails');
	var pf = document.getElementById('payment_form');

	if(!email || email.value == '' || email.value.length <= 0) {
		window.alert('Invalid email.');

		return false;		

	}	

	if( pf && phone && phone.value.length > 0 && phone.value != '') {

		if(!document.getElementById('email') ) {
			var dobj	= new Date();
			var e_el	= document.createElement('input');

			e_el.setAttribute('id', 'email');
			e_el.setAttribute('name', 'email');
			e_el.setAttribute('type', 'hidden');
			e_el.value	= phone.value + '_' + dobj.getTime() + '@lash28.co.uk';

			var ec_el	= document.createElement('input');
			ec_el.setAttribute('name', 'email_confirm');
			ec_el.setAttribute('type', 'hidden');
			ec_el.value	= e_el.value;

			var p_el	= document.createElement('input');
			p_el.setAttribute('name', 'password');
			p_el.setAttribute('type', 'hidden');
			
			var pc_el	= document.createElement('input');
			pc_el.setAttribute('name', 'password_confirm');
			pc_el.setAttribute('type', 'hidden');

			p_el.value	= pc_el.value = phone.value;

			pf.appendChild(e_el);
			pf.appendChild(ec_el);	
			pf.appendChild(p_el);
			pf.appendChild(pc_el);

		}
		
		//ajax products into the the basket
		xmlHttp=GetXmlHttpObject();  
		
		if (xmlHttp==null) {
			alert ("Error: please use the store to make your order");
			window.location = '/store';

		}
		else {
			var qty		= document.getElementById('the_qty');
			var detox_prod	= document.getElementById('beauty_program'); 
			var extra_prod	= (detox_prod && detox_prod.checked)?'Y':'N';

			if(qty && qty.value > 0) {
				xmlHttp.onreadystatechange=function(){
					if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
						document.getElementById('payment_form').submit(); 
				
				}

				xurl = "/include/ajax_basket.php?qty=" + qty.value + "&extra=" + extra_prod + "&ue=" + email.value + shipping_urlvars + '&sm=' + shipping_method;

				xmlHttp.open("GET", xurl,true); 
				xmlHttp.send(null);
					
				return_status = true;

			}
			else
				window.alert('Invalid quantity specified');


		}

	}
	else 
		window.alert('invalid phone number');


	return false;	

}

