showhide_check = 0;
var buttonclickedholder;
function showHideOrder(order) {
	if (showhide_check == 0) {
		showhide_check = 1;
		document.getElementById("order_form_" + order).style.display = 'inline';
		//document.getElementById("arrow_" + order).src = '/images/up_arrow.gif';
		buttonclickedholder = order;			
	} else {
		showhide_check = 0;
		document.getElementById("order_form_" + order).style.display = 'none';
		//document.getElementById("arrow_" + order).src = '/images/down_arrow.gif';	
		buttonclickedholder = '';		
	}
}

function RollOver (order) {
	document.getElementById(order).style.border = 'solid 2px #FFFFFF';
}

function RollOut (order) {
	if (showhide_check == 1) {
		document.getElementById(order).style.border = 'solid 2px #FFFFFF';
	} else {
		document.getElementById(order).style.border = 'solid 2px #000000';
	}
}

function fillFieldsFromSku(element, value, order){
	for (i=0;i<value.attributes.length;i++) {
		if (value.attributes[i].name == 'name'){
			$('product_' + order + '_name').value=value.attributes[i].value;
		}
		if (value.attributes[i].name == 'price') {
			$('rate_' + order).innerHTML=value.attributes[i].value;
		}
		if (value.attributes[i].name == 'colors') {
			if (value.attributes[i].value.search(/option/) != -1){
				$('product_color_' + order).innerHTML = value.attributes[i].value; 
				$('product_color_' + order).style.display='block';
			}
		}
		if (value.attributes[i].name == 'quantity') {
			$('product_quantity_' + order).innerHTML = value.attributes[i].value;
			$('product_quantity_' + order).style.display='block';
		}
	}
	$('quantity_' + order).style.display='block';
	$('quantity_' + order).value=1;
	$('rate_' + order).style.display='block';
	$('rate_' + order).disabled = true;
	$('save_button_' + order).style.display='block';	
}


function fillFieldsFromName(element, value, order){
	for (i=0;i<value.attributes.length;i++) {
		if (value.attributes[i].name == 'sku'){
			$('product_' + order + '_sku').value=value.attributes[i].value;
		}
		if (value.attributes[i].name == 'price') {
			$('rate_' + order).innerHTML=value.attributes[i].value;
		}
		if (value.attributes[i].name == 'colors') {
			if (value.attributes[i].value.search(/option/) != -1){
				$('product_color_' + order).innerHTML = value.attributes[i].value; 
				$('product_color_' + order).style.display='block';
			}
		}
		if (value.attributes[i].name == 'quantity') {
			$('product_quantity_' + order).innerHTML = value.attributes[i].value;
			$('product_quantity_' + order).style.display='block';
		}
	}
	$('rate_' + order).style.display='block';
	$('rate_' + order).disabled = true;
	$('save_button_' + order).style.display='block';
}



function showHidePaymentInfo(option) {
//  alert(option);
	if (option == 'PayPal') {
		document.getElementById("paypal_information").style.display = 'inline';
		document.getElementById("payment_information").style.display = 'none';
		document.getElementById("payment_type").value = 'PayPal';
	} else if (option == 'Visa') {
		document.getElementById("payment_information").style.display = 'inline';
		document.getElementById("paypal_information").style.display = 'none';
//		document.getElementById("payment_type").value = 'cc';
		document.getElementById("order[card_type]").value = 'Visa';
	} else if (option == 'Master') {
		document.getElementById("payment_information").style.display = 'inline';
		document.getElementById("paypal_information").style.display = 'none';
//		document.getElementById("payment_type").value = 'cc';
		document.getElementById("order[card_type]").value = 'Master';
	} else if (option == 'none') {
		document.getElementById("payment_information").style.display = 'none';
		document.getElementById("paypal_information").style.display = 'none';
	}
}


function checkPaymentType(option){
//  button.disbled = true;
//  button.src = '/image/shopping_cart/process_order_disabled.png';
  //imgelement = document.getElementById(img);
  //imgelement.src = pic;
  if (option == '') {
    alert('please, select a Payment option');
  }
}


//function two_alerts(order){
function two_alerts(t){
  if (confirm('Are you sure you want delete the order order?')) {
    var f = document.createElement('form'); 
    f.style.display = 'none'; 
    t.parentNode.appendChild(f); 
    f.method = 'POST'; 
    f.action = t.href;

    // second confirmation
    if (confirm('Do you want to release product quantities of this order?')) {
      var b = document.createElement('input')  
      b.setAttribute('type', 'hidden'); 
      b.setAttribute('name', 'release_quantity');
      b.setAttribute('value', 'yes');
    }
    else{
      var b = document.createElement('input')  
      b.setAttribute('type', 'hidden'); 
      b.setAttribute('name', 'release_quantity');
      b.setAttribute('value', 'no');
    };
    f.appendChild(b);

    var m = document.createElement('input'); 
    m.setAttribute('type', 'hidden'); 
    m.setAttribute('name', '_method'); 
    m.setAttribute('value', 'delete'); 
    f.appendChild(m);

    f.submit();
  };
  return false;
}


function addText(insert1, textAreaId, insert2, subjectId){
	//Get the textarea
	area = document.getElementById(textAreaId);
  area.value = insert1;

  subject = document.getElementById(subjectId);
  subject.value = insert2;
 
//	//Get the selection bounds
//	var start = area.selectionStart;
//	var end = area.selectionEnd;
// 
//	//Break up the text by selection
//	var text = area.value;
//	var pre = String.substring(text,0, start);
//	var sel = String.substring(text, start, end);
//	var post = String.substring(text,end);
// 
//	//Insert the text at the beginning of the selection
//	text = pre + escape(insert) + sel + post;
// 
//	//Put the text in the textarea
//	area.value = text;
// 
//	//Re-establish the selection, adjusted for the added characters.
//	area.selectionStart = start+insert.length;
//	area.selectionEnd = end+insert.length;
}

