var removeSignUp = "";

function CheckEmail(checkStr)
{
// test if valid email address, must have @ and .
var checkEmail	= "@.";
var EmailValid	= false;
var EmailAt	= false;
var EmailPeriod	= false;
var EmailSpace	= false;
var error		= "";

if (checkStr.indexOf(" ") > -1)
{
EmailSpace	= true;
}

for (i	= 0;i < checkStr.length;i++)
{
ch	= checkStr.charAt(i);

for (j	= 0;j < checkEmail.length;j++)
{

if (ch == checkEmail.charAt(j) && ch == "@")
EmailAt	= true;

if (ch == checkEmail.charAt(j) && ch == ".")
EmailPeriod	= true;

if (EmailAt && EmailPeriod)
break;

if (j == checkEmail.length)
break;
}

// if both the @ and . were in the string
if ((EmailAt) && (EmailPeriod) && (!EmailSpace))
{
EmailValid	= true
break;
error	= "";
}

}

if (!EmailValid)
{
error	= "";

if ((!EmailAt) && (!EmailPeriod))
{
error	+= " - Email must contain an \"@\" and a \".\"\n";
}

if (!EmailAt)
{
error += " - Email must contain an \"@\"\n";	
}

if (!EmailPeriod)
{
error += " - Email must contain an \".\"\n";	
}

if (EmailSpace)
{
error += " - Email must not contain a space\n";	
}

else
{
error	= " - Email is invalid\n";	
}

}

return error;
}

function SetCheckedByValue(theSelect, avalue)
{

if (theSelect)
{

if (avalue != 0)
{
theSelect.checked = true;
}

}

}

function SetSelectByValue( theSelect, avalue )
{

if (theSelect)
{

for ( var i=0,n=theSelect.options.length; i<n; i++ )
{
if ( theSelect.options[i].value == avalue )
{
 return( theSelect.selectedIndex = i );
}
}
return(-1);

}

}

function TrimString(str)
{
str 		= this != window? this : str;
str			= str.replace(/^\s+/g, "").replace(/\s+$/g, "");
str			= str.replace(/0/g, "");

return str;
}

function IsEmpty(TmpString)
{

if (!TmpString)
{
return true;	
}

TmpString	= TrimString(TmpString);

if (TmpString.length <= 0)
{
return true;
}

return false;
}

function ShowError(Errors)
{
Errors	= Errors.toLowerCase();
alert("The following error(s) occurred:\n" + Errors.substring(Errors,Errors.length-1) + "\n\nSorry can not Process the form");
return false;
}

function CheckCheckOut()
{

var alertsay	= "";

if (IsEmpty(document.getElementById("CheckOut").BillToFirstName.value))
{
alertsay		+= "- Please enter the billing first Name\n";
}

if (IsEmpty(document.getElementById("CheckOut").BillToLastName.value))
{
alertsay		+= "- Please enter the billing last Name\n";
}

if (IsEmpty(document.getElementById("CheckOut").ConsumerEmail.value))
{
alertsay 		+= "- Please enter your Email\n";
}

else
{
alertsay 		+= CheckEmail(document.getElementById("CheckOut").ConsumerEmail.value);
}

if (IsEmpty(document.getElementById("CheckOut").BillToAddress1.value))
{
alertsay		+= "- Please enter the first line of the Billing Address\n";
}

if (IsEmpty(document.getElementById("CheckOut").BillToCounty.value))
{
alertsay		+= "- Please enter the Billing County\n";
}

if (IsEmpty(document.getElementById("CheckOut").BillToPostCode.value))
{
alertsay		+= "- Please enter the Billing Post Code\n";
}

if (IsEmpty(document.getElementById("CheckOut").BillToCountry.value))
{
alertsay		+= "- Please select the Billing Country\n";
}

if (document.getElementById("CheckOut").SameAsBillTo.checked == false)
{

if (IsEmpty(document.getElementById("CheckOut").ShipToFirstName.value))
{
alertsay		+= "- Please enter the shipping first Name\n";
}

if (IsEmpty(document.getElementById("CheckOut").ShipToLastName.value))
{
alertsay		+= "- Please enter the shipping last Name\n";
}

if (IsEmpty(document.getElementById("CheckOut").ShipToAddress1.value))
{
alertsay		+= "- Please enter the first line of the Shiping Address\n";
}

if (IsEmpty(document.getElementById("CheckOut").ShipToCounty.value))
{
alertsay		+= "- Please enter the Shiping County\n";
}

if (IsEmpty(document.getElementById("CheckOut").ShipToPostCode.value))
{
alertsay		+= "- Please enter the Shiping Post Code\n";
}

if (IsEmpty(document.getElementById("CheckOut").ShipToCountry.value))
{
alertsay		+= "- Please select the Shiping Country\n";
}

}
/*
var letter		= /^[a-zA-Z\s]+$/;
var today		= new Date();
var CCStart		= new Date(document.getElementById("CheckOut").CCStartYear.value,document.getElementById("CheckOut").CCStartMonth.value);
var CCExpiry	= new Date(document.getElementById("CheckOut").CCExpiryYear.value,document.getElementById("CheckOut").CCExpiryMonth.value);

// Card Details
var CCType		= document.getElementById("CheckOut").CCType.value;
var CCNum		= document.getElementById("CheckOut").CCNumber.value;
var CCNum		= CCNum.replace(/ /g, "");

if (IsEmpty(CCType))
{
alertsay		+= "- You have not selected your card type\n";
}

else if (IsEmpty(CCNum))
{
alertsay		+= "- You have not entered the card number.\n";
}

else if (CCNum.length <= 10)
{
alertsay		+= "- You have not entered a full card number.\n";
}

else
{

// Visa Card
if ((CCType == 1) || (CCType == 11))
{

if ((CCNum.length != 13 || CCNum.length != 16) && (CCNum.substring(0,1) != 4))
{
alertsay		+= "- The card number you entered could not be validated.\n";
}

}

// Switch solo
if (CCType == 9)
{

if ((CCNum.length == 16 || CCNum.length == 18 || CCNum.length == 19) && (CCNum.match(/63345|63346|63347|63348|63349|6767/)))
{
}

else
{
alertsay		+= "- The card number is not a valid Solo Card Number.\n";
}

}

// MasterCard
if (CCType == 2)
{
var firstdig	= CCNum.substring(0,1);
var seconddig	= CCNum.substring(1,2);
if ((CCNum.length == 16 || CCNum.length == 19) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
{
}

else
{
alertsay		+= "- The card number is not a valid Mastercard Number.\n";
}

}

// Amercican Express
if (CCType == 8)
{
firstdig	= CCNum.substring(0,1);
seconddig	= CCNum.substring(1,2);
if (((CCNum.length != 15) || (CCNum.length != 18)) && (firstdig != 3) && ((seconddig != 4) || (seconddig != 7)))
{
alertsay		+= "- The card number is not a valid American Express Card Number.\n";
}

}

// Switch Cards
if (CCType == 10)
{

if ((CCNum.length ==16) && (CCNum.match(/^(491101|491102|564182|633300|633302|633303|633304|633305|633306|633307|633308|633309|633310|633311|633312|633313|633314|633315|633316|633317|633318|633319|633320|633321|633322|633323|633324|633325|633326|633327|633328|633329|633330|633331|633332|633333|633334|633335|633336|633337|633338|633339|633340|633341|633342|633343|633344|633345|633346|633347|633348|633349|675900|675902|675903|675904|675906|675907|675908|675909|675910|675911|675912|675913|675914|675915|675916|675917|675919|675920|675921|675922|675923|675924|675925|675926|675927|675928|675929|675930|675931|675932|675933|675934|675935|675936|675937|675941|675942|675943|675944|675945|675946|675947|675948|675949|675963|675964|675965|675966|675967|675968|675969|675970|675971|675972|675973|675974|675975|675976|675977|675978|675979|675980|675981|675982|675983|675984|675985|675986|675987|675988|675989|675990|675991|675992|675993|675994|675995|675996|675997|675999)/)) || (CCNum.length==18) && (CCNum.match(/^(675938|675939|675940|490302|490303|490304|490305|490306|490307|490308|490309|490335|490336|490337|490338|490339|491174|491175|491176|491177|491178|491179|491180|491181|491182)/)) || (CCNum.length==19) && (CCNum.match(/^(4936|633301|675901|675905|675918|675950|675951|675952|675953|675954|675955|675956|675957|675958|675959|675960|675961|675962|675998)/)))
{
}

else
{
alertsay		+= "- The card number is not a valid Switch Card Number.\n";
}

}

if (CCType == 9)
{

if ((IsEmpty(document.getElementById("CheckOut").CCStartMonth.value)) && (IsEmpty(document.getElementById("CheckOut").CCStartYear.value)))
{
alertsay		+= "- Please select the card start date\n";
}

}

if ((IsEmpty(document.getElementById("CheckOut").CCExpiryMonth.value)) && (IsEmpty(document.getElementById("CheckOut").CCExpiryYear.value)))
{
alertsay		+= "- Please select the card expiry date\n";
}

else if (CCExpiry < today)
{
alertsay		+= "- Your credit card has expired\n";
}

if (IsEmpty(document.getElementById("CheckOut").CVV2.value))
{
alertsay		+= "- Please enter the card security number (last 3 digits on back of card)\n";
}

}
*/
if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}

function ShareThisPicture()
{

var alertsay	= "";

if (IsEmpty(document.getElementById("ShareForm").FriendsName.value))
{
alertsay		+= "- Please enter your friends Name\n";
}

if (IsEmpty(document.getElementById("ShareForm").FriendsEmail.value))
{
alertsay 		+= "- Please enter your friends Email\n";
}

else
{
alertsay 		+= CheckEmail(document.getElementById("ShareForm").FriendsEmail.value);
}

if (IsEmpty(document.getElementById("ShareForm").YourName.value))
{
alertsay		+= "- Please enter your Name\n";
}

if (IsEmpty(document.getElementById("ShareForm").YourEmail.value))
{
alertsay 		+= "- Please enter your Email\n";
}

else
{
alertsay 		+= CheckEmail(document.getElementById("ShareForm").YourEmail.value);
}

if (alertsay)
{
ShowError(alertsay);
}

else
{
URL			= "/ajaxpopups/SharePicture.php?Send=true";
URL			+= "&PictureID=" + document.getElementById("ShareForm").PictureID.value;
URL			+= "&FriendsName=" + document.getElementById("ShareForm").FriendsName.value;
URL			+= "&FriendsEmail=" + document.getElementById("ShareForm").FriendsEmail.value;
URL			+= "&YourName=" + document.getElementById("ShareForm").YourName.value;
URL			+= "&YourEmail=" + document.getElementById("ShareForm").YourEmail.value;
URL			+= "&Message=" + document.getElementById("ShareForm").Message.value;
load(URL, "ShowPicture", "");
setTimeout("ShowMediumImage(" + document.getElementById("ShareForm").PictureID.value + ")", 3000);
}

}

function RemoveThisPicture()
{

var alertsay	= "";

if (IsEmpty(document.getElementById("ShareForm").Reason.value))
{
alertsay		+= "- Please enter the reason why you wish to remove this image\n";
}

if (alertsay)
{
ShowError(alertsay);
}

else
{
URL			= "/ajaxpopups/RequestRemoval.php?Send=true";
URL			+= "&PictureID=" + document.getElementById("ShareForm").PictureID.value;
URL			+= "&Reason=" + document.getElementById("ShareForm").Reason.value;
load(URL, "ShowPicture", "");
setTimeout("ShowMediumImage(" + document.getElementById("ShareForm").PictureID.value + ")", 3000);
}

}

function CheckRegisterUser()
{

var alertsay	= "";

if (IsEmpty(document.getElementById("RegisterForm").FirstName.value))
{
alertsay		+= "- Please enter your First Name\n";
}

if (IsEmpty(document.getElementById("RegisterForm").LastName.value))
{
alertsay		+= "- Please enter Last Name\n";
}

if (IsEmpty(document.getElementById("RegisterForm").EmailAddress.value))
{
alertsay 		+= "- Please enter your Email Address\n";
}

else
{
alertsay 		+= CheckEmail(document.getElementById("RegisterForm").EmailAddress.value);
}

if (IsEmpty(document.getElementById("RegisterForm").Password.value))
{
alertsay 		+= "- Please enter a Password\n";
}

else if ((document.getElementById("RegisterForm").Password.value != "") && (IsEmpty(document.getElementById("RegisterForm").ConfirmPassword.value)))
{
alertsay 		+= "- Please Confirm your Password\n";
}

else if (document.getElementById("RegisterForm").Password.value != document.getElementById("RegisterForm").ConfirmPassword.value)
{
alertsay 		+= "- Your Passwords do not match\n";
}

if (document.getElementById("RegisterForm").Terms.checked == false)
{
alertsay 		+= "- Please agree to terms of use\n";
}

if (alertsay)
{
ShowError(alertsay);
}

else
{

Newsletter	= 0;

if (document.getElementById("RegisterForm").Newsletter[0].checked == true)
{
Newsletter	= 1;	
}
	
URL			= "/ajaxpopups/RegisterUser.php?Register=true";
URL			+= "&FirstName=" + document.getElementById("RegisterForm").FirstName.value;
URL			+= "&LastName=" + document.getElementById("RegisterForm").LastName.value;
URL			+= "&EmailAddress=" + document.getElementById("RegisterForm").EmailAddress.value;
URL			+= "&Password=" + document.getElementById("RegisterForm").Password.value;
URL			+= "&DogName=" + document.getElementById("RegisterForm").DogName.value;
URL			+= "&DogDOB=" + document.getElementById("RegisterForm").DogDOB.value;
URL			+= "&Newsletter=" + Newsletter;
load(URL, "ShowRegister", "");
removeSignUp = setTimeout("removeElement()", 3000);
}

}

function CheckLogin()
{

var alertsay	= "";

if (IsEmpty(document.getElementById("LoginForm").UserName.value))
{
alertsay		+= "- Please enter your E-Mail\n";
}

if (IsEmpty(document.getElementById("LoginForm").Password.value))
{
alertsay 		+= "- Please enter your Password\n";
}

if (alertsay)
{
ShowError(alertsay);
}

else
{
URL					= "/ajax/DoLogin.php?Login=true";
URL					+= "&UserName=" + document.getElementById("LoginForm").UserName.value;
URL					+= "&Password=" + document.getElementById("LoginForm").Password.value;
ajax.requestFile	= URL;
ajax.onCompletion	= RunAJAX;
ajax.runAJAX();	
}

}

function SameAsBilling()
{
Disabled	= (document.getElementById("CheckOut").SameAsBillTo.checked) ? false : true;
document.getElementById("CheckOut").ShipToFirstName.disabled 	= Disabled;
document.getElementById("CheckOut").ShipToLastName.disabled 	= Disabled;
document.getElementById("CheckOut").ShipToAddress1.disabled 	= Disabled;
document.getElementById("CheckOut").ShipToAddress2.disabled 	= Disabled;
document.getElementById("CheckOut").ShipToAddress3.disabled 	= Disabled;
document.getElementById("CheckOut").ShipToCity.disabled 		= Disabled;
document.getElementById("CheckOut").ShipToCounty.disabled 		= Disabled;
document.getElementById("CheckOut").ShipToPostCode.disabled 	= Disabled;
document.getElementById("CheckOut").ShipToCountry.disabled 		= Disabled
}