/*function betterhandler(description,pagename,lineno)
{
 alert(
  'An Error occurred! \n'
  +'\n Description: \t'+description
  +'\n Page Name:      \t'+pagename
  +'\n At Line :       \t'+lineno
 )
 return true
}
window.onerror=betterhandler;*/
function getExchangeRate(){
  var x=document.getElementById("curExRate");
  document.getElementById('curPos').value=x.selectedIndex;
  if(x.options[x.selectedIndex].value==''){
  	document.getElementById('curCode').value=x.options[x.selectedIndex].text;
	document.getElementById('form1').action='getExchangeRate.php';
  	document.getElementById('form1').submit();
  }else{
	  //alert(x);
	document.getElementById('curCode').value=x.options[x.selectedIndex].text;  
  	document.getElementById('form1').action='itinerary.php';
	document.getElementById('form1').submit();
  }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function cal_total(){
	var x=document.getElementById("curExRate").value;
	var i=0;
	var num_Itinerary=document.getElementById('tblItinerary').rows.length-2;
	var total=parseFloat(0);
	var last_digit='0';
	var total_var='';
	var status_var='';
	for(i=1;i<=num_Itinerary;i++){
		/*alert(i);
		alert(document.getElementById('tblItinerary').rows[i].id.substr(0,1));*/
		last_digit=document.getElementById('tblItinerary').rows[i].id.substr(1);
		if(document.getElementById('tblItinerary').rows[i].id.substr(0,1)=='t'){
			status_var='tour_Rem'+last_digit;
			if(document.getElementById(status_var).checked==false){
				total=total+parseFloat(document.getElementById('tblItinerary').rows[i].cells[4].innerHTML);
			}
		}
		if(document.getElementById('tblItinerary').rows[i].id.substr(0,1)=='h'){
			status_var='hotel_Rem'+last_digit;
			//alert(document.getElementById('tblItinerary').rows[i].cells[4].innerHTML);
			if(document.getElementById(status_var).checked==false){
				total=total+parseFloat(document.getElementById('tblItinerary').rows[i].cells[4].innerHTML);
			}
		}
		if(document.getElementById('tblItinerary').rows[i].id.substr(0,1)=='a'){
			status_var='activity_Rem'+last_digit;
			if(document.getElementById(status_var).checked==false){
				total=total+parseFloat(document.getElementById('tblItinerary').rows[i].cells[4].innerHTML);
			}
		}
		if(document.getElementById('tblItinerary').rows[i].id.substr(0,1)=='s'){
			status_var='spa_Rem'+last_digit;
			if(document.getElementById(status_var).checked==false){
				total=total+parseFloat(document.getElementById('tblItinerary').rows[i].cells[4].innerHTML);
			}
		}
		if(document.getElementById('tblItinerary').rows[i].id.substr(0,1)=='c'){
			status_var='tra_Rem'+last_digit;
			if(document.getElementById(status_var).checked==false){
				total=total+parseFloat(document.getElementById('tblItinerary').rows[i].cells[4].innerHTML);
			}
		}
		//alert (total);
	}
	/*if(x.options[x.selectedIndex].value==''){
		x.options[x.selectedIndex].value=1;	
	}*/
	if(x==''){
		x=1;	
	}
	//document.getElementById('sum_total').innerHTML=total;
	document.getElementById('thbTotal').value=total;
	//total=total/parseFloat(x.options[x.selectedIndex].value);
	//total=total/parseFloat(x);
	document.getElementById('curTotal').value=total;
	//document.getElementById('tblTotal').rows[2].cells[1].innerHTML="<strong>"+document.getElementById('curCode').value+" "+round_decimals(total,2)+"</strong>"
	document.getElementById('tblItinerary').rows[document.getElementById('tblItinerary').rows.length-1].cells[1].innerHTML="<strong>"+document.getElementById('curCode').value+" "+round_decimals(total,2)+"</strong>"
}
function ChangeColor(inIDChang,cnt,valThis) {
	//alert(document.getElementById(inIDChang).style.backgroundColor);
	if(valThis.checked){
		var r=confirm("Are you sure for remove this service")
		if (r==false){
			//document.getElementById(status_var).checked==false
			valThis.checked=false;
			return false;
		}
	}
	var bbgColor='#96b7da';
		if(parseFloat(cnt)%2!=0){
			bbgColor='#96b7da';
		}else{
			bbgColor='#b4d6f1';
		}
     //if (document.getElementById(inIDChang).style.backgroundColor == '#96b7da' || document.getElementById(inIDChang).style.backgroundColor == '#b4d6f1') {
		 if (document.getElementById(inIDChang).style.backgroundColor == bbgColor) {
          document.getElementById(inIDChang).style.backgroundColor = '#CC99CC';
     } else {
          document.getElementById(inIDChang).style.backgroundColor = bbgColor;
     }
	 cal_total();
}
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
	return result3
    //return pad_with_zeros(result3, decimals)
}

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 goBack(){
	document.getElementById('form1').action='index.php';
	document.getElementById('form1').submit();
}
