function openWindow(urlLocation, strName, intWidth, intHeight)
{
	return window.open(urlLocation, strName, 'width='+ intWidth +',height='+ intHeight +',toolbar=0,resizable=0');
}

function copyCatagories()
{
	var box = document.getElementById('catagoryBox')
	var choices = new Array
	for (var i = 0; i < box.options.length; i++){
	    if (box.options[i].selected)
	      choices[choices.length] = box.options[i].value;
	}
	document.getElementById('catagoryList').value = choices;
}

function copySizes()
{
	var box = document.getElementById('sizesBox')
	var choices = new Array
	for (var i = 0; i < box.options.length; i++){
	    if (box.options[i].selected)
	      choices[choices.length] = box.options[i].value;
	}
	document.getElementById('sizes').value = choices;
}

function checkInt ( value )
{
	  for(var i=0;i < value.length; ++i)
	  {
		   var new_key = value.charAt(i); //cycle through characters
		   if((new_key < "0") || (new_key > "9") )
		   {
				return false;
				break;
		   }
	  }
	  
	if (value >= 1) {
		return true;
	} else {
		return false;
	}
}

function checkFloat ( value, max  )
{
	if (value.length > (max+1)) return false;
	  for(var i=0;i < value.length; ++i)
	  {
		   var new_key = value.charAt(i); //cycle through characters
		   var no_decimals = 0;
		   if (new_key!=".")
		   {
			   if((new_key < "0") || (new_key > "9"))
			   {
					return false;
					break;
			   }
		   } else
		   {
				no_decimals++;
				if (no_decimals>1) return false;
		   }
	  }
	  
	if (value >= 1) {
		return true;
	} else {
		return false;
	}
}

function emailCheck( str ) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
	return true;
	}
	return false;
}

function checkUpdateCart ( form )
{
  // ** START **
  
    if (form.quantity.value == "") {
    alert( "You must enter a quantity to update" );
    form.quantity.style.backgroundColor = "#e88080";
    form.quantity.focus();
    return false ;
  } else {form.quantity.style.backgroundColor = "white";}

  if (!checkInt(form.quantity.value)) {
	alert( "Please enter a valid integer as a quantity" );
	form.quantity.style.backgroundColor = "#e88080";
	form.quantity.focus();
	return false ;
  } else {form.quantity.style.backgroundColor = "white";}
  
  // ** END **
  return true ;
}

function checkContactForm ( form )
{
  // ** START **
  
    if (form.name.value == "") {
    alert( "You must enter your name" );
    form.name.style.backgroundColor = "#e88080";
    form.name.focus();
    return false ;
  } else {form.name.style.backgroundColor = "white";}
  
    if (form.verify.value == "") {
    alert( "Please enter the verification code" );
    form.verify.style.backgroundColor = "#e88080";
    form.verify.focus();
    return false ;
  } else {form.verify.style.backgroundColor = "white";}

  if (!emailCheck(form.Email.value)) {
	alert( "Please enter a valid email address" );
	form.Email.style.backgroundColor = "#e88080";
	form.Email.focus();
	return false ;
  } else {form.Email.style.backgroundColor = "white";}

  if (form.enquiry.value == "") {
    alert( "You have not entered a message!" );
    form.enquiry.style.backgroundColor = "#e88080";
    form.enquiry.focus();
    return false ;
  } else {form.enquiry.style.backgroundColor = "white";}
  
  // ** END **
  return true ;
}
