function GetXmlHttpObject()
{
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

function picAlpha(section, letter)
{
 	var currentDate = new Date();  
	var url = "results.php";
	var params = "s="+section+"&l="+letter+"&t="+currentDate.getSeconds();
	if(section == "ethnic")
	{
		document.getElementById('txtPicSearch').value = "";
		document.getElementById('selPicCategory').selectedIndex = 0;
		document.getElementById('selPicArea').selectedIndex = 0;		
	}
	else if (section == "carers")
	{
		document.getElementById('txtPicSearch').value = "";
		document.getElementById('selPicCategory').selectedIndex = 0;		
	}
	else if (section == "mental")
	{
		document.getElementById('txtPicSearch').value = "";
		document.getElementById('selPicCategory').selectedIndex = 0;		
	}
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("GET", url+"?"+params, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('results').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function viewPage(section, browsetype, letter, id)
{
	var currentDate = new Date() 
	var url = "viewpage.php";
	var params = "s="+section+"&b="+browsetype+"&l="+letter+"&id="+id+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("GET", url+"?"+params, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('results').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function picSearch(section, browsetype)
{
	var currentDate = new Date()
	var url = "results.php";
	var key = "";
	var area = "";	
	if(browsetype == 'search')
	{
		var search = document.getElementById('txtPicSearch').value;
		document.getElementById('selPicCategory').selectedIndex = 0;
		document.getElementById('selPicArea').selectedIndex = 0;
	}
	else if(browsetype == 'key')
	{
		var search = document.getElementById('selPicCategory').value;		
		var keytext = document.getElementById('selPicCategory').options[document.getElementById('selPicCategory').selectedIndex].text;
		keytext = keytext.replace("&","and");		
		document.getElementById('txtPicSearch').value = "";
		if(document.getElementById('selPicArea').value != "")
		{
			key = document.getElementById('selPicArea').value;
		}
	}
	else if(browsetype == 'area')
	{
		var search = document.getElementById('selPicArea').value;		
		var keytext = document.getElementById('selPicArea').options[document.getElementById('selPicArea').selectedIndex].text;
		document.getElementById('txtPicSearch').value = "";
		if(document.getElementById('selPicCategory').value != "")
		{
			key = document.getElementById('selPicCategory').value;
		}
	}
	var params = "s="+section+"&v="+search+"&b="+browsetype+"&k="+keytext+"&key="+key+"&t="+currentDate.getSeconds();

    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('results').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);
}

function picLeafletSearch()
{
	document.getElementById('picResults1').style.display = "block";
	document.getElementById('picResults1').innerHTML = "<img src=\"images/loading.gif\" /> Searching...Please wait.";
	
	var currentDate = new Date()
	var url = "leafletresults.php";
	var search = document.getElementById('txtPicLeaflet').value;
	var cat = document.getElementById('selCategory').value;
	var loc = document.getElementById('selLocation').value;
	var aud = document.getElementById('selAudience').value;
	var type = document.getElementById('selType').value;
	
	var params = "v="+search+"&c="+cat+"&l="+loc+"&a="+aud+"&lt="+type+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('results').innerHTML = xmlhttp.responseText;
			document.getElementById('picResults1').style.display = "none";
		}
	}
	xmlhttp.send(params);	
}

function request(id)
{
	var currentDate = new Date()
	var url = "leafletresults.php";
	var params = "id="+id+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("GET", url+"?"+params, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('results').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function SetPointer(TheRow, ThePointerColor) 
{
	var num_of_cells=TheRow.cells.length;
	for (var i=0;i<num_of_cells;i++) {
		TheRow.cells[i].bgColor=ThePointerColor;
	}
	return true;
}
function valpic()
{
    if (document.getElementById('txtPicName').value=="" || document.getElementById('txtPicEmail').value=="" || document.getElementById('txtPicTelephone').value=="" || document.getElementById('txtPicAddress').value=="")
    {
        alert ("Please complete required Fields.")
    }
    else
    {
		picRequest();
	}
}

function picRequest()
{
	var currentDate = new Date()
	var url = "leafletresults.php";
	var name = document.getElementById('txtPicName').value;		
	var email = document.getElementById('txtPicEmail').value;		
	var telephone = document.getElementById('txtPicTelephone').value;		
	var address = document.getElementById('txtPicAddress').value;		
	var comments = document.getElementById('txtPicComments').value;					

	var lname = document.getElementById('piclname').value;
	var lprice = document.getElementById('piclprice').value;
	var lnumber = document.getElementById('piclnumber').value;
	var ldescription = document.getElementById('picldescription').value;
	var llocation = document.getElementById('picllocation').value;
	var lID = document.getElementById('piclID').value;

	var params = "name="+name+"&email="+email+"&telephone="+telephone+"&address="+address+"&comments="+comments+"&lname="+lname+"&lprice="+lprice+"&lnumber="+lnumber+"&ldescription="+ldescription+"&llocation="+llocation+"&lid="+lID+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('results').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);	
}

function picLanguage(browsetype)
{
	var currentDate = new Date()
	var url = "languageresults.php";
	if (browsetype == 'key')
	{
		var search = document.getElementById('selKeyword').value;
		document.getElementById('selLanguage').selectedIndex = 0;
	}
	else if(browsetype == 'lan')
	{
		var search = document.getElementById('selLanguage').value;		
		document.getElementById('selKeyword').selectedIndex = 0;
	}
	document.getElementById('picResults1').innerHTML = "<img src=\"images/loading.gif\" /> Searching...Please wait.";
	var params = "b="+browsetype+"&v="+search+"&t="+currentDate.getSeconds();

    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
		 	document.getElementById('picResults1').innerHTML = "";
			document.getElementById('results').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);
}

function video(language, section)
{
	var currentDate = new Date();
 	if(typeof(window.innerWidth) == 'number')
	{ 
        availHeight = window.innerHeight; 
        availWidth = window.innerWidth; 
    }
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))					
	{ 
        availHeight = document.documentElement.clientHeight; 
        availWidth = document.documentElement.clientWidth; 
    }
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{ 
        availHeight = document.body.clientHeight; 
        availWidth = document.body.clientWidth; 
    }
	var fader = document.getElementById('divFade');
    fader.style.height = availHeight+"px";
    fader.style.width = availWidth+"px";
    fader.style.display="block";
    fader.style.zindex = "900";
    //fader.style.position="fixed";
    var indicatorWidth = 380;
    var indicatorHeight = 300;
    var left = (availWidth/2) - (indicatorWidth/2);
    var top = (availHeight/2) - (indicatorHeight/2);
	var decline = document.getElementById('divVideo');
    decline.style.top=top+"px";
    decline.style.left=left+"px";
    decline.style.display="block";
    decline.style.zindex = "999";
    //decline.style.position="fixed";

	var url = "videos/video.php";
	var params = "language="+language+"&section="+section+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("GET", url+"?"+params, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('divVideo').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);    
}
function cVideo()
{
	document.getElementById('divVideo').innerHTML = "";
	var fader = document.getElementById('divFade');
	fader.style.display = "none";
	var decline = document.getElementById('divVideo');
    decline.style.display = "none";
}
function cm(value)
{
	var currentDate = new Date()
	var url = "cm.php";
	var params = "v="+value+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			window.open("http://choiceandmedication.org.uk/northumberland-tyne-and-wear/");		 
		}
	}
	xmlhttp.send(params);	
}

/********************SELF HELP**************************/
function selfhelp(recid)
{
	var currentDate = new Date(); 
  	document.getElementById('popup').innerHTML = "<div class=\"loader\"><img src=\"images/loading.gif\" /></div><span class=\"loading\">Loading....</span>";
	fade('popup');
	var url = "listleaflets.php";
	var params = "recid="+recid+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('popup').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);
}
function leafletFile(recid)
{
	var currentDate = new Date(); 
	document.getElementById('popup').style.width = "580px";
  	document.getElementById('popup').innerHTML = "<div class=\"loader\"><img src=\"images/loading.gif\" /></div><span class=\"loading\">Loading....</span>";
	fade('popup');
	var url = "listleaflets.php";
	var params = "recid="+recid+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('popup').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);
}

function selfhelpvideo(v, title)
{
  	document.getElementById('popupshvideo').innerHTML = "<div class=\"loader\"><img src=\"images/loading.gif\" /></div><span class=\"loading\">Loading....</span>";
	fade('popupshvideo');
	var url = "shvideo.php";
	var params = "v="+v+"&title="+title+"&t="+Math.random();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('popupshvideo').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);
}
function fade(popup)
{
 	if(typeof(window.innerWidth) == 'number')
	{ 
        availHeight = window.innerHeight; 
        availWidth = window.innerWidth; 
    }
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))					
	{ 
        availHeight = document.documentElement.clientHeight; 
        availWidth = document.documentElement.clientWidth; 
    }
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{ 
        availHeight = document.body.clientHeight; 
        availWidth = document.body.clientWidth; 
    }

	var fader = document.getElementById('fade');
    fader.style.height = document.body.clientHeight; +"px";
    fader.style.width = availWidth+"px";
    fader.style.display="block";
    fader.style.zindex = "900";
    //fader.style.position="fixed";
    
    if(popup == "popup")
    {
		var indicatorWidth = 620;
	    var indicatorHeight = 400;
	    var left = (availWidth/2) - (indicatorWidth/2);
    	var top = (availHeight/2) - (indicatorHeight/2);
	}
	else if(popup == "popuppdf")
	{
		var indicatorWidth = 800;
	    var indicatorHeight = 800;
	    var left = (availWidth/2) - (indicatorWidth/2);
    	var top = (availHeight/2) - (indicatorHeight/2);		
	}
	else if(popup == "audio")
	{
		var indicatorWidth = 460;
	    var indicatorHeight = 200;
	    var left = (availWidth/2) - (indicatorWidth/2);
    	var top = (availHeight/2) - (indicatorHeight/2);		
	}	
	else if(popup == "popupshvideo")
	{
		var indicatorWidth = 640;
	    var indicatorHeight = 500;
	    var left = (availWidth/2) - (indicatorWidth/2);
    	var top = (availHeight/2) - (indicatorHeight/2);		
	}		
	var popup = document.getElementById(popup);
	
    popup.style.top=top+"px";
    popup.style.left=left+"px";
    popup.style.display="block";
    popup.style.zindex = "999";
    //popup.style.position="fixed";	
}

function closepopup(value)
{
 	document.getElementById(value).innerHTML = "";
 	document.getElementById(value).style.display = "none";
 	document.getElementById('fade').style.display = "none";
}

function audio()
{
	var currentDate = new Date()
	var url = "audio.php";
	var params = "?t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("GET", url+params, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('results').innerHTML = xmlhttp.responseText;
			document.getElementById('picResults1').style.display = "none";
		}
	}
	xmlhttp.send(null);
}

function play(value)
{
	fade('audio');
	var currentDate = new Date()
	var url = "play.php";
	var params = "?p="+value+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("GET", url+params, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('audio').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);	
}

function translated(recid, lang)
{
	var currentDate = new Date(); 
  	document.getElementById('popup').innerHTML = "<div class=\"loader\"><img src=\"images/loading.gif\" /></div><span class=\"loading\">Loading....</span>";
	fade('popup');
	var url = "listtranslated.php";
	var params = "recid="+recid+"&lang="+lang+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('popup').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);
}
function readreviews(recid, title)
{
	var currentDate = new Date(); 
  	document.getElementById('popup').innerHTML = "<div class=\"loader\"><img src=\"images/loading.gif\" /></div><span class=\"loading\">Loading....</span>";
	fade('popup');
	var url = "readreviews.php";
	var params = "recid="+recid+"&title="+title+"&t="+currentDate.getSeconds();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('popup').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);	
}

function review(recid, title)
{
	fade('popup');
	document.getElementById('popup').innerHTML = "<span class=\"popupheader\">"+title+"</span><p>Share your thoughts with other people and let them know what you think of this leaflet.</p><span class='revT''>Comments</span><span class='revI'><textarea name='txtReview' id='txtReview' cols='35' rows='5'></textarea></span><span class='revT'>Rating</span><span class='revI'><ul class='star-rating'><li class='current-rating' id='current-rating'></li><li><a href='javascript:;' onclick='vote(1); return false;' title='1 star out of 5' class='one-star'>1</a></li><li><a href='javascript:;' onclick='vote(2); return false;' title='2 star out of 5' class='two-stars'>2</a></li><li><a href='javascript:;' onclick='vote(3); return false;' title='3 star out of 5' class='three-stars'>3</a></li><li><a href='javascript:;' onclick='vote(4); return false;' title='4 star out of 5' class='four-stars'>4</a></li><li><a href='#' onclick='vote(5); return false;' title='5 star out of 5' class='five-stars'>5</a></li></ul></span><input type='hidden' name='rID' id='rID' value='"+recid+"' /><input type='hidden' name='current-rating-result' id='current-rating-result' /><input type='button' name='btnReview' id='btnReview' value='Review' onclick='addreview()' /><div class='cVideo'><a href='javascript:;' onclick=\"closepopup('popup')\"><img src='images/close.gif' alt='Close' /></a></div>";
}

function vote(amnt)
{
	if(amnt == 1)
	{
		document.getElementById('current-rating').style.width = "25px";
		document.getElementById('current-rating-result').value = 1;
	}
	else if(amnt == 2)
	{
		document.getElementById('current-rating').style.width = "50px";		
		document.getElementById('current-rating-result').value = 2;
	}
	else if(amnt == 3)
	{
		document.getElementById('current-rating').style.width = "75px";		
		document.getElementById('current-rating-result').value = 3;
	}
	else if(amnt == 4)
	{
		document.getElementById('current-rating').style.width = "100px";		
		document.getElementById('current-rating-result').value = 4;
	}
	else if(amnt == 5)
	{
		document.getElementById('current-rating').style.width = "125px";	
		document.getElementById('current-rating-result').value = 5;
	}
}

function addreview()
{
 	var msg = ""
	if(document.getElementById('txtReview').value == "")
	{
		msg += " - Review\n";
	}
	if(document.getElementById('current-rating-result').value == "")
	{
		msg += " - Rating";
	}
	if(msg != "")
	{
	 	alert("Please complete the following:\n"+msg);
	}
	else
	{
		var url = "rate.php";
		var id = document.getElementById('rID').value;
		var r1 = document.getElementById('txtReview').value.replace("&","and");
		var r2 = document.getElementById('current-rating-result').value;
		var params = "i="+id+"&r1="+r1+"&r2="+r2+"&t="+Math.random()
	    xmlhttp=GetXmlHttpObject();
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function() 
		{
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				document.getElementById('popup').innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(params);
	}
}

function mhavideo(v, title)
{
  	document.getElementById('popupshvideo').innerHTML = "<div class=\"loader\"><img src=\"images/loading.gif\" /></div><span class=\"loading\">Loading....</span>";
	fade('popupshvideo');
	var url = "mhavideo.php";
	var params = "v="+v+"&title="+title+"&t="+Math.random();
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('popupshvideo').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(params);
}
