var testsuccess = 0;
var lnid = new Array();
function categorylist(url)
  {
  self.location = url;
  }
 
var noresults=function(results)
  {
  return true;
  }
  
var getresults=function(results)
  {
  eval(results);
  if(window.drag_and_drop_cart_updater)
    {
     drag_and_drop_cart_updater();
    }
  if(document.getElementById('loadingimage') != null)
    {
    document.getElementById('loadingindicator').style.visibility = 'hidden';
    }
    else if(document.getElementById('alt_loadingimage') != null)
    {
    document.getElementById('alt_loadingindicator').style.visibility = 'hidden';
    }
  if((document.getElementById('sliding_cart') != null) && (document.getElementById('sliding_cart').style.display == 'none'))
    {
    jQuery("#fancy_collapser").attr("src", (base_url+"/wp-content/plugins/wp-shopping-cart/images/minus.png"));
    jQuery("#sliding_cart").show("fast",function(){
    ajax.post("index.php",noresults,"ajax=true&set_slider=true&state=1"); });
    }
  if(document.getElementById('fancy_notification') != null)
    {
    jQuery('#loading_animation').css("display", 'none');
    }
  }
  
function set_billing_country(html_form_id, form_id)
  {
  var billing_region = '';
  country = jQuery(("div#"+html_form_id+" select[@class=current_country]")).val();  
  region = jQuery(("div#"+html_form_id+" select[@class=current_region]")).val();
  if(/[\d]{1,6}/.test(region)) // number over 6 digits for a region ID? yeah right, not in the lifetime of this code
    {
    billing_region = "&billing_region="+region;
    }  
  ajax.post("index.php",getresults,("ajax=true&form_id="+form_id+"&billing_country="+country+billing_region));
  }

function submitform(frm, show_notification) { 	
  	var isValid = true;
	//validation
	/*$$('#addtocart select').each(function(el) {
		if (el.options[el.options.selectedIndex].value.length == 0) {
			isValid = false;
		}
	});*/

	//if valid, post via ajax
	if (isValid) {  
		ajax.post("index.php?ajax=true&user=true",getresults,ajax.serialize(frm));
		if(document.getElementById('loadingimage') != null)
		{
			document.getElementById('loadingimage').src = base_url+'/wp-content/plugins/wp-shopping-cart/images/indicator.gif';
			document.getElementById('loadingindicator').style.visibility = 'visible';
		} 
   
		if(document.getElementById('fancy_notification') != null) {			
			jQuery('#fancy_notification').css("display", 'block');
			jQuery('#loading_animation').css("display", 'block');
			jQuery('#fancy_notification_content').css("display", 'none'); 
			 
		}
	} else { // not valid

	}
  return false;
  }

function emptycart()
  {
  ajax.post("index.php",getresults,"ajax=true&user=true&emptycart=true");
  if(document.getElementById('loadingimage') != null)
    {
    document.getElementById('loadingimage').src = base_url+'/wp-content/plugins/wp-shopping-cart/images/indicator.gif';
    document.getElementById('loadingindicator').style.visibility = 'visible';
    } 
    else if(document.getElementById('alt_loadingimage') != null)
    {
    document.getElementById('alt_loadingimage').src = base_url+'/wp-content/plugins/wp-shopping-cart/images/indicator.gif';
    document.getElementById('alt_loadingindicator').style.visibility = 'visible';
    }    
  } 
  
function hide_save_indicator(id)
  {
  document.getElementById(id).style.display = "none";
  }

function submit_change_country()
  {
  document.forms.change_country.submit();
  }
  
function update_preview_url(prodid)
  {
  image_height = document.getElementById("image_height").value;
  image_width = document.getElementById("image_width").value;
  if(((image_height > 0) && (image_height <= 1024)) && ((image_width > 0) && (image_width <= 1024)))
    {
    new_url = "index.php?productid="+prodid+"&height="+image_height+"&width="+image_width+"";
    document.getElementById("preview_link").setAttribute('href',new_url);
    }
    else
      {
      new_url = "index.php?productid="+prodid+"";
      document.getElementById("preview_link").setAttribute('href',new_url);
      }
  return false;
  }
  
function change_variation(product_id, variation_ids, special, imgName)
  {
  var value_ids = '';
  var special_prefix = "";
  var form_id = "addtocart";
  
  for(var i in variation_ids)
    {
    if(!isNaN(parseInt(i)))
      {
      variation_name = "variation["+variation_ids[i]+"]";
      value_ids += "&variation[]="+document.getElementById(form_id).elements[variation_name].value;
      }
    }
  if(special == true)
    {
    var return_price=function(results)
      {
      //alert(results);
      eval(results);
      if(product_id != null)
        {
        target_id = "special_product_price_"+product_id;
        document.getElementById(target_id).firstChild.innerHTML = price;
        }
      }
    }
    else
    {
    var return_price=function(results)
      {
      eval(results);
      }
    }
    
   if (imgName != null) {
	   //swap image
	   //alert(imgName);
   	   //previewColor(imgName); 
   }
    
  ajax.post("index.php",return_price,"ajax=true&get_updated_price=true&product_id="+product_id+value_ids);
  }
  
 
function show_details_box(id,image_id)
  {
  state = document.getElementById(id).style.display; 
  if(state != 'block')
    {
    document.getElementById(id).style.display = 'block';
    document.getElementById(image_id).src = base_url+"/wp-content/plugins/wp-shopping-cart/images/icon_window_collapse.gif";
    }
    else
      {
      document.getElementById(id).style.display = 'none';
      document.getElementById(image_id).src = base_url+"/wp-content/plugins/wp-shopping-cart/images/icon_window_expand.gif";
      }
  return false;
  }
  
var register_results=function(results)
  {  
  jQuery("div#TB_ajaxContent").html(results);
  jQuery('div#checkout_login_box').css("border", '1px solid #339933');
  jQuery('div#checkout_login_box').css("background-color", '#e8fcea');
  }
  
function submit_register_form(frm)
  {
  jQuery('img#register_loading_img').css("display", 'inline');
  ajax.post("index.php?ajax=true&action=register",register_results,ajax.serialize(frm));

  return false;
  }