
//GLOBAL VARIABLES 

SS_CODE_URL = 'http://www.inter-fairline.com/jidousha/';

// THIS FUNCTION DISPLAYS A HIDDEN CSS LAYER //  
  function showDiv(id){
      document.getElementById(id).style.display = "block" ;
  }
   // THIS FUNCTION HIDES A  CSS LAYER //
  function hideDiv(id){
      document.getElementById(id).innerHTML ="";
	  document.getElementById(id).style.display = "none" ;
  }
function addAC(value)
{
	if(document.cmpFrm.oldCostTotal.value=='')
		document.cmpFrm.oldCostTotal.value = 0;
	if(value=='')
		value = 0;
	if(document.cmpFrm.sales_price.value=='')
		document.cmpFrm.sales_price.value = 0;
	if(document.cmpFrm.service_charges.value=='')
		document.cmpFrm.service_charges.value = 0;
	var costValue = parseInt(revCurrFormat(document.cmpFrm.oldCostTotal.value)) +  parseInt(revCurrFormat(value)); 
	var saleValue = parseInt(revCurrFormat(document.cmpFrm.sales_price.value)) +  parseInt(revCurrFormat(document.cmpFrm.service_charges.value)); 
	var costValue_dollar = (parseInt(costValue) /  parseInt(revCurrFormat(document.cmpFrm.xchange_rate.value))).toFixed(2); 	
	profit = parseInt(saleValue) - parseInt(costValue);
	document.getElementById('totalCostAll').innerHTML = currFormat(costValue.toString())+" JPY ("+costValue_dollar+" $)";
	var profit_dollar = (parseInt(profit) /  parseInt(revCurrFormat(document.cmpFrm.xchange_rate.value))).toFixed(2); 	
	document.getElementById('divPl').innerHTML	 = currFormat(profit.toString())+" JPY ("+profit_dollar+" $)"; 
}
function addSC(value)
{

	if(value=='')
	value = 0 ;
	if(document.cmpFrm.oldCostTotal.value=='')
		document.cmpFrm.oldCostTotal.value = 0;
	if(value=='')
		value = 0;
	if(document.cmpFrm.auction_charges.value=='')
		document.cmpFrm.auction_charges.value = 0;
	if(document.cmpFrm.sales_price.value=='')
		document.cmpFrm.sales_price.value = 0;

	if(document.cmpFrm.auction_charges.value!=0)
	{
		var costValue = parseInt(revCurrFormat(document.cmpFrm.oldCostTotal.value)) +  parseInt(revCurrFormat(document.cmpFrm.auction_charges.value)); 
		document.getElementById('totalCostAll').innerHTML = currFormat(costValue.toString())+" JPY ";
	}	
	else
		var costValue = parseInt(revCurrFormat(document.cmpFrm.oldCostTotal.value)); 
	
	var saleValue = parseInt(revCurrFormat(document.cmpFrm.sales_price.value)) +  parseInt(revCurrFormat(value)); 
	profit = parseInt(saleValue) - parseInt(costValue);
	var profit_dollar = (parseInt(profit) /  parseInt(revCurrFormat(document.cmpFrm.xchange_rate.value))).toFixed(2); 	

	document.getElementById('divPl').innerHTML	 = currFormat(profit.toString())+" JPY ("+profit_dollar+" $)"; 
}

    function showDivVis(id){
      document.getElementById(id).style.visibility="visible";
    }
   // THIS FUNCTION HIDES A  CSS LAYER //
  function hideDivVis(id){
      document.getElementById(id).style.visibility="hidden";

  }
  
// JavaScript Document
function delRecord(page,uid){
	
//	alert("page is "+page+"  uid"+uid);
	var answer = confirm("Are you sure to delete?");
	aurl=page+"?id="+uid;
      if(answer){
        if(navigator.appName == "Microsoft Internet Explorer"){	// INTERNET EXPLORER HACK FOR FIXING DELETE // ASAD 26-06-2008
            SideBar_RedirectUrl = aurl;
			setTimeout( "window.location.href = SideBar_RedirectUrl", 0 );
        }else{
            window.location = aurl;
        }
     }
}
function cancelRecord(page,uid){
	
//	alert("page is "+page+"  uid"+uid);
	var answer = confirm("Are you sure to cancel?");
	aurl=page+"?id="+uid;
	alert(aurl);
	if(answer)
		window.location.href = aurl;
}
function cancelRecord1(page,uid){
	
//	alert("page is "+page+"  uid"+uid);
	var answer = confirm("Are you sure to cancel?");
	aurl=page
	if(answer)
		window.location.href = aurl;
}

function sentRecord(page,uid){
 	var answer1 = confirm("Are you want to replace values with existing or not?");
	if(answer1)
    	aurl=page+"rep_values=1";
    else   
	    aurl=page;
    var answer = confirm("Are you sure to sent the Invoice?");
	if(answer)
		window.location.href = aurl;
}

function delRecords(page,condition){
	
	var answer = confirm("Are you sure to delete?");
	url=page+"?"+condition;

   	if(answer){
        if(navigator.appName == "Microsoft Internet Explorer"){	// INTERNET EXPLORER HACK FOR FIXING DELETE // ASAD 26-06-2008
            SideBar_RedirectUrl = url;
			setTimeout( "window.location.href = SideBar_RedirectUrl", 0 );
        }else{
            window.location = url;
        }
     }
}
function showHide(val){
	alert(val);
}

function add5Per(field){
	val = document.getElementById(field).value;
	temp = val.split(",");
	val ='';
//	alert("Hello");
	for(i=0; i<temp.length; i++){
		val+=temp[i];
	}
	// CHECKING IF THE VALUE IS VALID NUMBER //
	cBox = field+'cb';	
	if(isNaN(val) ||(val =='')){
		alert("Please Enter a Valid Numeric Value");
		document.getElementById(cBox).checked=0;	
		document.getElementById(cBox).value=0;	
		document.getElementById(field).value = '';
		document.getElementById(field).focus();		
	}else{
		if(document.getElementById(cBox).checked==1){
			document.getElementById(field+'h').value = val;
			document.getElementById(cBox).value=1;	
			document.getElementById(field).value = Math.round((parseInt(val))+parseInt((val*0.05)))
		}
		else if(document.getElementById(cBox).checked==0){
			if(document.getElementById(field+'h').value != ''){
				document.getElementById(field).value = document.getElementById(field+'h').value;
				document.getElementById(field+'h').value = '';
			}
		}// END CHECKED = 1
		document.getElementById(field).value = currFormat(document.getElementById(field).value);
	} // END IF VAL
} // END FUNCTION ADD 5 PER

function clearField(field){
	cBox = field+'cb';
	hField = field+'h';

	document.getElementById(cBox).checked=0;
	document.getElementById(field+'h').value = '';
}


function currFormat(value, field){
	ss = value.toString();
	if(ss.indexOf(',')==-1){
		var i=0;
		var val='';
		var str='';
	//	alert(ss.substr(0,1));	
		var len = value.length;
			if(len > 3){	
				for(j=len;j>0;j--){
					if(i==3){
						val+=',';	
						i=0;
					}
					temp = ss.substr(j-1,1);
					val += temp;			
				i++;
				} // END FIRST FOR LOOP
			}else{
				return value;	
			}// END IF LEN > 3
			
		for(j = val.length; j >0; j--){
			str += val.substr(j-1,1)	
		}// END FOR LOOP
	
	if(field!=null){
		document.getElementById(field).value = str;
	}else
	return str;	
	} // END IF INDEX OF
}

// START FUNCTION REV CURRENCY FORMAT
function revCurrFormat(value, field){
	var str='';		
	var temp = '';
		for(j = 0; j < value.length; j++){
			temp = value.substr(j,1);
			if(temp != ","){
				str += temp;
			}
			temp='';
		}// END FOR LOOP
	
	if(field!=null){
		document.getElementById(field).value = str;
	}else
	return str;	
} // END FUNCTION REV CURRENCY FORMAT

function emptyFields(){
	
	document.getElementById('car_price').value='';
	document.getElementById('consumption_tax').value='';
	document.getElementById('auction_fee').value='';
	document.getElementById('road_tax').value='';
	document.getElementById('recycle_charges').value='';
	document.getElementById('inland_transport').value='';
	document.getElementById('forwader_fee').value='';
	document.getElementById('service_fee').value='';
	document.getElementById('shipping_fee').value='';
	document.getElementById('insurance').value='';	
	document.getElementById('misc_charges').value='';
	document.getElementById('total').value='';
	document.getElementById('total_usd').value='';
}

function calInUsd(){
//	alert("cal in usd");
	var rate = document.getElementById('xchange_rate');
	var rate_purchase = document.getElementById('pur_xchange_rate');
//	alert(rate_purchase);
					total_amount = 0;
					if(document.getElementById('inland_transport').value!='')
						total_amount += parseInt(revCurrFormat(document.getElementById('inland_transport').value));
					if(document.getElementById('forwader_fee').value!='')					
						total_amount += parseInt(revCurrFormat(document.getElementById('forwader_fee').value));
					if(document.getElementById('service_fee').value!='')					
						total_amount += parseInt(revCurrFormat(document.getElementById('service_fee').value));
					if(document.getElementById('shipping_fee').value!='')					
						total_amount += parseInt(revCurrFormat(document.getElementById('shipping_fee').value));
					if(document.getElementById('insurance').value!='')					
						total_amount += parseInt(revCurrFormat(document.getElementById('insurance').value));
					if(document.getElementById('CC1').value!='')					
						total_amount += parseInt(revCurrFormat(document.getElementById('CC1').value));
					if(document.getElementById('CC2').value!='')					
						total_amount += parseInt(revCurrFormat(document.getElementById('CC2').value));
						//total_amount += parseInt(revCurrFormat(document.getElementById('road_tax').value));
						//total_amount += parseInt(revCurrFormat(document.getElementById('recycle_charges').value));
					if(! document.getElementById('ECC').value.length == 0)
						total_amount += parseInt(revCurrFormat(document.getElementById('ECC').value));
					if(document.getElementById('misc_charges').value!='')					
						total_amount += parseInt(revCurrFormat(document.getElementById('misc_charges').value));
					if(document.getElementById('shipping_rate').value!='')					
						total_amount += parseInt(revCurrFormat(document.getElementById('shipping_rate').value));

	if(rate.value==0 || rate.value.length==0){
		rate.value = 1;
	}
	if( rate_purchase.value == 0 || rate_purchase.value=='' || rate_purchase.value.length==0)
		rate_purchase.value = 1;


	new_rate= parseFloat(total_amount/revCurrFormat(rate.value));
	car_rate= parseFloat(revCurrFormat(document.getElementById('car_price').value)/revCurrFormat(rate_purchase.value));
	tax_rate= parseFloat(revCurrFormat(document.getElementById('consumption_tax').value)/revCurrFormat(rate_purchase.value));	
	rec_rate= parseFloat(revCurrFormat(document.getElementById('recycle_charges').value)/revCurrFormat(rate_purchase.value));	
	aucc_rate= parseFloat(revCurrFormat(document.getElementById('auction_fee').value)/revCurrFormat(rate_purchase.value));	
	road_rate= parseFloat(revCurrFormat(document.getElementById('road_tax').value)/revCurrFormat(rate_purchase.value));	
	document.getElementById('total_usd').value = currFormat((parseInt(parseFloat(new_rate)+parseFloat(car_rate)+parseFloat(tax_rate)+parseFloat(rec_rate)+parseFloat(aucc_rate)+parseFloat(road_rate))).toString());
    document.getElementById('hdn_total_usd').value = revCurrFormat(document.getElementById('total_usd').value);
	
	
}

function calInJPY(){
	var b=0;
	//	alert("cal in jpy");
//	var rate = parseInt(document.getElementById('xchange_rate').value);
//	if(document.getElementById('shipping_rate').value!='' ||document.getElementById('shipping_rate').value!=0)
//	document.getElementById('shipping_fee').value = currFormat((Math.round((revCurrFormat(document.getElementById('shipping_rate').value) * rate)*100)/100)+3000);
//	document.getElementById('shipping_fee').value = currFormat(document.getElementById('shipping_fee').value);
//continue;
}
function checkNum(field){ // THE FUNCTION CHECKS IF THERE IS ANY NUMERIC VALUE ENTERED INTO THE SYSTEM IF NOT IT WILL ENTER ONE OF ITSELF
	field.value = (field.value.length==0)  ? 0 : field.value;
	field.value = (isNaN(revCurrFormat(field.value))) ? 0 : field.value
}

function profitLoss(val1, valField, field, type, other){
//	alert("I AM IN");
if(val1=='')
	val1=0;
if(valField=='')
	valField=0;
if(other=='')
	other=0;
if(document.getElementById('service_charges').value=='')
document.getElementById('service_charges').value = 0;
	var frmField = document.getElementById(field);
	var profit=0;

//	alert(val1+" "+valField+" "+field);
	var auction_charges = revCurrFormat(document.getElementById('auction_charges').value);
	var service_charges = revCurrFormat(document.getElementById('service_charges').value);

	if(isNaN(auction_charges))
		auction_charges = 0;
	if(isNaN(val1))
		val1= 0;
	if(isNaN(valField))
		valField=0;

	var profit = (parseInt(val1)+parseInt(service_charges))-((parseInt(valField)+parseInt(auction_charges)));
	//alert(parseInt(valField)+parseInt(revCurrFormat(auction_charges)));
	if(other=="")
		other=0;
	
	if(isNaN(profit))
		profit = 0;
		
	if(type =='div')
		{
			var profit_dollar = (parseInt(profit) /  parseInt(revCurrFormat(document.cmpFrm.xchange_rate.value))).toFixed(2); 	
			frmField.innerHTML = currFormat(profit.toString())+" JPY ("+profit_dollar+" $)";
		}
	else
			var profit_dollar = (parseInt(profit) /  parseInt(revCurrFormat(document.cmpFrm.xchange_rate.value))).toFixed(2); 	
			frmField.innerHTML = currFormat(profit.toString())+" JPY ("+profit_dollar+" $)";
}

function showClient(){
	document.getElementById('vendor').style.visibility = 'hidden'; 	
	document.getElementById('client').style.visibility = 'visible'; 
}
function showVendor(){
	document.getElementById('client').style.visibility = 'hidden'; 	
	document.getElementById('vendor').style.visibility = 'visible'; 
}
function hideDivs(){
	document.getElementById('client').style.visibility = 'hidden'; 	
	document.getElementById('vendor').style.visibility = 'hidden'; 
}
//CONVERT TEXT IN TEXTBOX TO UPPERCASE
function toUpper(){
	document.cmpFrm.model_no.value = document.cmpFrm.model_no.value.toUpperCase();
}
function redirect(){
	window.location = "../_subpages/cpVehicle.php";
}

// THIS FUNCTION RETRIEVES CURRENCY DATA FROM GLOBAL CURRENCY CALCULATOR
// THE VARIABLE BASE CURR IS NOT IN USE CURRENTLY
/*function getExchangRate(url,targetCurr,  baseCurr){
			  try {
					 try {
						   netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
					   } catch (e) { document.write(e.toString()); alert("Permission UniversalBrowserRead denied."); }
			  
				http_request = new XMLHttpRequest();
			  }catch(trymicrosoft){
								  try {
									http_request = new ActiveXObject("Msxml2.XMLHTTP");
									  }catch (othermicrosoft) {
										 try {
											http_request = new ActiveXObject("Microsoft.XMLHTTP");
										  } catch (failed){
											   http_request = false;
						  			  } // END CATCH OTHERMICROSOFT
								  }//END CATCH TRY MICROSOFT
			  }//end CATCH TRY MICROSOFT

			 if (!http_request)
				alert("INITILIZATION ERROR");
			
			
			
			try{
				http_request.open('POST', url,true)
			 } 
			 catch(err){document.write(err.toString());}
			 http_request.onreadystatechange = handleExchangeRateReposone;     	
			 try{
				http_request.send(null);		
			}catch(err){document.write(err.toString());}	
}

function handleExchangeRateReposone(){
		var xmldoc = http_request.responseXML;
		if(http_request.readyState == 4){
			
		}// END IF
} // END HANDLE EXCHANGE RATE
*/

