// JavaScript Document
function openwin(location, name, width, height)
{

w = screen.availWidth;
h = screen.availHeight;

var popW = width, popH = height;
var leftPos = (w-popW)/2, topPos = (h-popH)/2;

window.open(location,name,"toolbars=0,width="+popW+",height="+popH+",top=" + topPos + ",left=" + leftPos + ",screenX= " + leftPos + ",screenY=" + topPos + ",status=0,menubar=0,scrollbars=yes,resizable=no");
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function validate1(whichform)
{
  if (whichform.login.value == "")
 {
    alert ("Please enter your email address");
    whichform.login.select();
    return false;
  }
  checkEmail = whichform.login.value
  if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
  {
    alert("You have entered an invalid email address. Please try again.");
    whichform.login.select();
    return false;
  }

  whichform.voucher.value = trim(whichform.voucher.value);

  if (whichform.voucher.value.length > 10)
  {
    alert("The voucher number you entered is too long");
    whichform.voucher.select();
    return false;
  }
      if ((whichform.voucher.value.length < 10) && (whichform.voucher.value.length != 0))
  {
    alert("The voucher number you entered is too short");
    whichform.voucher.select();
    return false;
  }

  return true;
}

function validate2(whichform)
{
  if (whichform.password.value == "")
  {
    alert ("Please enter a password");
    whichform.password.select();
    return false;
  }
   return true;
}

function validate3(whichform)
{

  checkEmail = whichform.email.value
  if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
  {
    alert("You have entered an invalid email address. Please try again.");
    whichform.email.select();
    return false;
  }

  if (whichform.firstName.value == "")
 {
    alert ("Please enter your name");
    whichform.firstName.select();
    return false;
  }
  
    if (whichform.surName.value == "")
 {
    alert ("Please enter your surname");
    whichform.surName.select();
    return false;
  }
    
      if (whichform.contactNumber.value == "")
 {
    alert ("Please enter your contact number");
    whichform.contactNumber.select();
    return false;
  }

  if (whichform.agree.checked==false)
  {
    alert ("Please read the flyphoto terms and conditions (you can see them by clicking on \"Terms & Conditions\" below), and check the box to indicate your agreement.");
    whichform.agree.select();
    return false;
  }
 
  if (deliveryType=="collect")
    return true;  
  
      if (whichform.address.value == "")
 {
    alert ("Please enter your delivery address");
    whichform.address.select();
    return false;
  }

      if (whichform.suburb.value == "")
 {
    alert ("Please enter your suburb");
    whichform.suburb.select();
    return false;
  }    
    
      if (whichform.city.value == "")
 {
    alert ("Please enter your city");
    whichform.city.select();
    return false;
  }
  
      if (whichform.postCode.value == "")
 {
    alert ("Please enter your postal code");
    whichform.postCode.select();
    return false;
  }  
  if (deliveryType == "courier" && 
		(whichform.address.value.toLowerCase().search("box") != -1 ||
		whichform.address.value.toLowerCase().search("posbus") != -1 ||
		whichform.address.value.toLowerCase().search("p.o") != -1 ||
		whichform.address.value.toLowerCase().search("po ") != -1 ||
		whichform.address.value.toLowerCase().search("private") != -1 ||
		whichform.address.value.toLowerCase().search("privaat") != -1 ||
		whichform.address.value.toLowerCase().search("bag") != -1 ||
		whichform.address.value.toLowerCase().search("sak") != -1 ))
  {
	if (!confirm("It looks like you have entered a P.O. Box or private bag as a delivery address.  Please note that courier deliveries can only be made to physical addresses where someone will be present to sign for the delivery. If you are certain that you have entered a valid delivery address, click 'OK' to continue. Otherwise click 'Cancel' to go back and change your delivery address. FlyPhoto will not be held responsible for any extra delivery charges incurred for incorrectly specifed addresses."))
	{
		whichform.address.focus();
		return false;	
	}
  }
  return true;
}

function validate4(whichform)
{
  if (whichform.name.value == "")
 {
    alert ("Please enter your name");
    whichform.name.select();
    return false;
  } 
  
  checkEmail = whichform.email.value
  if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
  {
    alert("You have entered an invalid email address. Please try again.");
    whichform.email.select();
    return false;
  }
  
  if (whichform.contactno.value == "")
 {
    alert ("Please enter your contact number");
    whichform.contactno.select();
    return false;
  }
  
    if (whichform.message.value == "")
 {
    alert ("No message has been entered.");
    whichform.message.select();
    return false;
  }
  
 
  return true;
}

function nothing()
{
}

function areyousure(question,newLocation)
{
  var whereTo = confirm(question);
  if (whereTo)
  {
    window.location=newLocation;
  }

}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

