
//GLOBAL VARIABLES 

SS_CODE_URL = 'http://gladkovsoft.com/';

// 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.visibility = "hidden" ;
  }
  
function addAC(value)
{
	
	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)); 
	profit = parseInt(saleValue) - parseInt(costValue);
	
	document.getElementById('totalCostAll').innerHTML = currFormat(costValue.toString())+" JPY ";

	document.getElementById('divPl').innerHTML	 = currFormat(profit.toString())+" JPY "; 
}
function addSC(value)
{
	var costValue = parseInt(revCurrFormat(document.cmpFrm.oldCostTotal.value)) +  parseInt(revCurrFormat(document.cmpFrm.auction_charges.value)); 
	var saleValue = parseInt(revCurrFormat(document.cmpFrm.sales_price.value)) +  parseInt(revCurrFormat(value)); 
	profit = parseInt(saleValue) - parseInt(costValue);
	
	document.getElementById('totalCostAll').innerHTML = currFormat(costValue.toString())+" JPY ";

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

    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)
		window.location.href = aurl;
}
function cancelRecord(page,uid){
	
//	alert("page is "+page+"  uid"+uid);
	var answer = confirm("Are you sure to cancel?");
	aurl=page+"?id="+uid;
	if(answer)
		window.location.href = aurl;
}

function delRecords(page,condition){
	
	var answer = confirm("Are you sure to delete?");
	url=page+"?"+condition;
	//alert(url);
	if(answer)
		window.location.href = 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 calInUsd(){
//	alert("cal in usd");
	var rate = document.cmpFrm.xchange_rate
	if(rate.value==0 || rate.value.length==0){
		rate.value = 1;
	}
	document.cmpFrm.total_usd.value = currFormat(Math.ceil(revCurrFormat(document.cmpFrm.total.value)/revCurrFormat(rate.value)).toString());
	
}
function calInJPY(){
	//	alert("cal in jpy");
	var rate = parseInt(document.cmpFrm.xchange_rate.value);
	if(document.cmpFrm.shipping_rate.value!='' ||document.cmpFrm.shipping_rate.value!=0)
	document.cmpFrm.shipping_fee.value = currFormat((Math.round((revCurrFormat(document.cmpFrm.shipping_rate.value) * rate)*100)/100)+3000);
	document.cmpFrm.shipping_fee.value = currFormat(document.cmpFrm.shipping_fee.value);
}
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");

	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')
		frmField.innerHTML = currFormat(profit.toString())+" JPY";
	else
		frmField.value =  currFormat(profit.toString())+" JPY";
}

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
*/
