function changeLocale(objLang) {
	var currentLocation = document.location.href;
	var newPath = currentLocation;
	
	// if the param 'locale' already exists in the URL
	if (currentLocation.indexOf("locale", 0) > -1) {
		var startIndex = currentLocation.indexOf("locale", 0);
		var endIndex = currentLocation.indexOf("&", startIndex);
		if (endIndex == -1) {
			endIndex = currentLocation.length;
		}
		
		newPath = currentLocation.substring(0, startIndex) + "locale=" + objLang.value + currentLocation.substring(endIndex, currentLocation.length);
	} else {
		if (currentLocation.indexOf("?", 0) > -1) {
			newPath += "&";
		} else {
			newPath += "?";
		}
	
		newPath += "locale=" + objLang.value;
	}
	
	document.location = newPath;
}

function validateNumber(obj_target) {
	if (isNaN(obj_target.value)) {
		obj_target.value = "0";
		return false;
	} else {
		obj_target.value = parseFloat(obj_target.value).toFixed(0);
		return true;
	}
}

function validateCurrency(obj_target) {
	if (isNaN(obj_target.value)) {
		obj_target.value = "0";
		return false;
	} else {
		obj_target.value = parseFloat(obj_target.value).toFixed(2);
		return true;
	}
}

function skipPhoneField(index, fieldName, hasExtension) {
	var maxLength = 0;
	if (index == 1 || index == 2) {
		maxLength = 3;
	}
	if (index == 3) {
		maxLength = 4;
	}
	
	var obj = document.getElementsByName(fieldName + "phone" + index)[0];
	if (obj.value.length == maxLength) {
		if (isNaN(obj.value)) {
			obj.value = 0;
			return false;
		}
		
		var nextObj;
		if (index != 3) {
			nextObj = document.getElementsByName(fieldName + "phone" + (index+1))[0];
		} else if (hasExtension) {
			nextObj = document.getElementsByName(fieldName + "extension")[0];
		}
		
		nextObj.focus();
	}
	
	return true;
}

function skipFaxField(index, fieldName) {
	var maxLength = 0;
	if (index == 1 || index == 2) {
		maxLength = 3;
	}
	if (index == 3) {
		maxLength = 4;
	}
	
	var obj = document.getElementsByName(fieldName + "fax" + index)[0];
	if (obj.value.length == maxLength) {
		if (isNaN(obj.value)) {
			obj.value = 0;
			return false;
		}
		
		var nextObj;
		if (index != 3) {
			nextObj = document.getElementsByName(fieldName + "fax" + (index+1))[0];
		}
		
		nextObj.focus();
	}
	
	return true;
}

function skipPostalCodeField(index, fieldName) {
	var maxLength = 3;
	
	var obj = document.getElementsByName(fieldName + "code" + index)[0];
	if (obj.value.length == maxLength) {
		var nextObj;
		if (index != 2) {
			nextObj = document.getElementsByName(fieldName + "code" + (index+1))[0];
		}
		
		nextObj.focus();
	}
	
	return true;
}

function editZone(key) {
	window.open('editZone.htm?key='+key,'_blank');
}

function highlight(zone) {
	zone.style.backgroundColor = '#90ee90';
}

function deselect(zone) {
	zone.style.backgroundColor = 'transparent';
}

function addDays(dateStr,offset) {
 	var day = dateStr.substr(0, 2);
   	var month = dateStr.substr(3, 2);
   	var year = dateStr.substr(6, 4);

   	var myDate = new Date();
   	myDate.setFullYear(parseInt(year, 10), parseInt(month, 10) - 1,parseInt(day, 10));
   	myDate.setDate(myDate.getDate()+offset);
   	
   	day = myDate.getDate();
   	month = myDate.getMonth() + 1;
   	year = myDate.getFullYear();
   	
	return (((day < 10) ? "0" : "")+day)+ "-" 
	        + (((month < 10) ? "0" : "")+month) 
	        + "-" + year;
}
