// PROFILE

function ship_mark_for_destroy(element){
	$(element).next('.should_destroy').value = 1;
	$(element).up('.frequent_ship_edit').hide();
}

function trip_mark_for_destroy(element){
	$(element).next('.should_destroy').value = 1;
	$(element).up('.frequent_trip_edit').hide();
}

function specialty_mark_for_destroy(element){
	$(element).next('.should_destroy').value = 1;
	$(element).up('.specialty').hide();
}

function serv_mark_for_destroy(element){
	$(element).next('.should_destroy').value = 1;
	$(element).up('.serv').hide();
}

//FREIGHT

function product_mark_for_destroy(element){
	$(element).next('.should_destroy').value = 1;
	$(element).up('.product').hide();
}

function check_or_uncheck_containers(element, type){
	checkboxes = $$("div#"+type+" input");
	for (i=0;i<checkboxes.length;i++){
		if(element.checked)
			checkboxes[i].checked = true;
		else
			checkboxes[i].checked = false;
	}
}

function uncheck_all(element){
	if(element.checked){
		$('freight_open_container').checked=false;
		$('freight_closed_container').checked=false;
		$('freight_reefer_container').checked=false;
		uncheck($$('div#closed_equipment input'));
		uncheck($$('div#open_equipment input'));
		uncheck($$('div#reefer_equipment input'));
	}
}

function uncheck(inputs){
	for(i=0;i<inputs.length;i++){
		inputs[i].checked=false
	}
}

function uncheck_not_secure(inputs){
	$('freight_vehicle_indiferent').checked=false;
}

function change_volume_field(select){
	if($F(select) == "Litros"){
		$('one_field_volume').show();
		$('three_field_volume').hide();
	}else{
		$('one_field_volume').hide();
		$('three_field_volume').show();
	}
}

function update_destination_field() {
	if ($F('state') == 'state') {
		$('state_auto_complete').show();
		$('city_auto_complete').hide();
	}
	else {
		$('state_auto_complete').hide();
		$('city_auto_complete').show();
	}
}

function remove_destination(id, type) {
	if (type == "state") {
		$('light_state_destination_'+id).remove();
		$('state_destination_'+id).remove();
	}
	else {
		$('light_city_destination_'+id).remove();
		$('city_destination_'+id).remove();
	}
}

//Contact

function use_my_info(type){
	if($(type+'_my_info').checked){
		$$('div#'+type+'_address input')[0].value = $F('myaddress');
		$$('div#'+type+'_neighbourhood input')[0].value = $F('myneighbourhood');
		$$('div#'+type+'_contact_name input')[0].value = $F('myname');
		$$('div#'+type+'_phone_type input')[0].checked = true;
		$$('div#'+type+'_phone_number input')[0].value = $F('myphone');
	}
	else
	{
		$$('div#'+type+'_address input')[0].value = "";
		$$('div#'+type+'_neighbourhood input')[0].value = "";
		$$('div#'+type+'_contact_name input')[0].value = "";
		$$('div#'+type+'_phone_type input')[0].checked = false;
		$$('div#'+type+'_phone_number input')[0].value = "";
	}
}


function update_price(price, name) {
  
  if ($('3_months').checked == true) {
    $('amount').value = Math.round(price)
    $('item_name').value = 'Suscripción a 3 meses en '+name }
  else if ($('12_months').checked == true) {
    $('amount').value = Math.round(price)
    $('item_name').value = 'Suscripción a 12 meses en '+name }
  else if ($('24_months').checked == true) {
    $('amount').value = Math.round(price * 0.9)
    $('item_name').value = 'Suscripción a 24 meses en '+name }
    
}

function change_form_action(){
	if ($('credit_card').checked == true){
		$('payment_form').action = "https://www.paypal.com/cgi-bin/websc";
	}else if($('transfer').checked==true){
		$('payment_form').action = "payment_information";
	}
}

function display_results(type, value){
	for(i=0;i<$$('.' + type).length;i++){
		if($$('.' + type)[i].id.include(value)){
			$$('.' + type)[i].setStyle({
				display:''
			});
		}else{
			$$('.' + type )[i].setStyle({
				display:'none'
			});
		}
	}
}