
//document.write("<script src='alertdialog/js/jquery.js' type='text/javascript'></script>");
//document.write("<script src='alertdialog/js/jquery.ui.draggable.js' type='text/javascript'></script>");    
//document.write("<script src='alertdialog/js/jquery.alerts.js' type='text/javascript'></script>");
//document.write("<link href='alertdialog/css/jquery.alerts.css' rel='stylesheet' type='text/css' media='screen' />");

/********************************************************* GLOBAL VARIABLES AND INIT **************************************/
var success = "";
var strQueryString="";
var hasQueryString = document.URL.indexOf('?'); 
if (hasQueryString != -1) 
{ 
	strQueryString = document.URL.substring(hasQueryString+1, document.URL.length);
}
var variables = strQueryString.split("/*/");
if (variables[0]!=null)
{	
	var successvar = variables[0].split("=");
	var success = successvar[1];
	//window.alert(successvar[1]);
}

/********************************************************* FUNCTIONS ******************************************************/

/*function showHideDiv() {
	var x = document.getElementById('signup_div')
	x.style.display = 'none';
}
*/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function validZip(zip)
{
	zip=zip.toUpperCase();
	
	if (zip.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) 
	{
		return true;
	}
	
	return false;
} 

function validEmail(email) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) 
   {
      return false;
   }
   else
   {
      return true;
   }
}

// JavaScript Document
function validate()
{
	var noErrors = true;
	var errorString = "";
	//var errorString = "<p align='left'>";
	
	var first = document.forms["myForm"].elements["first"].value;
	var last = document.forms["myForm"].elements["last"].value;
	var city = document.forms["myForm"].elements["city"].value;
	var province = document.forms["myForm"].elements["province"].value;
	var postalcode = document.forms["myForm"].elements["postalcode"].value;
	var emailadd = document.forms["myForm"].elements["emailadd"].value;
	
	
	if (first.length==0 || first==null)
	{
		noErrors = false;
		errorString += "First name is required\n";	

	}	
	if (last.length==0 || last==null)
	{
		noErrors = false;
		errorString += "Last name is required\n";	
	}
	if (city.length==0 || city==null)
	{
		noErrors = false;
		errorString += "City is required\n";	
	}
	if (province=='')
	{
		noErrors = false;
		errorString += "Province is not selected\n";	
	}
	
	if (!(validZip(postalcode)))
	{
		noErrors = false;
		errorString += "Postal code is invalid, example format: A1A1A1\n";	
	}
	
	if (!(validEmail(emailadd)))
	{
		noErrors = false;
		errorString += "Email is invalid, example format: a@a.com\n";	
	}
	
	if(! (document.forms["myForm"].elements["news"].checked && document.forms["myForm"].elements["terms"].checked)){
		noErrors = false;
		errorString += "Oh no! We can't send you our news if you don't check both little boxes.\n";
	}

	//errorString += "</p>";
	// print all errors found
	if (noErrors==false)
	{
		//jAlert('error', errorString, 'Error');
		window.alert(errorString);
	}
	
	var property = document.forms["myForm"].elements["rURL"];
	property.value = window.location.pathname;
	
	return noErrors;
}


document.write("<div id='dealsBox'>"); 
document.write("<img src='img/callHdlFindaDeal.jpg'/>"); 
document.write("<div class='innerPadding'>"); 
document.write("<a href='https://quikorder.pizzahut.com/pizzahutcanada2/deals.php'><img src='img/btnGo.gif' alt='Find a Deal' /></a>"); 
document.write("</div>"); 
document.write("<img src='img/callHdlGetMore.jpg' />"); 
document.write("<div class='innerPadding' style='padding-top:0px'>"); 
//document.write("<form action='newsletter.php' method='post' name='myForm' id='myForm' target='_new' onsubmit='return validate()';> "); 
document.write("<form action='newsletter.php' method='post' name='myForm' id='myForm' onsubmit='return validate()';> "); 
if (success==1)
{
	document.write("<br /><br /><br /><br /><br /><br />");
	document.write("<center><font size='3'><b>Thank You for joining the Pizza Hut Newsletter!</b></font></center>")
	document.write("<br /><br/><center><img src='img/ph_logo.gif'></center><br /><br />");
	document.write("<center><font size='3'><b>Stay Tuned for Great Offers!</b></font></center>");
	document.write("<br /><br /><br /><br /><br /><br />");
    document.write("</div>");    
	document.write("<img src='img/callBoxBottom.gif'/>"); 
    document.write("</div>");    
	//jAlert('success', 'Thank-you for signing up!', 'Success');	
}
else
{
	/*document.write("* Required fields</b><br/><br/>"); */

document.write("<input type='hidden' id='rURL' name='rURL'>");
document.write("<input type='hidden' id='userlang' name='userlang' value='english'>");
document.write("<input type='hidden' name=�residence' id='residence' value=''>");
document.write("<input type='hidden' name=�address' id='address' value=''>");
//document.write("<p>Sign up to receive your Pizza Hut newsletter.</p>");
document.write("<div id='signup_div'>");
document.write("<br>First Name*<br /> <input name='first' id='first' type='text' maxlength='50' style='font-size:10px; font-family:Arial; width:150px; ' /><br/>"); 
document.write("Last Name*<br /> <input name='last' id='last' type='text' maxlength='50' style='font-size:10px; font-family:Arial; width:150px; ' /><br/>");
document.write("Email Address*<br /> <input name='emailadd' id='emailadd' type='text' maxlength='50' style='font-size:10px; font-family:Arial; width:150px; '/><br/>"); 
document.write("City* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;   &nbsp; &nbsp;Province*<br /> <input name='city' id='city' type='text' maxlength='50' style='font-size:10px; font-family:Arial; width:100px; '/>"); 
document.write("&nbsp; &nbsp; <select name='province' id='province' style='font-size:10px; font-family:Arial; width:40px;'><option value='' selected> </option><option value='ab'>AB</option><option value='bc'>BC</option><option value='mb'>MB</option><option value='nb'>NB</option><option value='nl'>NL</option><option value='ns'>NS</option><option value='nt'>NT</option><option value='nu'>NU</option><option value='on'>ON</option><option value='pe'>PE</option><option value='qc'>QC</option><option value='sk'>SK</option><option value='yt'>YT</option></select><br/>"); 
document.write("Postal Code*<br /> <input name='postalcode' id='postalcode' type='text' maxlength='6' style='font-size:10px; font-family:Arial; width:150px; '/><br/>"); 
document.write("Date of Birth<br/><select name='month' id='month' style='width:80px; font-size:10px; font-family:Arial;'><option value=''  selected>month</option><option value='1'>January</option><option value='2'>February</option><option value='3'>March</option><option value='4'>April</option><option value='5'>May</option><option value='6'>June</option><option value='7'>July</option><option value='8'>August</option><option value='9'>September</option><option value='10'>October</option><option value='11'>November</option><option value='12'>December</option></select>&nbsp;<select name='day' id='day' style='width:43px; font-size:10px; font-family:Arial;'><option value='' selected>day</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option><option value='23'>23</option><option value='24'>24</option><option value='25'>25</option><option value='26'>26</option><option value='27'>27</option><option value='28'>28</option><option value='29'>29</option><option value='30'>30</option><option value='31'>31</option></select>&nbsp;<input type='text' name='year' id='year' maxlength='4' value='year' style='width:30px; font-size:10px; font-family:Arial;'/><br/>"); 
document.write("Phone Number<br/> <input name='phone' id='phone' type='text' maxlength='50' style='font-size:10px; font-family:Arial; width:150px; '/><br/>"); 
document.write("<div style='line-height:10px; margin-top:10px;'><input type='checkbox' name='news' id='news' checked='checked' />Yes, I would like to receive occasional promotional news and information from Pizza Hut and its partners</div>");
document.write("<div style='line-height:10px; margin:10px 0 10px 0;'><input type='checkbox' name='terms' id='terms' checked='checked' />Yes, I have read and agree to the terms of use for the site</div>");
document.write("<p align='center'><input type='submit' value='Submit' name='submit'></p>"); 
document.write("</form>");
document.write("</div>");
document.write("</div>");
document.write("<img src='img/callBoxBottom.gif'/>"); 
document.write("</div>");    
}