// JavaScript Document

function goto(place) {
	parent.window.location.href = place;
	return;
	}

function pullDown_Menu(){
	var url = document.pullDown.selectname.options[document.pullDown.selectname.selectedIndex].value;
	window.location.href = url;
	}
	
//FUNCTION LIST
// showDiv()
// showBasket()
// closeDiv()
// showReview()
// showReviewAdd()
// escapeVal()
// closeReview()
// sendReviewForm()

function showDiv () {
	
	var pathinfo = (location.pathname.indexOf('?') != -1) ? location.pathname.substring(0, location.pathname.indexOf('?')) : location.pathname;
	var divshow = document.getElementById('searchbox');

	if (document.Search.keyword.value.length > 3) 
		{
			if (divshow.style.display != "block") 
			{
				if( typeof( window.innerWidth ) == 'number' ) {
    				//Non-IE
    				width = window.innerWidth;
    				var newright = eval( ((width-1024)/2) + 136  )+'px';
					//alert('FFwidth - ' + width + 'new right - ' + newright);
					
  					} else if( document.documentElement && ( document.documentElement.clientWidth) ) {
    				//IE 6+ in 'standards compliant mode'
    				width = document.documentElement.clientWidth;
    				var newright = eval( ((width-1024)/2) + 136 )+'px' ;
					//alert('IEwidth - ' + width  + 'new right - ' + newright);
					}
				if (width > 1024) {
				divshow.style.right = newright;
				//alert('right changed to '+divshow.style.right);
				}
				divshow.style.display = "block";
			}
			
			var $j = jQuery.noConflict();
			
			$j.ajax({
				type: "POST",
				url: "/AJAXsearchboxresults.cfm",
				data: "test=" + document.Search.keyword.value + "&pagename=" + pathinfo,
				dataType: "html",
				success: function(msg){				
					$j("#searchcontent").html(msg);
				}

			})
			
			//new ajax ('/AJAXsearchboxresults.cfm', {postBody: "test=" + document.Search.keyword.value + "&pagename=" + pathinfo, update: $('searchcontent') });
	}
	else if (divshow.style.display == "block") 
	{
	closeDiv();
	}
}

//updates the right hand banner so that correct ads and basket are shown on cached pages - mat06
function showBasket() {
		//new ajax ('/RHSMenu.htm', {update: $('banner') });
}

function closeDiv () {
	var divshow = document.getElementById('searchbox');
	divshow.style.display = "none";
	//new ajax ('/AJAXsearchboxresults.cfm', {update: $('searchcontent') });
}

function showreview() {
		var addreviewshow = document.getElementById('addreviewbox');
		

			
			addreviewshow.style.display = "none";

			

}

function showreviewadd(itemid) {
		var addreviewshow = document.getElementById('addreviewbox');


		

			addreviewshow.style.display = "block";

			
		    //makeGetRequest('/addreview.htm?item=' + itemid, 'reviewbox');
			
}

function escapeVal(textarea,replaceWith){
	textarea.value = escape(textarea.value);
	for(i=0; i<textarea.value.length; i++){
	
	
		if(textarea.value.indexOf("%0D%0A") > -1){
		
			textarea.value=textarea.value.replace("%0D%0A",replaceWith);
		}
		else if(textarea.value.indexOf("%0A") > -1){
		
			textarea.value=textarea.value.replace("%0A",replaceWith);
		}
		else if(textarea.value.indexOf("%0A%0A") > -1){
		
			textarea.value=textarea.value.replace("%0A%0A",replaceWith + replaceWith);
		}
		else if(textarea.value.indexOf("%0D") > -1){
		
			textarea.value=textarea.value.replace("%0D",replaceWith);
		}
		
	
	}
textarea.value=unescape(textarea.value);

}



function closereview() {

		var addreviewshow = document.getElementById('addreviewbox');

		addreviewshow.style.display = "none";

}

function sendreviewform() {

var error = '';
var missingtext = 'false';
var name = document.reviewform.name.value;
var email = document.reviewform.email.value;
var text = document.reviewform.reviewtext.value;
var textmarker = document.reviewform.reviewtext;

var mark;
for(var i=0; i < document.reviewform.mark.length; i++)
{
	var temp = document.reviewform.mark[i];
	if(temp.checked) 
		{ mark = temp.value; break; }
}

var itemid = document.reviewform.itemid.value;

if (name=="") 
	{
	var error = error + 'Please enter your name \n';	
	 var missingtext = 'true';
	}
	

	var match = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{ 1,3})|([a-zA-Z]{2,6})|(aero|coop|info|museum|name))$/g.test(email);	
	
	if (match==false) 
	{
	var error = error + 'Please enter a real email address \n';
	 var missingtext = 'true';
	}
	
	
	if (email=="") 
	{
	var error = error + 'Please enter your email \n';
	 var missingtext = 'true';
	}

if (text=="") 
	{
	var error = error + 'Please enter your text \n';
	 var missingtext = 'true';
	} 
	
	
	
	
	


	
if (mark==null) 
	{
	var error = error + 'Please enter the mark \n' ;
	 var missingtext = 'true';
	}

if (missingtext == 'false') {
	
escapeVal(textmarker, '<br />');
var text = document.reviewform.reviewtext.value;
makeGetRequest('/ReviewAdd.htm?item=' + itemid + '&name=' + name + '&email=' + email + '&reviewtext=' + text + '&mark=' + mark, 'addreviewbox');
// + itemid + '&name=' + name + '&email=' + email + '&reviewtext=' + text + '&mark=' + mark
} else {

alert(error);
}





}

//Functions for the inclusion of flash in IE without a big blue thing around it!

function showflash() 
	{
	document.write('<object type="application/x-shockwave-flash" data="http://www.projectorpoint.co.uk/images/banners/selector-final.swf" width="149" height="182"> ');
	document.write('<param name="movie" value="http://www.projectorpoint.co.uk/images/banners/selector-final.swf" /> ');
	document.write('<param name="wmode" value="transparent" /> ');
	document.write('<param name="menu" value="false" />');
	document.write('<EMBED src="http://www.projectorpoint.co.uk/images/banners/selector-final.swf" menu=false quality=high bgcolor=##FFFFFF WIDTH="149" HEIGHT="182" NAME="effect" ALIGN=""TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/ge">');
	document.write('</EMBED>');
	document.write('</object>');
	}	
	
	
	function showflash2() 
	{	
	document.write('<OBJECT type="application/x-shockwave-flash" data="http://www.projectorpoint.co.uk/images/projectorselectorDEMO.swf" WIDTH="406" HEIGHT="358" id="effect" ALIGN="" BORDER=0>');
	document.write('<PARAM NAME=movie VALUE="http://www.projectorpoint.co.uk/images/projectorselectorDEMO.swf" /> ');
	document.write('<param name="menu" value="false" /> ');
	document.write('<PARAM NAME=quality VALUE=high />');
	document.write('<EMBED src="http://www.projectorpoint.co.uk/images/projectorselectorDEMO.swf" menu=false quality=high bgcolor=##FFFFFF WIDTH="406" HEIGHT="358" NAME="effect" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/ge">');
	document.write('</EMBED>');
	document.write('</object>');	
	}
	
// another bit of ajax	
function makeGetRequest(page, divId) {
    var xmlHttp;
	
	xmlHttp = createRequestObject();
	
	 
	
    //make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    
	//assign a handler for the response
	
	xmlHttp.open('get', page, true);
	
	xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        if(xmlHttp.readyState==4){
	
		
        //read and assign the response from the server
        var response = xmlHttp.responseText;
		
        var divtochange = document.getElementById(divId);
		
        //in this case simply assign the response to the contents of the <div> on the page. 
        
		
		
		divtochange.innerHTML = response;
		
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
        }
      }
	//actually send the request to the server
    
	xmlHttp.send(null); 
	
	
}

function createRequestObject() {
    
	var xmlHttp;
  try
    {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		
	}
	  
	catch (e)
		{
			// Internet Explorer
			try
			  {
			  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  
			  }
			catch (e)
				  {
					  try
						{
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");		
						}
					  	
						catch (e)
							{
							alert("Your browser does not support AJAX!");
							return false;
							}
				  }
	}
	
	
	return xmlHttp;
}
