var url;

function addCategory_Check(item) {

	if (item.categoryName.value != '' && item.categoryName.value != item.previousValue.value) {
		follow_link_NO_LOADER('admin/admin.inc.php?area=addCategory_showSubmitButton', 'addCategory_SubmitSpan');
	}
	else {
		follow_link_NO_LOADER('blank.html', 'addCategory_SubmitSpan');
	}
}

function addManufacturer_Check(item) {

	if (item.rename.value == 'rename') {
		if ((item.manufacturerName.value != '' && item.manufacturerName.value != item.manufacturerName_previousValue.value) || 
			(item.manufacturerLink.value != '' && item.manufacturerLink.value != item.manufacturerLink_previousValue.value)) {
			follow_link_NO_LOADER('admin/admin.inc.php?area=addManufacturer_showSubmitButton', 'addManufacturer_SubmitSpan');
		}
		else {
			follow_link_NO_LOADER('blank.html', 'addManufacturer_SubmitSpan');
		}
	}
	else {
		if (item.manufacturerName.value != '' && item.manufacturerName.value != item.manufacturerName_previousValue.value && 
			item.manufacturerLink.value != '' && item.manufacturerLink.value != item.manufacturerLink_previousValue.value) {
			follow_link_NO_LOADER('admin/admin.inc.php?area=addManufacturer_showSubmitButton', 'addManufacturer_SubmitSpan');
		}
		else {
			follow_link_NO_LOADER('blank.html', 'addManufacturer_SubmitSpan');
		}
	}
}

function addProduct_Check(item) {

	if (item.action.value == 'edit'){
		if (	(item.productName.value != '' && item.productName.value != item.productName_previousValue.value) || 
			(item.productCategory.value != '0' && item.productCategory.value != item.productCategory_previousValue.value) || 
			(item.productSubCategory.value != '0' && item.productSubCategory.value != item.productSubCategory_previousValue.value) || 
			(item.productManufacturer.value != '0' && item.productManufacturer.value != item.productManufacturer_previousValue.value) || 
			(item.productManufacturerCode.value != '' && item.productManufacturerCode.value != item.productManufacturerCode_previousValue.value) || 
			(item.productDescShort.value != '' && item.productDescShort.value != item.productDescShort_previousValue.value) || 
			(item.productPrice.value != '' && item.productPrice.value != item.productPrice_previousValue.value && IsNumeric(item.productPrice.value) == true)) {
			follow_link_NO_LOADER('products/products.inc.php?area=addProduct_showSubmitButton', 'addProduct_SubmitSpan');
		}
		else {
			follow_link_NO_LOADER('blank.html', 'addProduct_SubmitSpan');
		}
	}
	else {
		if (	item.productName.value != '' && item.productName.value != item.productName_previousValue.value && 
			item.productCategory.value != '0' && item.productCategory.value != item.productCategory_previousValue.value && 
			item.productSubCategory.value != '0' && item.productSubCategory.value != item.productSubCategory_previousValue.value && 
			item.productManufacturer.value != '0' && item.productManufacturer.value != item.productManufacturer_previousValue.value && 
			item.productManufacturerCode.value != '' && item.productManufacturerCode.value != item.productManufacturerCode_previousValue.value && 
			item.productDescShort.value != '' && item.productDescShort.value != item.productDescShort_previousValue.value && 
			item.productPrice.value != '' && item.productPrice.value != item.productPrice_previousValue.value && IsNumeric(item.productPrice.value) == true) {
			follow_link_NO_LOADER('products/products.inc.php?area=addProduct_showSubmitButton', 'addProduct_SubmitSpan', 'no');
		}
		else {
			follow_link_NO_LOADER('blank.html', 'addProduct_SubmitSpan');
		}
	}
}

function addShippingDetails_Check(item) {

	if (	item.Name.value != '' &&
		item.Address.value != '' &&
		item.City.value != '' &&
		item.State.value != '' &&
		item.Country.value != 0 &&
		item.Plz.value != '' &&
		item.Phone.value != '') {
		item.submit.disabled = false;
	}
	else {
		item.submit.disabled = true;
	}
}

function addSubCategory_Check(item) {

	if (item.subCategoryName.value != '' && item.subCategoryName.value != item.previousValue.value) {
		follow_link_NO_LOADER('admin/admin.inc.php?area=addSubCategory_showSubmitButton', 'addSubCategory_SubmitSpan');
	}
	else {
		follow_link_NO_LOADER('blank.html', 'addSubCategory_SubmitSpan');
	}
}

function confirmDeleteProduct(productsID, categoryID, subCategoryID, manufacturerID, sid) {

	if (confirm("Do you really want to delete the selected product?")) {
		follow_link('products/products.inc.php?area=deleteProduct&productsID=' + productsID + '&categoryID=' + categoryID + '&subCategoryID=' + subCategoryID + '&manufacturerID=' + manufacturerID + '&sid=' + sid, 'mainFrame');
	}
}

function login_submitCheck(item) {

	if (item.user_Login.value == "" || item.user_Password.value == "") {
		item.submit.disabled = true;
	}
	else {
		item.submit.disabled = false;
	}
}

function login_submitCheckMainFrame(item) {

	if (item.user_Login.value == "" || item.user_Password.value == "") {
		item.mainFrameSubmit.disabled = true;
	}
	else {
		item.mainFrameSubmit.disabled = false;
	}
}

function IsNumeric(some_string) {

	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < some_string.length && IsNumber == true; i++) { 
		Char = some_string.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function IsEmail(some_string) {

	var ValidChars1 = "0123456789abcdefghijklmnropqrstuvwxyz_-@.";
	var ValidChars2 = "@.";
	var IsEmail=true;
	var gotAt=false;
	var Char;

	for (i = 0; i < some_string.length && IsEmail == true; i++) { 
		Char = some_string.charAt(i); 
		if (ValidChars1.indexOf(Char) == -1) {
			IsEmail = false;
		}
	}

	if (IsEmail == true) {
		for (i = 0; i < ValidChars2.length && IsEmail == true; i++) { 
			Char = ValidChars2.charAt(i); 
			if (some_string.indexOf(Char) == -1) {
				IsEmail = false;
			}
		}
	}

	return IsEmail;
}

function registerCheck(item) {
	if (	item.userLogin.value == "" ||
		item.userPassword.value == "" ||
		item.userPasswordConfirm.value == "" ||
		item.userPassword.value != item.userPasswordConfirm.value ||
		item.userTitle.value == "0" ||
		item.userFirst.value == "" ||
		item.userLast.value == "" ||
		item.userEmail.value == "" ||
		item.userPhone.value == "" ||
		item.userAddress.value == "" ||
		item.userCity.value == "" ||
		item.userState.value == "" ||
		item.userPLZ.value == "" ||
		item.userCountry.value == "0") {
		item.submit.disabled = true;
	}
	else {
		item.submit.disabled = false;
	}
}

function registerCheckEmail(item, SpanID) {
	if (IsEmail(item.userEmail.value) == true) {
		follow_link_NO_LOADER('user/user.inc.php?area=checkEmail&result=1', SpanID);
		registerCheck(item);
	}
	else {
		follow_link_NO_LOADER('user/user.inc.php?area=checkEmail&result=0', SpanID);
		item.submit.disabled = true;
	}
}

function registerCheckLogin(item, SpanID) {

	follow_link_NO_LOADER('user/user.inc.php?area=checkLogin&login=' + item.userLogin.value, SpanID);

	registerCheck(item);
}

function registerCheckPassword(item, SpanID) {

	follow_link_NO_LOADER('user/user.inc.php?area=checkPassword&password=' + item.userPassword.value + '&passwordConfirm=' + item.userPasswordConfirm.value, SpanID);

	registerCheck(item);
}

function shippingAddress_delete(userID, postalID, domainRoot, SpanID) {

	if (confirm("Do you really want to delete the selected product?")) {
		follow_link(domainRoot + '/user/user.inc.php?area=deleteShippingAddress&postalID=' + postalID + '&userID=' + userID, SpanID);
	}
}
function shippingDetails(itemID, userID, SpanID, showOptions) {

	if (itemID == "add") {
		follow_link('user/user.inc.php?area=addShippingDetails&userID=' + userID, SpanID);
	}
	else {
		follow_link('user/user.inc.php?area=showShippingDetails&userID=' + userID + '&postalID=' + itemID + '&showOptions=' + showOptions, SpanID);
	}
}

function specialsPrice_Check(item, SpanID) {
		
	if (		IsNumeric(item.specialsPrice.value) == false ||
			item.specialsPrice.value == '' ||
			item.validFrom_Checkbox.checked == false ||
			item.validUntil_Checkbox.checked == false) {
		follow_link_NO_LOADER('specials/specials.inc.php?area=specialsSubmitButton&show=0', SpanID);
	}
	else {
		follow_link_NO_LOADER('specials/specials.inc.php?area=specialsSubmitButton&show=1&productID=' + item.productID.value + '&specialsPrice=' + item.specialsPrice.value + '&validFrom=0000-00-00&validUntil=9999-12-31&frontPage=' + item.frontPage_Checkbox.checked, SpanID);
	}

}

