// JavaScript Document

var eds_temp_artist = new Array()
var eds_temp_category = new Array()
var eds_temp_byartid = new Array()
var eds_temp_bycatid = new Array()

function logout2e()
{
  document.loginform.submit();
}


function JumpToIt(frm) {
    var newPage = frm.artistDd.options[frm.artistDd.selectedIndex].value
    if (newPage != "home.php") {
        location.href=newPage
    }
}

function mailSub2e() {
		document.getElementById('SubscribeValidation2e').style.display="block";
}

function searchblank() {	
		document.getElementById('2eCMsearch').value="";		
}

$(document).ready(function() 
{ 
	$("a.detailed-image").fancybox({ 'overlayShow': true }); 
$('ul#promo-image').innerfade({
						speed: 1000,
						timeout: 5000,
						type: 'random',
						containerheight: '205px'
					});
}); 





// *************  artist list ************************************

function get_artist_list()  {
	var querytest = "";
	$.post("2e-methods.php", { artist: ""+querytest+""},
													  function(data){
																	//	alert("Data Loaded: " + data);
																		get_artist_returndata(data)
													  });
	
	arraytest_temp = "";
	for(key in eds_temp_artist)
		{
  			 arraytest_temp += "key " + key	 + " has value " + eds_temp_artist[key] + "\n";
		}	
	alert(arraytest_temp);
}
function get_artist_returndata(data) {	
	var temp ="";
	$(data).find('artist').each(
						function(i) {
							artistName = $(this).find("name").text();
							artistID =  $(this).find("id").text();
							temp +=artistName;
							temp +=artistID + " \n ";
							eds_temp_artist[artistID] = artistName;
						}
	);
	alert (temp);	
}




// *************  category list ********************************************


function get_category_list()  {
	var querytest = "";
	$.post("2e-methods2.php", { artist: ""+querytest+""},
													  function(data){
																	//	alert("Data Loaded: " + data);
																		get_category_list_returndata(data)
													  });
	arraytest_temp = "";
	for(key in eds_temp_category)
		{
  			 arraytest_temp += "key " + key	 + " has value " + eds_temp_category[key] + "\n";
		}	
	alert(arraytest_temp);

}
function get_category_list_returndata(data) {	
	var temp ="";
	$(data).find('cats').each(
						function(i) {
							Name = $(this).find("name").text();
							ID =  $(this).find("id").text();
							temp +=Name;
							temp +=ID + " \n ";
							eds_temp_category[ID] = Name;							
						}
	);
	alert (temp);
}


// *************  propduct list by artist id ***********************************


function get_products_from_artist_id()  {
	var querytest = $("#prodbyart").attr("value");
	alert(querytest);
		var inputString = 'category';
		var data ="test";
	$.post("2e-methods3.php", {queryString: ""+querytest+""},
													  function(data){
																	//	alert("Data Loaded: " + data);
																		get_products_from_artist_id_returndata(data)
													  });
	//alert(eds_temp_byartid[1].artist + eds_temp_byartid[1].product + eds_temp_byartid[1].productcode);
//	for (var i = 0; i < eds_temp_byartid.length; i++)
//			{
//				alert(eds_temp_byartid[i]["product"]);
//			}
			
	
	
}
function get_products_from_artist_id_returndata(data) {	
	var eds_localtemp = new Array()
	var eds_localtemp2 = new Array()	
	var temp ="";
	var x=0;
	$(data).find('product_by_artist').each(
						function(i) {
							artistName = $(this).find("artist_name").text();
							product =  $(this).find("product").text();
							productcode = $(this).find("product_code").text();
							list_price =  $(this).find("list_price").text();							

							temp +=artistName;
							temp +=product;
							temp +=productcode;
							temp +=list_price + " \n ";
							
				eds_temp_byartid.push(	{
											"artist": artistName,
											"product": product,
											"productcode": productcode,
											"price": list_price
										}
									);							

						}

	);
	//eds_temp_byartid = eds_localtemp2;
	alert (temp);	
}


// *************  propduct list by category id ***********************************


function get_products_from_category_id()  {
	var querytest = $("#prodbycat").attr("value");
	alert(querytest);
		var inputString = 'category';
		var data ="test";
	$.post("2e-methods4.php", {queryString: ""+querytest+""},
													  function(data){
																	//	alert("Data Loaded: " + data);
																		get_products_from_category_id_returndata(data)
													  });
//	for (var i = 0; i < eds_temp_bycatid.length; i++)
//			{
//				alert(eds_temp_bycatid[i]["product"]);
//			}	
	
}
function get_products_from_category_id_returndata(data) {	
	var temp ="";
	$(data).find('product_by_category').each(
						function(i) {
							category = $(this).find("category").text();
							product =  $(this).find("product").text();
							productcode = $(this).find("product_code").text();
							list_price =  $(this).find("list_price").text();							

							temp +=category;
							temp +=product;
							temp +=productcode;
							temp +=list_price + " \n ";
							eds_temp_bycatid.push(	{
														"category": category,
														"product": product,
														"productcode": productcode,
														"price": list_price
													}
												);								
						}
	);
	alert (temp);

}




















//  ******************************    code to add a product to the basket. ******************


// inputs additional details and adds them to the basket.
function  add_prod_to_basket(prodid, catid, quantity)   {
	
	var page="cart.php";
	var pars="";
	
	pars+= "?mode=add";
	pars+= "&productid="+prodid;	
	pars+= "&cat="+catid;
	pars+= "&amount="+quantity;	
	
	page += pars;
	$.get(page);
}


// inputs items position in basket and the quantity to change it to.
function change_quantity_in_basket(position, quantity)   {

	var page="cart.php";
	var pars="?productindexes["+position+"]="+quantity;
	pars+= "&action=update";	
	
	page += pars;
	alert (page);
	$.get(page);
}


// Delete a product from the basket
function delete_product_in_basket(position)   {

	var page="cart.php";
	var pars="?productindex="+position;
	pars+= "&mode=delete";	
	
	page += pars;
	alert (page);
	$.get(page);
}




