function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval("location.href='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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 auto_off(){
document.getElementById("searchterm").setAttribute( "autocomplete", "off" );
}

function validate_form(){
    valid = true;
	messageout = "Please fill in the following fields:";

    if ( document.checkoutform.CustomerEmail.value == "" ){
        messageout = messageout+" email address,";
        valid = false;
    }

	if ( document.checkoutform.CustomerName.value == "" ){
        messageout = messageout+" name,";
        valid = false;
    }

	if ( document.checkoutform.deliveryaddress1.value == "" ){
        messageout = messageout+" delivery address,";
        valid = false;
    }

	if ( document.checkoutform.deliverycity.value == "" ){
        messageout = messageout+" city,";
        valid = false;
    }

	if ( document.checkoutform.deliverycounty.value == "" ){
        messageout = messageout+" county,";
        valid = false;
    }

	if ( document.checkoutform.DeliveryPostCode.value == "" ){
        messageout = messageout+" delivery postcode,";
        valid = false;
    }

	if ( document.checkoutform.ContactNumber.value == "" ){
        messageout = messageout+" contact number";
        valid = false;
    }

	while (1) {
    if (messageout.substring(messageout.length - 1, messageout.length) != ",")
      break;
    messageout = messageout.substring(0, messageout.length - 1);
    }

	if(valid==false){
	alert ( messageout );
	}

return valid;
}





function update_pcountry(sval){
document.checkoutform.pcountrydrop.value == document.cartform.countrydrop.value;
}

function update_cardcharge(sval){
document.checkoutform.pcardcharge.value == document.cartform.cardcharge.value;
}



function hideTracks(){
  document.getElementById("tracksdiv").style.overflow="hidden";
  document.getElementById("moretracksdiv").style.visibility="visible";
}



function showTracks(){
  document.getElementById("tracksdiv").style.overflow="visible";
  document.getElementById("moretracksdiv").style.visibility="hidden";
}

function show_bundle_contents(div_id){
  if(document.getElementById("bundle_"+div_id+"_details").style.display=="block"){
	  document.getElementById("bundle_"+div_id+"_details").style.display="none";
  }else{
  document.getElementById("bundle_"+div_id+"_details").style.display="block";
  }
}
  

function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
		document.getElementById("moretracksdiv").style.display="";
		document.getElementById("lesstracksdiv").style.display="none";
	}else{
		el.style.display = '';
		document.getElementById("moretracksdiv").style.display="none";
		document.getElementById("lesstracksdiv").style.display="";
	}
}



function shipping_country_switch(cart_id,logged_in){
	
	//write the structure if necessary
	if (window.XMLHttpRequest){
	// code for IE7+, Firefox, Chrome, Opera, Safari
  	xmlhttp_country=new XMLHttpRequest();
  	}else{
	// code for IE6, IE5
  	xmlhttp_country=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	xmlhttp_country.onreadystatechange=function(){
  		if(xmlhttp_country.readyState==4 && xmlhttp_country.status==200){
			
		var return_parts = xmlhttp_country.responseText.split('|');
		var shipping_total = return_parts[0];
		var final_total = return_parts[1];
		var sub_total = return_parts[2];
		
		var shipping_tag = 'Shipping';
		if(selected_country == 'United Kingdom'){
			shipping_tag = 'Shipping (UK)';
		}
		
    	document.getElementById('shipping_display').innerHTML=shipping_total;
		document.getElementById('box_shipping_total').innerHTML=shipping_total;
		document.getElementById('box_shipping_tag').innerHTML=shipping_tag;
		document.getElementById('final_total').innerHTML=final_total;
		document.getElementById('box_total-price').innerHTML=sub_total;

		document.getElementById('checkout_button_div').innerHTML=sub_total;
		
		}
  	}

var selected_country = document.getElementById('country').value;
xmlhttp_country.open("GET","shipping_country_switch.php?c="+selected_country+"&cart_id="+cart_id,true);
xmlhttp_country.send();

}




function toggle_row(whichLayer) {
if(document.getElementById(whichLayer).style.display == "none"){
document.getElementById(whichLayer).style.display = "table-row";
}else{
document.getElementById(whichLayer).style.display = "none";
}
}

function toggle_div(whichLayer) {
if(document.getElementById(whichLayer).style.display == "block"){
document.getElementById(whichLayer).style.display = "none";
}else{
document.getElementById(whichLayer).style.display = "block";
}
}

function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}

document.onkeypress = stopRKey;


function clear_search(thefield){
if (thefield.defaultValue==thefield.value){
thefield.value = "";
thefield.style.color = "#333333";
}
}
function fade_search(thefield){
if (thefield.value==""){
thefield.value = thefield.defaultValue;
}
thefield.style.color = "#A7A7A7";
}


function toggle_notes(cat){
	if(document.getElementById("status_notes_" + cat).value == "closed"){
	document.getElementById("target_notes_" + cat).innerHTML=document.getElementById("fullnotes_" + cat).value;
	document.getElementById("more_notes_link_" + cat).innerHTML="<a href=\"#\" onclick=\"toggle_notes('" + cat + "'); return false;\">...hide full notes</a>";
	document.getElementById("status_notes_" + cat).value="open";
	}else{
	document.getElementById("target_notes_" + cat).innerHTML=document.getElementById("shortnotes_" + cat).value;
	document.getElementById("more_notes_link_" + cat).innerHTML="<a href=\"#\" onclick=\"toggle_notes('" + cat + "'); return false;\">...read full notes</a>";
	document.getElementById("status_notes_" + cat).value="closed";
	}
}

function toggle_moretracks(){
	if(document.getElementById("status_tracks").value == "closed"){
		
	document.getElementById("toggle_tracks_div").innerHTML="<a href=\"javascript:toggle_moretracks();\" id=\"show_more_tracks\">...hide tracks</a>";
	document.getElementById("hidden_tracks").style.display = "block";
	document.getElementById("status_tracks").value="open";
	
	}else{
		
	document.getElementById("toggle_tracks_div").innerHTML="<a href=\"javascript:toggle_moretracks();\" id=\"show_more_tracks\">...show all tracks</a>";
	document.getElementById("hidden_tracks").style.display = "none";
	document.getElementById("status_tracks").value="closed";
	
	}
}


function toggle_reviews(cat,more_reviews){
	if(document.getElementById("status_reviews_" + cat).value == "closed"){
	document.getElementById("target_reviews_" + cat).innerHTML=document.getElementById("fullreviews_" + cat).value;
	document.getElementById("more_reviews_link_" + cat).innerHTML="<a href=\"#\" onclick=\"toggle_reviews('" + cat + "','"+more_reviews+"'); return false;\">...close reviews</a>";
	document.getElementById("status_reviews_" + cat).value="open";
	}else{
	document.getElementById("target_reviews_" + cat).innerHTML=document.getElementById("shortreviews_" + cat).value;
	document.getElementById("more_reviews_link_" + cat).innerHTML="<a href=\"#\" onclick=\"toggle_reviews('" + cat + "','"+more_reviews+"'); return false;\">...and "+more_reviews+" more reviews</a>";
	document.getElementById("status_reviews_" + cat).value="closed";
	}
}





function toggle_permalink(){
if(document.getElementById("permalink_display").style.display == "block"){
document.getElementById("permalink_display").style.display = "none";
document.getElementById("permalink_display_link").style.display = "none";
}else{
	
document.getElementById('permalink_field').value='Loading...';

//set the permalink
var permalink = document.getElementById('current_permalink').value;

//write the structure if necessary
	if (window.XMLHttpRequest){
	// code for IE7+, Firefox, Chrome, Opera, Safari
  	xmlhttp_permalink=new XMLHttpRequest();
  	}else{
	// code for IE6, IE5
  	xmlhttp_permalink=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	xmlhttp_permalink.onreadystatechange=function(){
  		if(xmlhttp_permalink.readyState==4 && xmlhttp_permalink.status==200){
    	document.getElementById('permalink_field').value=xmlhttp_permalink.responseText;
    	}
  	}

xmlhttp_permalink.open("GET","get_bitly_link.php?permalink="+permalink,true);
xmlhttp_permalink.send();

document.getElementById("permalink_display").style.display = "block";
document.getElementById("permalink_display_link").style.display = "block";
}
}






function toggle_box(whichLayer) {
if(document.getElementById(whichLayer).style.display == "block"){
document.getElementById(whichLayer).style.display = "none";
}else{
document.getElementById(whichLayer).style.display = "block";
}
}
























function add_to_box(store_id,cart_id,product_uid,unit_price){	

document.getElementById('box').innerHTML="<div align=center><img src=\"/images/loading_small.gif\" style=\"margin-top:20px;\"></div>";

//write the structure if necessary
	if (window.XMLHttpRequest){
	// code for IE7+, Firefox, Chrome, Opera, Safari
  	xmlhttp=new XMLHttpRequest();
  	}else{
	// code for IE6, IE5
  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	xmlhttp.onreadystatechange=function(){
  		if(xmlhttp.readyState==4 && xmlhttp.status==200){
    	document.getElementById('alert_div').style.bottom=0;
    	document.getElementById('box').innerHTML=xmlhttp.responseText;
		setTimeout('moveDiv();',1400);
    	}
  	}

xmlhttp.open("GET","/modify_cart.php?cart_id="+cart_id+"&product_uid="+product_uid+"&store_id="+store_id+"&unit_price="+unit_price+"&action=add",true);
xmlhttp.send();

//end
}


function remove_from_box(cart_product_uid,cart_id){	

document.getElementById('box').innerHTML="<div align=center><img src=\"/images/loading_small.gif\" style=\"margin-top:20px;\"></div>";

//write the structure if necessary
	if (window.XMLHttpRequest){
	// code for IE7+, Firefox, Chrome, Opera, Safari
  	xmlhttp=new XMLHttpRequest();
  	}else{
	// code for IE6, IE5
  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	xmlhttp.onreadystatechange=function(){
  		if(xmlhttp.readyState==4 && xmlhttp.status==200){
    	document.getElementById('box').innerHTML=xmlhttp.responseText;
    	}
  	}

xmlhttp.open("GET","modify_cart.php?cart_id="+cart_id+"&cart_product_uid="+cart_product_uid+"&action=remove",true);
xmlhttp.send();

//end
}





function getX( oElement ){
var iReturnValue = 0;
elementid=document.getElementById(oElement)
while( elementid != null ){
iReturnValue += elementid.offsetLeft;
elementid = elementid.offsetParent;
}
return iReturnValue;
}

function getBottom( oElement ){
var iReturnValue = 0;
elementid=document.getElementById(oElement)
while( elementid != null ){
iReturnValue += (elementid.offsetTop + 9);
elementid = elementid.offsetParent;
}
return iReturnValue;
}

function get_suggestions(str,unfiltered,store_id,obj_id){
	
if (str.length==0){ 
  document.getElementById("searchsuggest").innerHTML="";
  document.getElementById("searchsuggest").style.border="0px";
  document.getElementById("searchsuggest").style.display="none";
  return;
  }

if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }else{
// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200){
	if(xmlhttp.responseText.length>0){
    document.getElementById("searchsuggest").style.left=(getX('searchterm'))+'px';
    document.getElementById("searchsuggest").style.top=(getBottom('searchterm')-10)+'px';
    document.getElementById("searchsuggest").style.border="1px solid #A5ACB2";
	document.getElementById("searchsuggest").style.display="block";
	document.getElementById("searchsuggest").style.zIndex="99";
    document.getElementById("searchsuggest").innerHTML=xmlhttp.responseText;
	}
    }
  }

xmlhttp.open("GET","/searchsuggest_ff.php?q="+str+"&unfiltered="+unfiltered+"&store_id="+store_id+"&obj_id="+obj_id,true);
xmlhttp.send();
}





document.onclick=check; 

function check(e){ 
var target = (e && e.target) || (event && event.srcElement); 
var obj = document.getElementById('searchsuggest'); 
var obj2 = document.getElementById('sho'); 
checkParent(target)?obj.style.display='none':null; 
target==obj2?obj.style.display='block':null; 
} 

function checkParent(t){ 
while(t.parentNode){ 
if(t==document.getElementById('searchsuggest')){ 
return false 
} 
t=t.parentNode 
} 
return true 
}














function check_player_is_loaded() {
	if(document.getElementById("player_is_loaded").value == 1){
	return true;
	}else{
	return false;
	}
}



function play_item(cat,track_number,track_artist,album_artist,track_title,album_title,label,action,album_only,is_digi,cart_id,store_id,is_verified,fobj,store_string) {
	
	l_url = '/player.php';
	l_windowName = 'player_window';

  if ( typeof play_item.winrefs == 'undefined' ){
    play_item.winrefs = {};
  }


  if ( typeof play_item.winrefs[l_windowName] == 'undefined' || play_item.winrefs[l_windowName].closed ){
	  
	//make sure the player_is_loaded formvar is 0
	document.getElementById("player_is_loaded").value = 0;
	
//if window isn't open, open it
    var l_width = 297;
    var l_height = 500;

    var l_params = 'status=0' +
                   ',resizable=1' +
                   ',scrollbars=1' +
                   ',width=' + l_width +
                   ',height=' + l_height +
                   ',left=50' +
                   ',top=50';
				   

	//open it properly
    play_item.winrefs[l_windowName] = window.open('', l_windowName, l_params);
	
  	if(play_item.winrefs[l_windowName].document.getElementById("lighthouse") != null){
		//fine
	}else{
	play_item.winrefs[l_windowName] = window.open(l_url, l_windowName, l_params);
    play_item.winrefs[l_windowName].resizeTo(l_width, l_height);
	}

	//wait till the player is loaded, then play it
	if(document.getElementById("player_is_loaded").value == 1){
		if(action=='play_now'){
		play_item.winrefs[l_windowName].play_item_now(cat,track_number,track_artist,album_artist,track_title,album_title,label,album_only,is_digi,cart_id,store_id,is_verified,fobj,store_string);
		}else{
		play_item.winrefs[l_windowName].add_item_to_playlist(cat,track_number,track_artist,album_artist,track_title,album_title,label,album_only,is_digi,cart_id,store_id,is_verified,fobj,store_string);
		}
	}else{
	setTimeout("play_item('"+cat+"','"+track_number+"','"+track_artist+"','"+album_artist+"','"+track_title+"','"+album_title+"','"+label+"','"+action+"','"+album_only+"','"+is_digi+"','"+cart_id+"','"+store_id+"','"+is_verified+"','"+fobj+"','"+store_string+"')",1000);
	}
	
		
  } else {
//or else focus on it
    play_item.winrefs[l_windowName].focus();
	
	//and play it
	if(action=='play_now'){
	play_item.winrefs[l_windowName].play_item_now(cat,track_number,track_artist,album_artist,track_title,album_title,label,album_only,is_digi,cart_id,store_id,is_verified,fobj,store_string);
	}else{
	play_item.winrefs[l_windowName].add_item_to_playlist(cat,track_number,track_artist,album_artist,track_title,album_title,label,album_only,is_digi,cart_id,store_id,is_verified,fobj,store_string);
	}
	
  }
}





























function add_item_to_playlist(cat_in,track_number_in,track_id_in, artist_in, track_title_in, album_title_in, label_in) {
	
if(player_window){
	
	player_window.focus();
	player_window.add_item_to_playlist(cat_in,track_number_in,track_id_in, artist_in, track_title_in, album_title_in, label_in);
	
}else{
	
	if( player_window = window.open('/player.php','player_window','width=400,height=500') ){
		
	player_window.add_item_to_playlist(cat_in,track_number_in,track_id_in, artist_in, track_title_in, album_title_in, label_in);
		
	}
	
}
}





function select_delivery_address(user_id){
	
var selected_address_id = document.getElementById('delivery_address_chooser').selectedIndex;
if(selected_address_id==0){
	
	    document.getElementById('shipping_address_1').value='';
    	document.getElementById('shipping_address_2').value='';
    	document.getElementById('shipping_city').value='';
    	document.getElementById('shipping_state').value='';
    	document.getElementById('shipping_postcode').value='';
    	document.getElementById('shipping_country').value='';
    	document.getElementById('shipping_phone').value='';

}else{


//write the structure if necessary
	if (window.XMLHttpRequest){
	// code for IE7+, Firefox, Chrome, Opera, Safari
  	xmlhttp=new XMLHttpRequest();
  	}else{
	// code for IE6, IE5
  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	xmlhttp.onreadystatechange=function(){
  		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			
		var return_parts = xmlhttp.responseText.split('|');
		
		var shipping_name = return_parts[0];
		var shipping_email = return_parts[1];
		var shipping_address_1 = return_parts[2];
		var shipping_address_2 = return_parts[3];
		var shipping_city = return_parts[4];
		var shipping_state = return_parts[5];
		var shipping_postcode = return_parts[6];
		var shipping_country = return_parts[7];
		var shipping_phone = return_parts[8];

    	document.getElementById('shipping_address_1').value=shipping_address_1;
    	document.getElementById('shipping_address_2').value=shipping_address_2;
    	document.getElementById('shipping_city').value=shipping_city;
    	document.getElementById('shipping_state').value=shipping_state;
    	document.getElementById('shipping_postcode').value=shipping_postcode;
    	document.getElementById('shipping_country').selectedIndex=shipping_country;
    	document.getElementById('shipping_phone').value=shipping_phone;
		
    	}
  	}

xmlhttp.open("GET","select_delivery_address.php?delivery_address_id="+selected_address_id+"&user_id="+user_id,true);
xmlhttp.send();

}

//end
}




function check_shipping(){
	
    valid = true;
	messageout = "Please fill in the following fields:";

    if ( document.checkoutform.billing_name.value == "" ){
        messageout = messageout+" billing name,";
		document.checkoutform.billing_name.style.border='1px solid #FF0000';
        valid = false;
    }else{
		document.checkoutform.billing_name.style.border='1px solid #CCCCCC';
	}

	if ( document.checkoutform.shipping_email.value == "" ){
        messageout = messageout+" email,";
		document.checkoutform.shipping_email.style.border='1px solid #FF0000';
        valid = false;
    }else{
		
	//validate the email address
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var cs_email = document.checkoutform.shipping_email.value;
    if(reg.test(cs_email) == false) {
    messageout = messageout+" email,";
	valid = false;
	}else{
	document.checkoutform.shipping_email.style.border='1px solid #CCCCCC';
	}
	
	}
	


	if ( document.checkoutform.billing_address_1.value == "" ){
        messageout = messageout+" billing address,";
		document.checkoutform.billing_address_1.style.border='1px solid #FF0000';
        valid = false;
    }else{
		document.checkoutform.billing_address_1.style.border='1px solid #CCCCCC';
	}

	if ( document.checkoutform.billing_city.value == "" ){
        messageout = messageout+" billing city,";
		document.checkoutform.billing_city.style.border='1px solid #FF0000';
        valid = false;
    }else{
		document.checkoutform.billing_city.style.border='1px solid #CCCCCC';
	}

	if ( document.checkoutform.billing_state.value == "" ){
        messageout = messageout+" billing state/county,";
		document.checkoutform.billing_state.style.border='1px solid #FF0000';
        valid = false;
    }else{
		document.checkoutform.billing_state.style.border='1px solid #CCCCCC';
	}

	if ( document.checkoutform.billing_postcode.value == "" ){
        messageout = messageout+" billing postcode,";
		document.checkoutform.billing_postcode.style.border='1px solid #FF0000';
        valid = false;
    }else{
		document.checkoutform.billing_postcode.style.border='1px solid #CCCCCC';
	}
	
	if ( document.checkoutform.billing_phone.value == "" ){
        messageout = messageout+" phone,";
		document.checkoutform.billing_phone.style.border='1px solid #FF0000';
        valid = false;
    }else{
		document.checkoutform.billing_phone.style.border='1px solid #CCCCCC';
	}

	while (1) {
    if (messageout.substring(messageout.length - 1, messageout.length) != ",")
      break;
    messageout = messageout.substring(0, messageout.length - 1);
    }
	
	if(valid==false){
	alert ( messageout );
	}

return valid;

}





/*for the no-login popper*/

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'block' ) {	el.style.display = 'none';}
	else {el.style.display = 'block';}
}

function blanket_size(popUpDivVar,obj_id) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('nologin_blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-230;//230 is half popup's height
	if(obj_id==''){
	popUpDiv.style.top = popUpDiv_height + 'px';
	}else{
	popUpDiv.style.top = '50px';
	}
}

function window_pos(popUpDivVar,obj_id,obj_width) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	if(obj_id==''){
	popUpDiv.style.left = window_width + 'px';
	}else{
	var left_margin = parseInt( (obj_width - 300)/2 );
	popUpDiv.style.left = left_margin + 'px';
	}
}

function nologin_popup(obj_id,obj_width) {
	blanket_size('nologin_alert',obj_id);
	window_pos('nologin_alert',obj_id,obj_width);
	toggle('nologin_blanket');
	toggle('nologin_alert');
}



function cart_submit(action, is_logged_in, cart_contains_physical, obj_id, obj_width, payment_system){
	
	if(cart_contains_physical){
	var selObj = document.getElementById('country');	
	var selIndex = selObj.selectedIndex;
	if(selObj.options[selIndex].value!="" || action == 'update'){

	document.getElementById('submit_action').value = action;
	document.getElementById('opt_in_pm').value = payment_system;
	document.getElementById('opt_out_pm').value = payment_system;

		if(action=="update"){
		document.forms["cart_form"].target = '_self';
		document.forms["cart_form"].submit();
		}else if(is_logged_in){
		document.forms["cart_form"].submit();
		}else{
		nologin_popup(obj_id,obj_width);
		}
		
	}else{
	alert("Please select a shipping country");
	}
	
	}else{
		
	document.getElementById('submit_action').value = action;
	document.getElementById('opt_in_pm').value = payment_system;
	document.getElementById('opt_out_pm').value = payment_system;

		if(action=="update"){
		document.forms["cart_form"].target = '_self';
		document.forms["cart_form"].submit();
		}else if(is_logged_in){
		document.forms["cart_form"].submit();
		}else{
		nologin_popup(obj_id,obj_width);
		}
		
	}
		
}



function close_nologin(){
document.getElementById('nologin_blanket').style.display="none";
document.getElementById('nologin_alert').style.display="none";
}



function store_account_details(user_id){

if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }else{
// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200){
	if(xmlhttp.responseText.length>0){
    document.getElementById("account_stored").innerHTML=xmlhttp.responseText;
	}
    }
  }

var billing_name 		= escape(document.getElementById('billing_name').value);
var shipping_email 		= escape(document.getElementById('shipping_email').value);
var billing_address_1 	= escape(document.getElementById('.billing_address_1').value);
var billing_address_2 	= escape(document.getElementById('billing_address_2').value);
var billing_city 		= escape(document.getElementById('billing_city').value);
var billing_state 		= escape(document.getElementById('billing_state').value);
var billing_postcode 	= escape(document.getElementById('billing_postcode').value);
var billing_phone 		= escape(document.getElementById('billing_phone').value);
var billing_country 	= escape(document.getElementById('billing_country').value);

var shipping_address_1 	= escape(document.getElementById('shipping_address_1').value);
var shipping_address_2 	= escape(document.getElementById('shipping_address_2').value);
var shipping_city 		= escape(document.getElementById('shipping_city').value);
var shipping_state 		= escape(document.getElementById('shipping_state').value);
var shipping_postcode 	= escape(document.getElementById('shipping_postcode').value);
var shipping_country 	= escape(document.getElementById('shipping_country').value);
var shipping_phone 		= escape(document.getElementById('shipping_phone').value);

xmlhttp.open("GET","/modules/store_account.php?user_id="+user_id+"&billing_name="+billing_name+"&shipping_email="+shipping_email+"&billing_address_1="+billing_address_1+"&billing_address_2="+billing_address_2+"&billing_city="+billing_city+"&billing_state="+billing_state+"&billing_postcode="+billing_postcode+"&billing_phone="+billing_phone+"&billing_country="+billing_country+"&shipping_address_1="+shipping_address_1+"&shipping_address_2="+shipping_address_2+"&shipping_city="+shipping_city+"&shipping_state="+shipping_state+"&shipping_postcode="+shipping_postcode+"&shipping_country="+shipping_country+"&shipping_phone="+shipping_phone,true);
xmlhttp.send();

}





function checkout_log_in(){

var email = document.getElementById('login_email').value;
var password = document.getElementById('login_password').value;
var payment_method = document.getElementById('opt_in_pm').value;

if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }else{
// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200){
	if(xmlhttp.responseText.length>0){
		
	//set the login form html
    document.getElementById("paypal_checkout_login").innerHTML=xmlhttp.responseText;
	
	if(xmlhttp.responseText.indexOf("Login successful")>0){
		
	//remove the other forms
    document.getElementById("paypal_checkout_signup").innerHTML='';
    document.getElementById("paypal_checkout_nologin").innerHTML='';
	
	redirTime = "1000";
	self.setTimeout(document.forms["cart_form"].submit(),redirTime);
	}
	
	}
    }
  }
  
  //alert("/checkout_auth.php?email="+email+"&password="+password+"&payment_method="+payment_method+"&action=log_in");
  
xmlhttp.open("GET","/checkout_auth.php?email="+email+"&password="+password+"&payment_method="+payment_method+"&action=log_in",true);
xmlhttp.send();

}






function checkout_sign_up(){
	
var email = document.getElementById('signup_email').value;
var password = document.getElementById('signup_password').value;
var payment_method = document.getElementById('opt_in_pm').value;

if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }else{
// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200){
	if(xmlhttp.responseText.length>0){
		
    document.getElementById("paypal_checkout_signup").innerHTML=xmlhttp.responseText;
	
	if(xmlhttp.responseText.indexOf("Signup successful")>0){

	//remove the other forms
    document.getElementById("paypal_checkout_login").innerHTML='';
    document.getElementById("paypal_checkout_nologin").innerHTML='';

	redirTime = "1000";
	self.setTimeout(document.forms["cart_form"].submit(),redirTime);
	
	}

	}
    }
  }
  
xmlhttp.open("GET","/checkout_auth.php?email="+email+"&password="+password+"&payment_method="+payment_method+"&action=sign_up",true);
xmlhttp.send();

}


function show_obj_notes(){
document.getElementById("full_notes").style.display="block";
}
function hide_obj_notes(){
document.getElementById("full_notes").style.display="none";
}


function breakout_of_frames(page_system){
  if ( (page_system == 'checkout') && (top.location != location) ) {
    top.location.href = document.location.href ;
  }
}


function scrollWindow(){
	var new_top = document.getElementById("wrapper").offsetTop;
	window.scrollTo(0,new_top);
}



function start_download(c,m,serve){
	
	
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }else{
// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function(){
	if (xmlhttp.readyState==4 && xmlhttp.status==200){
		if(xmlhttp.responseText.length>0){
			document.getElementById("download_button").innerHTML=xmlhttp.responseText;
		}
	}
}
  
xmlhttp.open("GET","/mech/agent_v2_build.php?c="+c+"&m="+m+"&serve="+serve,true);
xmlhttp.send();

}

