$(document).ready(function(){

$(".rollover").hover(
 function() {
  curr = $(this).find("img").attr("src");
  overlen = curr.length;
  over = curr.substr(0, overlen-4);
  over = over+'_over.png';
  $(this).find("img").attr({ src: over});
 },
 function() {
  $(this).find("img").attr({ src: curr});
 }
)

$(".rollover").find("img").each(function(i) {
  temp = this.src;
  prelen = temp.length;
  pre = temp.substr(0, prelen-4);
  pre = pre+'_over.png';
  preload_image_object = new Image();
  preload_image_object.src = pre;
});

$(".rollover2").hover(
 function() {
  curr = $(this).find("img").attr("src");
  overlen = curr.length;
  over = curr.substr(0, overlen-4);
  over = over+'_over.gif';
  $(this).find("img").attr({ src: over});
 },
 function() {
  $(this).find("img").attr({ src: curr});
 }
)

$(".rollover2").find("img").each(function(i) {
  temp = this.src;
  prelen = temp.length;
  pre = temp.substr(0, prelen-4);
  pre = pre+'_over.gif';
  preload_image_object = new Image();
  preload_image_object.src = pre;
});

});

function updateField(value,field){
	document.getElementById(field).value = value;
	//alert (document.getElementById(field).value);
}

function submit(form){
	//alert('submit');
	document[form].method = 'post';
	document[form].action = "basket.php?updatecart&id=1";
	document[form].submit();
}

function submitform(url){
	////alert(url);
	document.form1.action = url;
	document.form1.method = 'post';
    document.form1.submit();
}

		function updateDelete(obj){
		
	var delid = '';
	//loop through checkboxes
	var i=-1;
	
	while(++i < obj.length){
		if(obj[i].checked == true){
			delid += obj[i].value + ',';
	
			
		}
	}
	
	delid = delid.substring(0,delid.length-1);
			////alert(delid);
			document.getElementById('deleteids').value = delid;

}
	
	function toggleCheck(is_checked,field){
		////alert (is_checked);
		if(is_checked){
	 document.getElementById(field).value = 1;
		} else {
			////alert ('zero');
	 document.getElementById(field).value = 0;	
		}
	}
	
	function updateProds(obj,fieldid){
		//alert(fieldid);
	var checkedids = '';
	
	//loop through checkboxes
	var i=-1;
	
	while(++i < obj.length){
if(obj[i].checked == true){
			checkedids += obj[i].value + ',';
		}
	}
	checkedids = "1,8,11,"+checkedids;
	checkedids = checkedids.substring(0,checkedids.length-1);
//alert(checkedids);
document.getElementById(fieldid).value = checkedids;
			
			//alert(document.getElementById(fieldid).value);
}

	function updateLocs(){
		
	var checkedids = '';
	
	//loop through checkboxes
	var i=-1;
	obj = document.admin.loc_check;
	while(++i < obj.length){
if(obj[i].checked == true){
			checkedids += obj[i].value + ',';
		}
	}
	checkedids = checkedids.substring(0,checkedids.length-1);
//alert(checkedids);
document.getElementById('image_location_id').value = checkedids;
	}


function updateRadios(form,prefix,fieldid,totalgroups){
	////alert('up radios');

	var checkedids = '';
	
	//loop through checkboxes
	
	//loop radio groups
	for (i = 1; i <= totalgroups; i++) {
	////alert(totalgroups);
		var rdogroup = prefix + '_'+ i;
		////alert(rdogroup);
len = document[form][rdogroup].length;
////alert(len);
//loop radio group
for (j = 0; j < len; j++) {
if (document[form][rdogroup][j].checked) {
checkedids += document[form][rdogroup][j].value + ",";
}
}
}
		
	checkedids = checkedids.substring(0,checkedids.length-1);

			document.getElementById(fieldid).value = "8," +checkedids;
			//alert(document.getElementById(fieldid).value);

}
	

function popwhizz(element){ //Pop up a whizzywig form for the element id
window.open('whizzy.htm?'+element,'popwhizzhizz',
'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=640,height=480,top=100')
}
function whizzed(){
//EXAMPLE ONLY: Join the divs together and put them into the hidden 'edited' - 
//alert("whizz");
 document.getElementById('product_desc').value= document.getElementById('product_desc_prev').innerHTML;


}


//function to handle item inputs
function updateItems(){
	////alert('up items');
	
//update selects
	var id = 0;

	obj = document.admin.defaults;
values = "";
	var j=-1;
	while(++j < obj.length){
		if(obj[j].checked) val = obj[j].value; else val = '0';
		values += val + ",";
	}
	values = values.substring(0,values.length-1);
	////alert(values);
	document.getElementById('defaults_hdn').value = values;
	//alert (	document.getElementById('defaults_hdn').value);				 
}

function resetItems(){
	//reset selects
	obj = document.admin.styles;
	var i=-1;
	while(++i < obj.length){
		obj[i].selectedIndex = 0;
	}
	obj = document.admin.sizes;
	var i=-1;
	while(++i < obj.length){
		obj[i].selectedIndex = 0;
	}
	//reset inputs
		obj = document.admin.fabrics;
	var i=-1;
	while(++i < obj.length){
		obj[i].value = "";
	}
	
		obj = document.admin.costs;
	var i=-1;
	while(++i < obj.length){
		obj[i].value = "";
	}
	
		obj = document.admin.defaults;
	var i=-1;
	while(++i < obj.length){
		obj[i].checked = 0;
		
	}
}

function singleCheck(index,obj){
	//alert('single');
	var i=-1;
	while(++i < obj.length){
		if(obj[i].checked && i != index){
	obj[i].checked = false;
		}
	}
}
