function imageItem(image_location) {
	this.image_item = new Image();
	this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
	return(imageObj.image_item.src)
}
function generate(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
	if (random_display) {
		image_index = generate(0, number_of_image-1);
	}
	else {
		image_index = (image_index+1) % number_of_image;
	}
	var new_image = get_ImageItemLocation(image_list[image_index]);
	return(new_image);
}
function rotateImage(place) {
	var new_image = getNextImage();	
	document.getElementById(place).src = new_image;
	var recur_call = "rotateImage('"+place+"')";
}
function change_client_address(){	
	if(document.getElementById('client_address').checked){
		document.getElementById('client_address_tr').style.display = '';
	}
	else{
		document.getElementById('client_address_tr').style.display = 'none';
	}
}
function show_categories_float(){	
	document.getElementById('categories_float').style.left = '10%'
	document.getElementById('categories_float').style.top = '40%'	
	document.getElementById('categories_float').style.display = '';
}

function show_events_float(){	
	document.getElementById('events_float').style.left = '40%'
	document.getElementById('events_float').style.top = '40%'	
	document.getElementById('events_float').style.display = '';
}

function show_price_float(){	
	document.getElementById('price_float').style.left = '40%'
	document.getElementById('price_float').style.top = '40%'	
	document.getElementById('price_float').style.display = '';
}

function show_amount_float(){	
	document.getElementById('amount_float').style.left = '40%'
	document.getElementById('amount_float').style.top = '40%'	
	document.getElementById('amount_float').style.display = '';
}

function detect_beowser(){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	
	//document.write("Browser name: "+ browser);
	//document.write("<br />");
	//document.write("Browser version: "+ version);
	return browser+version
}
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
        }
}
return [curleft,curtop];
}
function delete_product_crom_cart(){
	var conf = confirm('האם אתה בטוח שברצונך למחוק את המוצר');
	return conf;
}
function show_visa(){
	document.getElementById('visa_order_type').style.display = ''
}
function hide_visa(){
	document.getElementById('visa_order_type').style.display = 'none'
}
function cart_shipment_type(value){
	if(document.getElementById('oreder_shipment').checked){
		document.getElementById('shipment_default').style.display = '';
		document.getElementById('shipment_manual').style.display = 'none';
	}
	else{
		document.getElementById('shipment_default').style.display = 'none';
		document.getElementById('shipment_manual').style.display = '';
	}
}
function order_products(value,pn,page,c_id,ot){
	var link = 'http://www.HaMusica.co.il/?page='+page+'&c_id='+c_id+'&ob='+value;
	if(pn!=''){
		link = link+'&pn='+pn;
	}	
	if(ot==1){
		ot_now = 0;
	}
	else{
		ot_now = 1;
	}
	
	link = link+'&ot='+ot_now;
	
	if(value=='normal'){
		link = 'http://www.HaMusica.co.il/?page='+page+'&c_id='+c_id;
	}
	
	window.location = link;
}
function order_products_search(value,pn,page,c_id,ot,term){
	var link = 'http://www.HaMusica.co.il/?page='+page+'&term='+term+'&ob='+value;
	if(pn!=''){
		link = link+'&pn='+pn;
	}	
	if(ot==1){
		ot_now = 0;
	}
	else{
		ot_now = 1;
	}
	
	link = link+'&ot='+ot_now;
	
	if(value=='normal'){
		link = 'http://www.HaMusica.co.il/?page='+page+'&term='+term;
	}
	
	window.location = link;
}
function show_change_password(){
	var obj = document.getElementById('change_passowrd');
	var obj2 = document.getElementById('change_passowrd_text');

	var pass = document.getElementById('register_password');
	var conf_pass = document.getElementById('register_confirm_password');

	if(obj.style.display=='none'){
		obj.style.display = '';
		obj2.style.display = '';
	}
	else{
		obj.style.display = 'none';
		obj2.style.display = 'none';
		pass.value='';
		conf_pass.value='';
	}
}
function show_product_picture(picture_id){
	if(document.getElementById('product_big_picture_1')){
		document.getElementById('product_big_picture_1').style.display = 'none';
	}
	if(document.getElementById('product_big_picture_2')){
		document.getElementById('product_big_picture_2').style.display = 'none';
	}
	if(document.getElementById('product_big_picture_3')){
		document.getElementById('product_big_picture_3').style.display = 'none';
	}
	if(document.getElementById('product_big_picture_4')){
		document.getElementById('product_big_picture_4').style.display = 'none';
	}
	if(document.getElementById('product_big_picture_5')){
		document.getElementById('product_big_picture_5').style.display = 'none';
	}
	if(document.getElementById('product_big_picture_6')){
		document.getElementById('product_big_picture_6').style.display = 'none';
	}
	document.getElementById('product_big_picture_'+picture_id).style.display = '';
}
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
        }
}
return [curleft,curtop];
}



function show_sub_menu(sub_menu_id){
	var obj = document.getElementById(sub_menu_id);
	if(obj.style.display=='none'){
		obj.style.display='';
	}
	else{
		obj.style.display='none'
	}	
}

function change_addons_sum(value){
	var addons_sum = 0;

	if(document.product_form.product_addon_1){		
		if(document.product_form.product_addon_1.length>1){
			for (var i=0; i < document.product_form.product_addon_1.length; i++){				
				if (document.product_form.product_addon_1[i].checked){
					var rad_val = document.product_form.product_addon_1[i].value;
					var mySplitResult = rad_val.split("#%#");
					addons_sum = addons_sum+parseFloat(mySplitResult[0]);
				}
			}		
		}
		else if(document.product_form.product_addon_1.checked){		
			var rad_val = document.product_form.product_addon_1.value;	
			var mySplitResult = rad_val.split("#%#");
			addons_sum = addons_sum+parseFloat(mySplitResult[0]);
		}
		
	}
	
	if(document.product_form.product_addon_2){		
		if(document.product_form.product_addon_2.length>1){
			for (var i=0; i < document.product_form.product_addon_2.length; i++){
				if (document.product_form.product_addon_2[i].checked){
					var rad_val = document.product_form.product_addon_2[i].value;
					var mySplitResult = rad_val.split("#%#");
	
					addons_sum = addons_sum+parseFloat(mySplitResult[0]);
				}
			}
		}
		else if(document.product_form.product_addon_2.checked){	
			var rad_val = document.product_form.product_addon_2.value;	
			var mySplitResult = rad_val.split("#%#");
			addons_sum = addons_sum+parseFloat(mySplitResult[0]);
		}
	}

	if(document.product_form.product_addon_3){		
		if(document.product_form.product_addon_3.length>1){
			for (var i=0; i < document.product_form.product_addon_3.length; i++){
				if (document.product_form.product_addon_3[i].checked){
					var rad_val = document.product_form.product_addon_3[i].value;
					var mySplitResult = rad_val.split("#%#");
	
					addons_sum = addons_sum+parseFloat(mySplitResult[0]);
				}
			}
		}
		else if(document.product_form.product_addon_3.checked){	
			var rad_val = document.product_form.product_addon_3.value;	
			var mySplitResult = rad_val.split("#%#");
			addons_sum = addons_sum+parseFloat(mySplitResult[0]);
		}
	}

	if(document.product_form.product_addon_4){		
		if(document.product_form.product_addon_4.length>1){
			for (var i=0; i < document.product_form.product_addon_4.length; i++){
				if (document.product_form.product_addon_4[i].checked){
					var rad_val = document.product_form.product_addon_4[i].value;
					var mySplitResult = rad_val.split("#%#");
	
					addons_sum = addons_sum+parseFloat(mySplitResult[0]);
				}
			}
		}
		else if(document.product_form.product_addon_4.checked){	
			var rad_val = document.product_form.product_addon_4.value;	
			var mySplitResult = rad_val.split("#%#");
			addons_sum = addons_sum+parseFloat(mySplitResult[0]);
		}
	}

	if(document.product_form.product_addon_5){		
		if(document.product_form.product_addon_5.length>1){
			for (var i=0; i < document.product_form.product_addon_5.length; i++){
				if (document.product_form.product_addon_5[i].checked){
					var rad_val = document.product_form.product_addon_5[i].value;
					var mySplitResult = rad_val.split("#%#");
	
					addons_sum = addons_sum+parseFloat(mySplitResult[0]);
				}
			}
		}
		else if(document.product_form.product_addon_5.checked){	
			var rad_val = document.product_form.product_addon_5.value;	
			var mySplitResult = rad_val.split("#%#");
			addons_sum = addons_sum+parseFloat(mySplitResult[0]);
		}
	}

	document.getElementById('addons_cost').innerHTML = addons_sum+' ₪';
}

function checkDefault(value,obj_id){	
	if(document.getElementById(obj_id).value==''){
		document.getElementById(obj_id).value = value;
	}	
}

function clearDefault(el) {
	if (el.defaultValue==el.value) el.value = ""
}
