var objVisibleLayer;
function isInteger(s){
 var i;
 for (i = 0; i < s.length; i++){
  // Check that current character is number.
  var c = s.charAt(i);
  if (((c < "0") || (c > "9"))) return false;
 }
 // All characters are numbers.
 return true;
}
function showLayer(layerID){
	if( objVisibleLayer ){
		if( objVisibleLayer.id == layerID ) return 0;
	}

	objVisibleLayer = document.getElementById(layerID);

	if( objVisibleLayer )
		objVisibleLayer.style.display = '';

}

function hideLayer(){

	if( objVisibleLayer ){
		objVisibleLayer.style.display = 'none';
		objVisibleLayer = null;
	}

}

function swapSideImage(imgName, imgPath){
	var imgRef = document.getElementById(imgName);

	if( imgRef ){

		imgRef.src = imgPath;

	}

}

function OpenInPopup(url)
{
	ShowPopUpWindow("prpopup",basehref + url,870,650,"yes","yes","yes");
}

function openCertDetails() {

	var referer = "";
	var siteSealImage;

	if (self.sampleReferer)
		referer = self.sampleReferer;
	else
		referer = window.location;
/*
	if (document.images) {
		siteSealImage = document.images["thawteSiteSeal"]
		siteSealImage.src="https://www.thawte.com/cgi/server/seal_generator.exe?referer=" + referer
	}
*/
	certDetailsUrlWithReferer = "https://www.thawte.com/cgi/server/certdetails.exe?referer=" + referer;
	thewindow = window.open(certDetailsUrlWithReferer,
		"newWindow", config="height=500,width=516,toolbar=no,menubar=no," +
		"scrollbars=yes,resizable=no,location=no,directories=no,status=yes");

}

function isEmail(email) {
	var invalidCharString = " ,<>!\"?%^&*()+=*/\\\';:#~[]{}";
	var i = 0;
	
	for (i = 0; i < invalidCharString.length; i++) {
		if (-1 < email.indexOf(invalidCharString.charAt(i))) {
			return false;
		}
	}
	
	var firstAt = email.indexOf('@');
	var lastAt = email.lastIndexOf('@');
	var lastDot = email.lastIndexOf('.');
	if (!((0 < firstAt) && (1 < lastDot) && (firstAt == lastAt) && ((firstAt + 1) < lastDot) && (lastDot < (email.length - 2)))) 
	{
		return false;
	}
	else {
		return true;
	}
}

function isInteger(s){
	if (s.length == 0) {
		return false;
	}
	var i;
	for (i = 0; i < s.length; i++){
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function getRadioButtonValue(radioButtonArray) {
	var value = '';
	
	if (!radioButtonArray.length) {
		// Only one radio button, so form.radiobuttonname returns a radiobutton element, not an array
		if (radioButtonArray.checked) {
			value = radioButtonArray.value;
		}
	}
	else {
		for (var i=0; i<radioButtonArray.length; i++) {
			if (radioButtonArray[i].checked) {
				value = radioButtonArray[i].value;
				break;
			}
		}
	}
	
	return value;
}

function checkCountryRules(roiID)
{
	if(document.getElementById('CountryID').options[document.getElementById('CountryID').selectedIndex].value == roiID)
	{
		document.getElementById('Postcode').value = '000';
		document.getElementById('PostCodeRow').style.visibility = 'hidden';
		document.getElementById('PostCodeRow').style.display = 'none';
	}
	else
	{
		document.getElementById('PostCodeRow').style.visibility = 'visible';
		document.getElementById('PostCodeRow').style.display = '';
	}
}

function NoneLink() {
	return;
}


function loadImg(path,id){
	var strImgName = 'swatchImg_'+ id

	document.getElementById(strImgName).src = path;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function RequestQuote(rdoEnquiryType){

	var t=0, l = 0, winstring = "";


	if(infowindow){
		if(!infowindow.closed) infowindow.close()
	}
	l = ((screen.width / 2) - (595 / 2))
	t = ((screen.height / 2) - (535 / 2))
	winstring = "width=592,height=535,left=" + l + ",top=" + t +  ",status=yes,resizable=no,scrollbars=yes";

	infowindow = window.open(basehref + 'QuoteRequest.cfm?EnquiryType=' + rdoEnquiryType, 'PersonalisedQuote', winstring);

	return;
}


/* Video Report Dialog */
var dialogOptions = { width: 650, height: 500 }
var ajax = null;

function Ajax()
{
	this.toString = function() {return "Ajax";}
	this.makeRequest = function(_method, _url, _callbackMethod)
	{
		this.request = (window.XMLHttpRequest)? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
		this.request.onreadystatechange = _callbackMethod;
		this.request.open(_method, _url, true);
		this.request.send(_url);
		this.request.contenttype = "text/html"
		this.request.charset = "ISO-8859-1"

	}
	this.checkReadyState = function(_id, waitContent, showMessage, suppressWaitContent)
	{
		return this.request.status;
	}
}

function loadVideo_Complete(data)
{
	if( ajax.request.readyState == 4 && ajax.request.status == 200 )
	{
		var waitMessage = document.getElementById('VideoReportLoading');
		var videoReport = document.getElementById('VideoReport');
		
		waitMessage.style.display = 'none';
		videoReport.style.display = 'block';
		
		videoReport.innerHTML = ajax.request.responseText;
	}
}

function VideoReport(videoId)
{
	ShowVideoReport(videoId);
}

function ShowVideoReport(videoId)
{
	var dlg = document.getElementById('VideoReportDialog');
	var dialogShield = document.getElementById('dialogShield');
	var closeButton = document.getElementById('CloseButton');
	
	var btns = document.getElementById('VideoDialogButtons');
	var title = document.getElementById('VideoDialogTitle');
	
	var videoReport = document.getElementById('VideoReport');
	var waitMessage = document.getElementById('VideoReportLoading');
	
	dlg.style.display = 'block';
	waitMessage.style.display = 'block';
	videoReport.style.display = 'block';

	closeButton.onclick = function(){
		dialogShield.style.display = 'none';
		dlg.style.display = 'none';
		
		return false;
	}
	
	dlg.style.width = dialogOptions.width;
	dlg.style.height = dialogOptions.height;
	
	dlg.style.top = ((getPageHeight() / 2) - (dialogOptions.height / 2)) + getScrollTop();
	dlg.style.left = (getPageWidth() / 2) - (dialogOptions.width / 2);
	
	var videoHeight = dialogOptions.height - (btns.offsetHeight + title.offsetHeight);
	
	videoReport.style.height = videoHeight;
	videoReport.style.minHeight = videoHeight;
	
	dialogShield.style.display = 'block';
	dialogShield.style.height = getDocHeight();
	dialogShield.style.width = getDocWidth();
	
	btns.style.width = dialogOptions.width;
	
	var url = 'ShowVideoReport.cfm?id=' + videoId;
	
	ajax = new Ajax();
	ajax.makeRequest('get', url, loadVideo_Complete);
}

function getScrollTop()
{
	var ScrollTop = document.body.scrollTop;
	 
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	
	return ScrollTop;
}

function getScrollLeft()
{
	var scrollLeft = document.body.scrollLeft;
	 
	if (scrollLeft == 0)
	{
		if (window.pageXOffset)
			scrollLeft = window.pageXOffset;
		else
			scrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
	}
	
	return scrollLeft;
}


function getDocHeight(){ 
	if( document.height != undefined ) // good browsers
	{	
		return document.height;
	}
	else{
		var scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
		var offsetHeight = Math.max(document.documentElement.offsetHeight, document.body.offsetHeight);

		return scrollHeight < offsetHeight ? offsetHeight :  scrollHeight;
	}
}

function getDocWidth(){ 

	if (document.width != undefined) // good browsers
	{
		return document.width;
	}
	else{
		var scrollWidth = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
		var offsetWidth = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth);

		return scrollWidth < offsetWidth ? offsetWidth : scrollWidth;
	}
}

function getPageWidth()
{
	if( document.all ){ 
		var clientWidth = document.documentElement.clientWidth;
		
		if( clientWidth <= 0 ) clientWidth = document.body.clientWidth;
	
		return clientWidth; 
	} 
	else { 
		return window.innerWidth; 
	}
}

function getPageHeight()
{
	if( document.all ){ 
		var clientHeight = document.documentElement.clientHeight;
		
		if( clientHeight <= 0 ) clientHeight = document.body.clientHeight;
		
		return clientHeight; 
	} 
	else { 
		return window.innerHeight; 
	} 
}

window.onresize = function()
{
	var dialogShield = document.getElementById('dialogShield');
	
	if( dialogShield )
	{
		dialogShield.style.height = getDocHeight();
		dialogShield.style.width = getDocWidth();
	}
}

window.onscroll = function()
{
	// // Note: This code renders the Video correctly in the repositioned dialog for IE and Safari but it doesn't work in Firefox.....
	// var dlg = document.getElementById('VideoReportDialog');

	// if( dlg != null && dlg.style.display != 'none' )
	// {
		// dlg.style.top = ((getPageHeight() / 2) - (dialogOptions.height / 2)) + getScrollTop();
		// dlg.style.left = (getPageWidth() / 2) - (dialogOptions.width / 2) + getScrollLeft();
	// }
	
}
// End of Video Report Dialog
