var array = new Array();

function fill_form(a_array, b_array){
	if(document.getElementById('same').checked == true){
		if((a_array[0] == 1)&&(b_array[0] == 1)){
			document.getElementById('s_title').value = document.getElementById('b_title').value;
		}
		if((a_array[1] == 1)&&(b_array[1] == 1)){
			document.getElementById('s_first_name').value = document.getElementById('b_first_name').value;
		}
		if((a_array[2] == 1)&&(b_array[2] == 1)){
			document.getElementById('s_last_name').value = document.getElementById('b_last_name').value;
		}
		if((a_array[3] == 1)&&(b_array[3] == 1)){
			document.getElementById('s_company').value = document.getElementById('b_company').value;
		}
		if((a_array[4] == 1)&&(b_array[4] == 1)){
			document.getElementById('s_address_1').value = document.getElementById('b_address_1').value;
		}
		if((a_array[5] == 1)&&(b_array[5] == 1)){
			document.getElementById('s_address_2').value = document.getElementById('b_address_2').value;
		}
		if((a_array[6] == 1)&&(b_array[6] == 1)){
			document.getElementById('s_postcode').value = document.getElementById('b_postcode').value;
		}
		if((a_array[7] == 1)&&(b_array[7] == 1)){
			document.getElementById('s_city').value = document.getElementById('b_city').value;
		}
		if((a_array[8] == 1)&&(b_array[8] == 1)){
			document.getElementById('s_country').value = document.getElementById('b_country').value;
		}
		if((a_array[9] == 1)&&(b_array[9] == 1)){
			document.getElementById('s_state').value = document.getElementById('b_state').value;
		}
		if((a_array[10] == 1)&&(b_array[10] == 1)){
			document.getElementById('s_phone').value = document.getElementById('b_phone').value;
		}
		if((a_array[11] == 1)&&(b_array[11] == 1)){
			document.getElementById('s_fax').value = document.getElementById('b_fax').value;
		}
		if((a_array[12] == 1)&&(b_array[12] == 1)){
			document.getElementById('s_email').value = document.getElementById('b_email').value;
		}
		if((a_array[13] == 1)&&(b_array[13] == 1)){
			document.getElementById('s_cnp').value = document.getElementById('b_cnp').value;
		}
	}else{
		if((a_array[0] == 1)&&(b_array[0] == 1)){
			document.getElementById('s_title').value = '';
		}
		if((a_array[1] == 1)&&(b_array[1] == 1)){
			document.getElementById('s_first_name').value = '';
		}
		if((a_array[2] == 1)&&(b_array[2] == 1)){
			document.getElementById('s_last_name').value = '';
		}
		if((a_array[3] == 1)&&(b_array[3] == 1)){
			document.getElementById('s_company').value = '';
		}
		if((a_array[4] == 1)&&(b_array[4] == 1)){
			document.getElementById('s_address_1').value = '';
		}
		if((a_array[5] == 1)&&(b_array[5] == 1)){
			document.getElementById('s_address_2').value = '';
		}
		if((a_array[6] == 1)&&(b_array[6] == 1)){
			document.getElementById('s_postcode').value = '';
		}
		if((a_array[7] == 1)&&(b_array[7] == 1)){
			document.getElementById('s_city').value = '';
		}
		if((a_array[8] == 1)&&(b_array[8] == 1)){
			document.getElementById('s_country').value = '';
		}
		if((a_array[9] == 1)&&(b_array[9] == 1)){
			document.getElementById('s_state').value = '';
		}
		if((a_array[10] == 1)&&(b_array[10] == 1)){
			document.getElementById('s_phone').value = '';
		}
		if((a_array[11] == 1)&&(b_array[11] == 1)){
			document.getElementById('s_fax').value = '';
		}
		if((a_array[12] == 1)&&(b_array[12] == 1)){
			document.getElementById('s_email').value = '';
		}
		if((a_array[13] == 1)&&(b_array[13] == 1)){
			document.getElementById('s_cnp').value = '';
		}
	}
}

function change_s(val, field, contor, a_array, b_array){

	if(document.getElementById('same').checked == false){

		if((a_array[contor] == 1)&&(b_array[contor] == 1)){

			document.getElementById(field).value = val;

		}

	}

}



function pad_with_zeros(rounded_value, decimal_places) {



    // Convert the number to a string

    var value_string = rounded_value.toString()

    

    // Locate the decimal point

    var decimal_location = value_string.indexOf(".")



    // Is there a decimal point?

    if (decimal_location == -1) {

        

        // If no, then all decimal places will be padded with 0s

        decimal_part_length = 0

        

        // If decimal_places is greater than zero, tack on a decimal point

        value_string += decimal_places > 0 ? "." : ""

    }

    else {



        // If yes, then only the extra decimal places will be padded with 0s

        decimal_part_length = value_string.length - decimal_location - 1

    }

    

    // Calculate the number of decimal places that need to be padded with 0s

    var pad_total = decimal_places - decimal_part_length

    

    if (pad_total > 0) {

        

        // Pad the string with 0s

        for (var counter = 1; counter <= pad_total; counter++) 

            value_string += "0"

        }

    return value_string

}



function number_format(original_number, decimals) {

    var result1 = original_number * Math.pow(10, decimals)

    var result2 = Math.round(result1)

    var result3 = result2 / Math.pow(10, decimals)

    return pad_with_zeros(result3, decimals)

}



function calculate_total(value1, value2, mii, zecimi){

	var a_value = value1.split("_");

	var a = number_format(parseFloat(a_value[1]) + parseFloat(value2), 2).split(".");

	var contor = 0;

	var a_intors = new Array();

	if(a[0].length > 3){

		for(i=(a[0].length-1);i>=0;i--){

			if(contor == 3){

				a_intors = a_intors + mii ;

				contor = 0;

			}

			a_intors = a_intors + a[0].charAt(i);

			contor++;

		}

		var a_bun = "";

		for(i=(a_intors.length-1);i>=0;i--){

			a_bun = a_bun + a_intors.charAt(i);	

		}

		a[0] = a_bun;

	}

	var total_new = a[0] + zecimi +a[1];

	document.getElementById('total_order_value').style.width = total_new.length*6 + 'px';

	document.getElementById('total_order_value').value = a[0] + zecimi +a[1];

	

	var a = number_format(a_value[3], 2).split(".");

	var contor = 0;

	var a_intors = new Array();

	if(a[0].length > 3){

		for(i=(a[0].length-1);i>=0;i--){

			if(contor == 3){

				a_intors = a_intors + mii ;

				contor = 0;

			}

			a_intors = a_intors + a[0].charAt(i);

			contor++;

		}

		var a_bun = "";

		for(i=(a_intors.length-1);i>=0;i--){

			a_bun = a_bun + a_intors.charAt(i);	

		}

		a[0] = a_bun;

	}

	

	document.getElementById('shipping_vat_value').value = a[0] + zecimi +a[1];

}



showRow = (navigator.appName.indexOf("Internet Explorer") != -1) ? "block" :"table-row";

function hide_tr_(val, val_total){

	for(i = 1; i < val_total; i++){

		if(val == i){

			window.document.getElementById("tr" + val).style.display = showRow;

		}else{

			window.document.getElementById("tr" + i).style.display = "none";

		}

	}

}



//showRow = (navigator.appName.indexOf("Internet Explorer") != -1) ? "block" :"table-row";

function hide_tr(){

	if(document.getElementById('same').checked == true){

		window.document.getElementById("tr1").style.display = "none";

		window.document.getElementById("tr2").style.display = "none";

		window.document.getElementById("tr3").style.display = "none";

		window.document.getElementById("tr4").style.display = "none";

		window.document.getElementById("tr5").style.display = "none";

		window.document.getElementById("tr6").style.display = "none";

		window.document.getElementById("tr7").style.display = "none";

		window.document.getElementById("tr8").style.display = "none";

		window.document.getElementById("tr9").style.display = "none";

		window.document.getElementById("tr10").style.display = "none";

		window.document.getElementById("tr11").style.display = "none";

		window.document.getElementById("tr12").style.display = "none";

		//window.document.getElementById("tr13").style.display = "none";

	}else{

		window.document.getElementById("tr1").style.display = showRow;

		window.document.getElementById("tr2").style.display = showRow;

		window.document.getElementById("tr3").style.display = showRow;

		window.document.getElementById("tr4").style.display = showRow;

		window.document.getElementById("tr5").style.display = showRow;

		window.document.getElementById("tr6").style.display = showRow;

		window.document.getElementById("tr7").style.display = showRow;

		window.document.getElementById("tr8").style.display = showRow;

		window.document.getElementById("tr9").style.display = showRow;

		window.document.getElementById("tr10").style.display = showRow;

		window.document.getElementById("tr11").style.display = showRow;

		window.document.getElementById("tr12").style.display = showRow;

		//window.document.getElementById("tr13").style.display = showRow;

	}

}



function display_tr(){
	if(document.getElementById('gift').checked == true){
		document.getElementById('tr_gift').style.display = showRow;
	}else{
		document.getElementById('tr_gift').style.display = "none";
	}
}



//dummy function

function nd(){

}


