//function for rounding on 4 decimal places
function round_price(price){
	return (Math.round(10000*price))/10000;
	}
	
//function for checking decimal value
function check_number(obj){
	var tes_val;
	re = /[^0-9.]/;
	re2=/\,/;
	obj.value=obj.value.replace(re2,"");
	test_val=parseFloat(obj.value);
	
	if(isNaN(test_val)){
		
		obj.value="";
	}else{
		obj.value=parseFloat(obj.value);
	}
	obj.val=parseFloat(obj.value);
	if(re.test(obj.value)){
		alert("Valid characters for this field are:0-9 and '.' for decimal point.");
		obj.focus();
		
	}else{
		
	}
	
	
}
//function for checking integer value 
function check_int(obj){
	re = /[^0-9\-]/;
	
	var test_val=parseFloat(obj.value);
	
	if(isNaN(test_val)){
		
		obj.value=0;
	}else{
		obj.value=parseFloat(obj.value);
	}
	
	if(re.test(obj.value)){
		alert("Valid characters for this field are:0-9 and '-' for negative values.");
		obj.focus();
		return false;
	}
}

function check_pint(obj){
	re = /[^0-9]/;
	
	var test_val=parseFloat(obj.value);
	
	if(isNaN(test_val)){
		
		obj.value="";
	}else{
		obj.value=parseFloat(obj.value);
	}
	if(re.test(obj.value)){
		alert("Valid characters for this field are:0-9.");
		obj.focus();
		return false;
	}else{
		return true;
	}
	
	
}
//function for checking length of string
function check_str(obj){
	
	re=/\s/g;
	var temp_val=obj.value.replace(re,"");
	if(temp_val.length==0){
		
		return false;
		
	}else{
		return true;
	}
}

function check_email(obj){
	
	re=/\w{0,}[\-\.]?\w{1,}\@\w{1,}[\-\.]?\w{0,}\.\w{2,}/g;
	answ=re.test(obj.value);
	if(!answ){
		alert("E-mail you’ve entered doesn’t seem to be OK!");
		return false;
	}else{
		return true;
	}
	
}

function format_price(str){
	re0=/\.\d{4}/;
	re1=/\.\d{3}/;
	re2=/\.\d{2}/;
	re3=/\.\d{1}/;
	
	if(re0.test(str)){
		return(str);
	}else if(re1.test(str)){
		return(str+"0");
	}else if(re2.test(str)){
		return(str+"00");
	}else if(re3.test(str)){
		return(str+"000");
	}else{
		return(str+".0000");
	}
}

//part for layers and old browsers
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

