// JavaScript Document
var windowWidth = 0, windowHeight = 0;
var strSiteLink = "http://server03/HomeDecor";

function relocateTo(pageLocation)
{
	if(pageLocation != "")
	{
		document.location.href=pageLocation;
	}
}

function FullScreen(lang){
	//this.moveTo(0,0);
	//resizeTo(screen.availWidth,screen.availHeight);
	//top.location.href = "default.php";
	var url = "default.asp"
	if(lang != ""){url += "?lang="+lang;}
	//newwindow=window.open(url,'name','screen.availWidth,screen.availHeight');
	var strWidthHeight = "width="+ screen.availWidth + ",height="+screen.height;
	//alert(screen.height);
	//alert(strWidthHeight);
	
	newwindow=window.open(url,'name',strWidthHeight);
	//newwindow=window.open(url,'name','height=400,width=200');
	if (window.focus) {
		newwindow.focus();
		//newwindow.location.href = "default.php";
	}
}

function EvenFullerScreen(){
//	window.open("fullscreen.htm","Aaarrgh","fullscreen ");
}

function autoFill()
{
	self.moveTo(0,0);
	self.resizeTo(screen.availWidth,screen.availHeight);
}

function redir(pageName){
	if(pageName != ""){document.location.href=pageName;}	
}

function poplink(cmd)
{
	switch(cmd)
	{
		case "door-designer":
			//createPopDisplay('door-designer.asp', 'PopDiv');
			createExitPop('door-designer.asp');
			isExit = true;
			ExitPop(isExit);
			document.getElementById("detail-floater-wrapper").style.display = "";
			document.getElementById("detail-floater").style.display = "";
			break;

		case "how-to-video":
			createExitPop('how-to-video.asp');
			isExit = true;
			ExitPop(isExit);
			document.getElementById("detail-floater-wrapper").style.display = "";
			document.getElementById("detail-floater").style.display = "";
			break;
			
		case "find-a-stockist":
			createExitPop('find-a-stockist.asp');
			isExit = true;
			ExitPop(isExit);
			document.getElementById("detail-floater-wrapper").style.display = "";
			document.getElementById("detail-floater").style.display = "";
			break;

		default:
			break;
	}
}

function showVideo()
{
	document.getElementById("detail-floater-wrapper").className="showMe";
	document.getElementById("detail-floater").className="showMe";
	document.getElementById("popper-header").className="showMe";
	document.getElementById("popper-main").className="showMe";
}

function hideVideo()
{
	document.getElementById("detail-floater").className="hideMe";
	document.getElementById("detail-floater-wrapper").className="hideMe";
	document.getElementById("popper-header").className="hideMe";
	document.getElementById("popper-main").className="hideMe";
}

	function swapVideoFlow(strVideoRequest)
	{
		
		/*flowplayer( 
			"VideoPlayback_H",  
			"video/flowplayer-3.2.0.swf",  
			"video/"+strVideoRequest+".mov"
   		);*/
		var vUrl = "";
		
		document.getElementById("flashvars").value="video/"+strVideoRequest+".mov";
		
		/*swfobject.embedSWF("video/flowplayer-3.2.0.swf", "VideoPlayback_H", "470", "320", "9.0.0", null, 
			{ 
				config: "{'clip': 'video/"+strVideoRequest+".mov' }",
				controls: "{'fullscreen': 'true' }"
			}
		); */

		
		//-------------------
		
		/*
		flowplayer("VideoPlayback_H", "video/flowplayer-3.2.0.swf", {
		
		clip: {
		autoPlay: false,
		autoBuffering: false,
		url: escape('video/'+strVideoRequest+'.mov'),
		scaling: 'orig'
		
		},
		canvas: {
		height: 340,
		width:470,
		borderRadius: 10,
		backgroundColor: '#000000',
		backgroundGradient: 'none',
		padding:0
		},
		
		plugins: {
		
		controls: {
		url: 'video/flowplayer.controls-3.2.0.swf',
		// which buttons are visible and which not ?
		play:true,
		fullscreen:true,
		// scrubber is a well known nickname to the timeline/playhead combination
		scrubber: true,
		backgroundColor: '#000000',//'#ECF5D9',
		sliderColor: '#9DCB3B',
		progressColor: '#9DCB3B',
		timeColor: '#FFFFFF',
		durationColor: '#9DCB3B',
		bufferColor: '#C2DA55'
		
		}		
		
		}
		});
		
		*/
		//-------------------
		

	}

var viewportheight = 0;
// Get Browser Width
function getBrowserWidth () {
    var viewportwidth;
    //var viewportheight;
    if (typeof window.innerWidth != 'undefined'){
        viewportwidth = window.innerWidth,
        viewportheight = window.innerHeight
    }else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
        viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight
    }else{
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
	return viewportwidth;
}

function siteResize()
{
	/*document.getElementById("ispace_range_atmospheric").style.display = 'none';*/
	document.getElementById("ispace_range_atmospheric").style.display = '';
	var browserWidth;
	var browserCenter;
	var menusLeft;
	var aPadding = 0;
	browserWidth = getBrowserWidth ();

	browserCenter = Math.round(browserWidth/2);
	menusLeft = browserCenter-490;

	// alert(viewportheight);

	//var mWidth = parseInt((screen.availHeight / 100) * 95.703125) + "px";
	//var aWidth = Math.round(((screen.availWidth / 100) * 43.16406) + "px";
	//var aHeight = Math.round(((screen.availHeight / 100) * 55.59895) + "px";

	var aWidth = Math.round((browserWidth / 100) * 43.16406); // + "px";
	var aHeight = Math.round((viewportheight / 100) * 55.59895); // + "px";

	aPadding = Math.round((browserWidth / 100) * 97);
	aPadding = (aPadding - aWidth);
	aPadding = aPadding - aWidth;
	aPadding = aPadding /2;
	
	aWidth = aWidth + "px";
	aHeight = aHeight + "px";
	aPadding = aPadding + "px";
	//alert(aPadding);

	//document.getElementById("main_ispace").style.width = mWidth;
	/*
	document.getElementById("ispace_range_atmospheric").style.width = aWidth;
	document.getElementById("ispace_range_atmospheric").style.height = aHeight;
	document.getElementById("ispace_range_atmospheric").style.display = '';
	document.getElementById("ispace_range_right").style.height = aHeight;
	if(browserWidth > 1024)
	{
		document.getElementById("ispace_range_atmospheric").style.marginLeft = aPadding;
	}
	*/
}



function showPlay (index_id) {
    document.getElementById('show_' + index_id).style.visibility = "hidden"
	document.getElementById('show_' + index_id).style.height = "0px"
	document.getElementById('play_' + index_id).style.height = "115px"	
    document.getElementById('play_' + index_id).style.visibility = "visible"	
	document.getElementById('link_' + index_id).style.height = "115px"	
    document.getElementById('link_' + index_id).style.visibility = "visible"		
}

function hidePlay (index_id) {
    document.getElementById('link_' + index_id).style.height = "0px"	 
    document.getElementById('link_' + index_id).style.visibility = "hidden"		
    document.getElementById('play_' + index_id).style.height = "0px"	 
    document.getElementById('play_' + index_id).style.visibility = "hidden"
    document.getElementById('show_' + index_id).style.height = "115px"		
    document.getElementById('show_' + index_id).style.visibility = "visible"    	
}

/**/

	function showLanguageLink(pageSwitch)
	{
		var thisClassName = "hideMe";
		document.getElementById("static-popper-language").className = "showMe";
	}
	
	function popupControl()
	{
		document.getElementById("static-popper-wrapper").className = "hideMe";
	}

	function showHeaderLink(pageSwitch)
	{
		var thisClassName = "hideMe";
		var element2check = document.getElementById("static-popper-wrapper");
		alertSize();

		var leftPopPos = parseInt(windowWidth/2) - 480;
		leftPopPos += "px";
		//alert(leftPopPos);
		//element2check.style.left = ((windowWidth /2)-470) + 'px';
		element2check.style.left = (leftPopPos);
		if(pageSwitch != "close")
		{
			thisClassName = "showMe";
		}else{
			document.getElementById("ExitPop").className = "hideMe";
			var tmpClassName = "hideMe";
			thisClassName = ((element2check.className == tmpClassName) ? "showMe" : "hideMe");
		}
		
		if(thisClassName == "showMe"){
			document.getElementById("ExitPop").className = "showMe";
			switch(pageSwitch)
			{
				case "how-to-install":
					clientSideInclude('includeone', 'how-to-video.asp');
					break;
				case "store-locator":
					clientSideInclude('includeone', 'home-decor-store-locator.asp');
					//clientSideInclude('includeone', 'find-a-stockist.asp');
					break;
				case "faqs":
					clientSideInclude('includeone', 'home-decor-frequently-asked-questions.asp');
					break;
				case "about":
					clientSideInclude('includeone', 'about-home-decor.asp');
					break;
				case "stanley":
					clientSideInclude('includeone', 'stanley.asp');
					break;
				case "contact":
					clientSideInclude('includeone', 'contact-home-decor.asp');
					break;
				case "select-language":
					clientSideInclude('includeone', 'language-selection.asp');
					break;
				case "site-search":
					if(document.getElementById("search_site_field").value != "")
					{
						var randomnumber=Math.floor(Math.random()*11);
						clientSideInclude('includeone', 'home-decor-product-search.asp?smtg="+randomnumber+"&search-term=' + document.getElementById("search_site_field").value);
						element2check.style.top = "-50px";
						//element2check.style.left = (screen.availWidth/2)- 470 + "px";
						element2check.className = thisClassName;
					}

					return false;
					break;

				case "news":
					clientSideInclude('includeone', 'home-decor-news.asp');
					break;
					
				case "site-search-door":
					clientSideInclude('includeone', 'home-decor-product-search.asp?smtg="+randomnumber+"&search-term=door');
					break;

				case "site-search-storage":
					clientSideInclude('includeone', 'home-decor-product-search.asp?smtg="+randomnumber+"&search-term=storage');
					break;
					
				case "terms":
					clientSideInclude('includeone', 'home-decor-terms-and-conditions.asp');
					break;

				default:
					thisClassName = "hideMe";
					break;
			}
		}
		element2check.style.top = (0-50) +'px'; //(0-45) +'px';
		//element2check.style.left = (screen.availWidth /2) -470 + "px";
		//element2check.className = thisClassName;
		element2check.className = thisClassName;
	}

		function headClicker(divOption){
			var thediv=document.getElementById("detail-floater");
			var thediv0=document.getElementById("detail-floater-wrapper");
			var thediv1=document.getElementById("detail-floater-content");
			
			if(thediv.className == "hideMe"){
				tempClassName = "showMe";
			}else{
				tempClassName = "hideMe";
				thediv.className = tempClassName;
				thediv0.className = tempClassName;
				thediv1.className = tempClassName;
				document.getElementById("popper-header-designer").className = tempClassName;
				document.getElementById("popper-main-designer").className = tempClassName;
				document.getElementById("popper-header-video").className = tempClassName;
				document.getElementById("popper-main-video").className = tempClassName;
				document.getElementById("popper-header-stockist").className = tempClassName;
				document.getElementById("popper-main-stockist").className = tempClassName;
				document.getElementById("popper-header-interior").className = tempClassName;
				document.getElementById("popper-main-interior").className = tempClassName;
			}
			
			var tempClassName
			
			switch(divOption)
			{
				case "designer":
					thediv.className = tempClassName;
					thediv0.className = tempClassName;
					thediv1.className = tempClassName;
					document.getElementById("popper-header-designer").className = tempClassName;
					document.getElementById("popper-main-designer").className = tempClassName;
					break;
				case "video":
					thediv.className = tempClassName;
					thediv0.className = tempClassName;
					thediv1.className = tempClassName;
					document.getElementById("popper-header-video").className = tempClassName;
					document.getElementById("popper-main-video").className = tempClassName;
					break;
				case "stockist":
					thediv.className = tempClassName;
					thediv0.className = tempClassName;
					thediv1.className = tempClassName;
					document.getElementById("popper-header-stockist").className = tempClassName;
					document.getElementById("popper-main-stockist").className = tempClassName;
					break;
				case "interior":
					thediv.className = tempClassName;
					thediv0.className = tempClassName;
					thediv1.className = tempClassName;
					document.getElementById("popper-header-interior").className = tempClassName;
					document.getElementById("popper-main-interior").className = tempClassName;
					break;
				default:
					tempClassName = "hideMe";
					thediv.className = tempClassName;
					thediv0.className = tempClassName;
					thediv1.className = tempClassName;
					document.getElementById("popper-header-designer").className = tempClassName;
					document.getElementById("popper-main-designer").className = tempClassName;
					document.getElementById("popper-header-video").className = tempClassName;
					document.getElementById("popper-main-video").className = tempClassName;
					document.getElementById("popper-header-stockist").className = tempClassName;
					document.getElementById("popper-main-stockist").className = tempClassName;
					document.getElementById("popper-header-interior").className = tempClassName;
					document.getElementById("popper-main-interior").className = tempClassName;
					break;
			}
			
	
			return false;
		}
		
function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}

/*MAP INCLUDE*/

			function load() {
				if (GBrowserIsCompatible()) {
					var map = new GMap2(document.getElementById("map"));
					map.setCenter(new GLatLng(37.4419, -122.1419), 13);
				}

			}


		//window.onload
		function loadMaps(){

			if (GBrowserIsCompatible()) {
				var mapdiv = document.getElementById("map");
				// CFH DEFAULT
				//var strhtml = "<div class='paragraph_title'>CFH Creative Communications Ltd</div><div class='paragraph_body'>The Portal,<br>Bridgewater Close,<br>Bentley Wood,<br>Lancashire,<br>BB11 5TT<br><span class='letter_highlight'>T:</span> +44 (0)1282 446100<br /><span class='letter_highlight'>F:</span> +44 (0)1282 446110<br><span class='letter_highlight'>E:</span> info@cfh-uk.net</div>";
				//var point = new GLatLng(53.7826, -2.2954);
				var strhtml = "<div class='paragraph_body'><div class='paragraph_title'>Home Decor Innovations<br /></div><div class='paragraph_body'>Beighton Road East,<br>Sheffield,<br>South Yorkshire,<br>S20 7JZ</div><div class='clear'></div><div class='paragraph_title'>T:</div><div class='paragraph_body'> +44 (0)114 276 4099</div><div class='paragraph_title'>F:</div><div class='paragraph_body'> +44 (0)114 276 4099<br /></div><div class='paragraph_title'>E:</div><div class='paragraph_body'> info@hdhc.com</div></div>";
				
				
				//alert(strhtml);
				
				var point = new GLatLng(53.3498,-1.3567);
				var marker = new GMarker( point );
				//GEvent.addListener( marker, "click", function() { marker.openInfoWindowHtml(strhtml); } );
		
				var map = new GMap2(mapdiv);
					map.setMapType(G_NORMAL_MAP);
					map.setCenter(point, 6);
					map.addControl(new GLargeMapControl());
					map.enableDoubleClickZoom();
					map.enableScrollWheelZoom();
					map.addOverlay(marker);
				
				GEvent.trigger(marker, "click");
			}
			placeMarkerAtPointAndCenter('S20 7JZ','map',strhtml)
			mapLoad();
			//showmarkers();
			map.setZoom(map.getBoundsZoomLevel(bounds));
			map.setCenter(bounds.getCenter());

		}//;


	function SubmitMapSearch() {
		// alert("got it");
		document.getElementById("errMessage").innerHTML = "";
		document.getElementById("mapframe").src = "loading.asp";

		var icon = new GIcon();
		icon.image = "images/hd_stockist_logo_01.png";
		icon.shadow = "shadow50.png";
		icon.iconSize = new GSize(20, 32);  /// (w,h)
		icon.shadowSize = new GSize(28, 20);
		icon.iconAnchor = new GPoint(1, 25); // (w,h) h=increase to get pin point higher,  20 moves north 20 pixals
		icon.infoWindowAnchor = new GPoint(5, 1);

		localSearch.setSearchCompleteCallback(null, 
			function() {
				if (localSearch.results[0]) {    
					document.getElementById("userLatitude").value = localSearch.results[0].lat;
					document.getElementById("userLongitude").value = localSearch.results[0].lng;
					var aUrl = "find-a-stockist-view.asp?";
					
					//aUrl += "fldPostalCodePart1=" + localSearch.results[0].lat;
					//aUrl += "&fldPostalCodePart2=" + localSearch.results[0].lng;
					//aUrl += "&userDistance=" + document.getElementById("fldUserDistance").value;
					
					aUrl += "fldPostalCodePart1="+document.getElementById("fldPostalCodePart1").value;
					aUrl += "&userLatitude=" + localSearch.results[0].lat;
					aUrl += "&fldPostalCodePart2="+document.getElementById("fldPostalCodePart2").value;
					aUrl += "&userlongitude=" + localSearch.results[0].lng;
					aUrl += "&userDistance="+document.getElementById("fldUserDistance").value;
					document.getElementById("stockist-strap-instruction-2").innerHTML = "Click on a marker on the map to get details or click 'back' to search again";
					
					top.aUrl = aUrl;
					//document.getElementById("mapWrapper").className="hideMe";
					//document.getElementById("mapViewer").className="showMe";
					document.getElementById("mapWrapper").style.display="none";
					document.getElementById("mapViewer").style.display="block";
					document.getElementById('backbutton').style.display="block";
					document.getElementById('backbuttonspacer').style.display='none';
					document.getElementById("mapframe").src = aUrl;


				}else{
					document.getElementById("errMessage").innerHTML = "Postcode not recognised<br />please check and try again<br /><br />";
				}
			}
		);  
	
		if(document.getElementById("fldPostalCodePart1").value == "" || document.getElementById("fldPostalCodePart2").value == "")
		{
			document.getElementById("errMessage").innerHTML = "Postcode not recognised<br />please check and try again<br /><br />";
		}else{
			var address = document.getElementById("fldPostalCodePart1").value + " " + document.getElementById("fldPostalCodePart2").value + ", UK"
			localSearch.execute(address);
		}
	}
	
	function locateStockist()
	{
		document.getElementById('mapViewer').style.display='none';
		document.getElementById('mapWrapper').style.display='block';
		document.getElementById('stockist-strap-instruction').innerHTML = 'Search by entering your postcode below';
		document.getElementById('backbutton').style.display='none';
		document.getElementById('backbuttonspacer').style.display='block';
	}
	
	function selfCentre()
	{
		// alert(screen.availheight);
		var width=1024;
		var height=1280;
		if(height > screen.availheight){height = screen.availheight}
		self.moveTo((screen.availwidth-width)/2,(screen.availheight-height)/2);
		self.resizeTo(width,height);
	}
	
	function getWindowWidth() {
	  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
	}
	 
	function getWindowHeight() {
	  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
	}
	
	function alertSize() {

	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	  }
	  //window.alert( 'Width = ' + windowWidth );
	  //window.alert( 'Height = ' + windowHeight );
	}
	
	
/*
CURSOR STUFF
*/
function cursor_link() {
	document.body.style.cursor = 'pointer';
}

function cursor_wait() {
	document.body.style.cursor = 'wait';
}

function cursor_clear() {
	document.body.style.cursor = 'default';
}

function calc() {
	var dummy = 0;
	
	for (var i=0; i<1000000;i++) {
		for (var z=0; i<1000000;i++) {
			dummy = dummy + z + i;
		}
	}
	
	cursor_clear();
}

function checkSearchInput(defaultSearchFieldValue)
{
	if(document.getElementById("search_site_field").value == defaultSearchFieldValue){document.getElementById("search_site_field").value = ""}
}

/****************************************************************************************
		MAPPING
****************************************************************************************/
		function initializeMap() {
		
		      if (GBrowserIsCompatible()) {
				//alert("initialising... ..");
				//document.getElementById("mapContainer").style.border="1px solid #000";
				// create the map
		        var map = new GMap2(document.getElementById("mapContainer"));
				map.addControl(new GSmallMapControl());
				map.setMapType(G_NORMAL_MAP);
				//alert("stage 1");
				// create the custom icon
				var customIcon = new GIcon(G_DEFAULT_ICON);
				customIcon.image = "images/hd_stockist_logo_01.png";
				customIcon.iconSize = new GSize(109, 28);
				customIcon.iconAnchor = new GPoint(30, 27);
				//alert("stage 2");
				// encode enpresiv's address
				var geocoder = new GClientGeocoder();
				//var point = new GLatLng(53.3498,-1.3567);
				geocoder.getLatLng(
					'beighton road east, S20 7JZ, UK',
					function(point) {
						if(!point) {
						//alert("address not found");
						} else {
							//alert("stage 3");
							map.setCenter(point, 16);
							var marker = new GMarker(point, {icon:customIcon});
							map.addOverlay(marker);
							//alert("complete ... ..");
						}
					}
				);
			}
		}
	
		//google.load("maps", "2");
