// JScript File

function resizeAdjust(){

	 var viewportwidth;
	 var viewportheight;

	function setSize(viewportWidth){
		if(viewportWidth <= 910){
		
			if(document.getElementsByTagName('body')[0].id == 'body'){
				document.getElementsByTagName('body')[0].id = 'body-thin';
			}
			
		} else {
		
			if(document.getElementsByTagName('body')[0].id == 'body-thin'){
				document.getElementsByTagName('body')[0].id = 'body';
			}
			
		}
	}
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth;
		  viewportheight = window.innerHeight;
		  setSize(viewportwidth);
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth;
		   viewportheight = document.documentElement.clientHeight;
		   setSize(viewportwidth);
	 }
	 
	 // older versions of IE	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight;
		   setSize(viewportwidth);
	 }	
}

function colorReplaceOn(id){
	document.getElementById(id).style.backgroundColor = "#DE6E00";
}

function colorReplaceOff(id){
	document.getElementById(id).style.backgroundColor = "#1D4388";
}

function addressLookupHide(){
	if(document.getElementById('backPost').value != 'true'){
		document.getElementById('address-container').className = "hidden";
	}
}

function bookmark(){
	// Firefox
	if(window.sidebar){
		window.sidebar.addPanel(document.title, document.location.href, "Gullivers Sports Travel");
	}
	
	// Opera
	else if(window.opera && window.print){ 
		var elem = document.createElement('a');
		elem.setAttribute('href',document.location.href);
		elem.setAttribute('title',document.title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	
	// IE
	else if(document.all){
		window.external.AddFavorite(document.location.href, document.title);
	}
}

function addressLookup(){
	if(document.getElementById('address-container').className == 'hidden'){
		document.getElementById('address-container').className = "show";
	}
	else{
		document.getElementById('address-container').className = "hidden";
	}
}

function URLRedirect(){
    var countryName = document.getElementById('productid').value.toLowerCase();
    countryName = countryName.replace(' - ','-');
    countryName = countryName.replace(', ','-');
    countryName = countryName.replace(' & ','-');
    countryName = countryName.replace(' ','-');
    countryName = countryName.replace(' ','-');
    countryName = countryName.replace(' ','-');
    window.location = "http://www.gulliverstravel.co.uk/countries/" + countryName;
    return false;
}

function populateURL(){
	if(document.friendForm){
		document.getElementById('currentURL').value = encodeURI(location.href);
	}
}

function formSubmit(){
	document.friendForm.submit();
}

function nameAdd(){
	var sendersName = document.getElementById('senderName').value;
	var receiversName = document.getElementById('receiverName').value;
	var messageString = "Dear " + receiversName + "," + "\r\r" + "I found the following page on the Gullivers Sports Travel website and thought you might like to take a look." + "\r\r" + document.getElementById('pagelink').value + "\r\r" + "Regards," + "\r\r" + sendersName;
	
	document.getElementById('messageContent').value = messageString;
}

function addtoWishList(productid, returnURL)
{

if (returnURL == null){
    var sreturnURL = new String(window.location);
    //returnURL = returnURL.replace(/^(http¦ftp¦news)s?:\/+/i, '');
    var iSlashIndex = sreturnURL.indexOf("//");
    if (iSlashIndex != -1){
		sreturnURL = sreturnURL.substring(iSlashIndex +2);
    }
    
    returnURL = sreturnURL;
}

window.open( "http://www.gulliverstravel.co.uk/add-to-favourites.aspx?productid=" + productid + "&ururl=" + escape(returnURL), "addtofavourites", "status = 1, height = 150, width = 300, resizable = 0" )

}

function safeParentWindowLocation(url, qsToEncode, closeSelf)
{
	self.opener.location = url + encodeURIComponent(qsToEncode);

if (closeSelf == 'true')
{
self.close();
}
}

function enewsletterValidation(){
	var errorMsg = '';	
	if(document.getElementById('Title').value == ''){
		errorMsg = errorMsg + 'Please enter your title' + '\n';
	}
	if(document.getElementById('FirstName').value == ''){
		errorMsg = errorMsg + 'Please enter your first name' + '\n';
	}
	if(document.getElementById('LastName').value == ''){
		errorMsg = errorMsg + 'Please enter your last name' + '\n';
	}
	if(document.getElementById('Address').value == ''){
		errorMsg = errorMsg + 'Please enter your email address' + '\n';
	}
	if(document.getElementById('CompanyName').value == ''){
		errorMsg = errorMsg + 'Please enter your favorite sport' + '\n';
	}
	if(errorMsg == ''){return true}
	else{
		alert(errorMsg);
		return false
	}
}