
if (document.images) 
{
	img1 = new Image();
	img2 = new Image();
	img3 = new Image();
	img4 = new Image();
	img5 = new Image();
	img6 = new Image();
	img7 = new Image();
	img8 = new Image();
	img9 = new Image();
	img10 = new Image();
	img11 = new Image();
	img12 = new Image();
	img13 = new Image();
	img14 = new Image();
	
	img1.src = "images/home_on.gif";
	img2.src = "images/aboutus_on.gif"
	img3.src = "images/stores_on.gif"
	img4.src = "images/register_on.gif"
	img5.src = "images/links_on.gif"
	img6.src = "images/employment_on.gif"
	img7.src = "images/contactus_on.gif"
	img8.src = "images/specialoffers_on.gif"
	img9.src = "images/yourbasket_on.gif"
	img10.src = "images/youraccount_on.gif"
	img11.src = "images/emptybasket_on.gif"
	img12.src = "images/checkout_on.gif"
	img13.src = "images/carryonshopping_on.gif"
	img14.src = "images/news_on.gif"
}

 
function UrbanRockInfoTerms(theForm)
{
	//theForm = document.forms[3];
	frmlocation = theForm.Terms.options[theForm.Terms.selectedIndex].value;	
	if(frmlocation != "-1")
		self.location = frmlocation;
	else
		return false;
	return true;
}

function validateSearchForm(theForm)
{

	if (!validNumbers(theForm.frmSearch,"Title"))
		
		return false;		
	return true;
}

function swapImg(name,over)
{
	if(document.images) 
	{
		if (over)
		{
			//alert(name)
			document.images[name].src = "images/" + name + "_on.gif";
		}
		else
		{
			document.images[name].src = "images/" + name + "_off.gif";
		}
	}
}
function windowPrompt(strMessage, strLocation)
{
	var agree = confirm(strMessage);
	
	//alert(agree + " : " + strLocation);

	if (agree) 
	{
		if(strLocation != "")
		{
			self.location = strLocation;
			
		}
		else
		{
			submitNewsletterForm();
		}
	}
}

function openWindow(frmEmail)
{
	if(frmEmail.value.length > 5) 
	{
		strURL = "newsletter_register.php?frmEmail=" + frmEmail.value
		//alert(frmEmail.value);
		window.open(strURL,"new","menubar=no,toolbar=no,status=no,scrollbars=0,width=300,height=300")
	}
}

function openEditProducts_1_Window(frmEmail)
{
	if(frmEmail.value.length > 5) 
	{
		strURL = "newsletter_register.php?frmEmail=" + frmEmail
		window.open(strURL,"new","menubar=no,toolbar=no,status=no,scrollbars=0,width=300,height=300")
	}
}

function openCategoriesEditWindow(CategoryId, ParentId)
{
	strURL = "CategoriesEditWindow.php?CategoryId=" + CategoryId + "&ParentId=" + ParentId
	window.open(strURL,"new","menubar=no,toolbar=no,status=no,scrollbars=0,width=300,height=50")
}

function openNotesWindow(OrderId, VendorTxCode)
{
	strURL = "orders_add_note.php?OrderId=" + OrderId + "&VendorTxCode=" + VendorTxCode;
	window.open(strURL,"new","menubar=no,toolbar=no,status=no,scrollbars=0,width=400,height=400")
}

function openOrderRefWindow(OrderId)
{
	strURL = "orders_add_reference.php?OrderId=" + OrderId;
	window.open(strURL,"new","menubar=no,toolbar=no,status=no,scrollbars=0,width=400,height=400")
}

function openPostageWindow(OrderId)
{
	strURL = "orders_add_postage.php?OrderId=" + OrderId;
	window.open(strURL,"new","menubar=no,toolbar=no,status=no,scrollbars=0,width=400,height=400")
}

function openStaffWindow(OrderId)
{
	strURL = "orders_add_staff.php?OrderId=" + OrderId;
	window.open(strURL,"new","menubar=no,toolbar=no,status=no,scrollbars=0,width=400,height=400")
}


function openCategoriesProductWindow(CategoryId, ParentId)
{
	//alert("pop up working");
	args = "menubar=no,toolbar=no,status=no,scrollbars=yes,width=300,height=300";
	strName = "new";
	strURL = "CategoriesProductWindow.php";
	
	if (typeof(popupWin) != "object")
	{
		popupWin = window.open(strURL,strName,args);
	} 
	else 
	{
		if (!popupWin.closed)
		{ 
			popupWin.location.href = strURL;
		} 
		else 
		{
			popupWin = window.open(strURL, strName,args);
		}
	}
	popupWin.focus();
}


function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}

function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}

function confirmPassword(formField1, formField2,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField1,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (formField1.value != formField2.value)
 		{
 			alert('Please make sure the"' + fieldLabel +'" fields match.');
			formField1.focus();		
			result = false;
		}
	} 
	
	return result;
}

function validInt(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value,10);
 		if (isNaN(num))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validDate(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var elems = formField.value.split("/");
 		
 		result = (elems.length == 3); // should be three components
 		
 		if (result)
 		{
 			var month = parseInt(elems[0],10);
  			var day = parseInt(elems[1],10);
 			var year = parseInt(elems[2],10);
			result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
					 allDigits(elems[1]) && (day > 0) && (day < 32) &&
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
			formField.focus();		
		}
	} 
	
	return result;
}
