// FUNCTION TO GET A COOKIE.
function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie;             
    if (dc.length > 0) {              
	    begin = dc.indexOf(cname);       
        if (begin != -1) {           
	        begin += cname.length;       
	        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
	return null;
}


	//var	 itemDetail=getCookie('itemDetail');
	//var	 itemMain=getCookie('itemMain');
	//alert(itemDetail+":"+itemMain);
	//if ((itemDetail != "" && itemDetail != null && itemDetail != "null" && itemDetail != "undefined")
	//	&& (itemMain != "" && itemMain != null && itemMain != "null" && itemMain != "undefined")){
		// WE HAVE A RESULT //
		surveypopUp();	
	//}




			////////////////// EDIT THE NUMBER OF SECONDS BELOW FOR THE DELAY //
			var delaytime=1;


			////////////////// EDIT THE PERCENTAGE OF TIME IT SHOULD APPEAR //
			var appearPc=100;
			////////////////// END OF EDITING //

			function createSurveyCookie() {
				document.cookie = "surveycookie="+new Date().getTime()+"; path=/";
			}
			function clearSurveyCookie() {
				document.cookie = "surveycookie=-1; path=/";
			}
			
			function readSurveyCookie() {
				var nameEQ = "surveycookie=";
				var ca = document.cookie.split(';');
				for(var i=0;i < ca.length;i++) {
					var c = ca[i];
					while (c.charAt(0)==' ') c = c.substring(1,c.length);
					if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
				}
				return null;
			}
			
			function checkSurveyCookie() {	
				var ck = readSurveyCookie("surveycookie");
				if (ck == null || ck == "null" || ck == undefined || ck == "") {
					var num = Math.random();
					var appearNum = appearPc/100;
					if (num < appearNum) {
						createSurveyCookie();
						window.surveyTimer = setTimeout("checkSurveyCookie()", 1000);
					} else {
						clearSurveyCookie();
					}
				} else {
					ck = parseInt(ck);
					if (ck > -1) {
						var time_now = new Date().getTime();
						var time_then = ck;
						var difference = time_now - time_then;
						var delaytimeMiliseconds = delaytime*1000;
						if (difference > delaytimeMiliseconds) {
							showSurveysurveypopUp();
						} else {
							window.surveyTimer = setTimeout("checkSurveyCookie()", 1000);
						}
					}
				}
			}
		
			function showSurveysurveypopUp() {
				var lay = document.getElementById("surveypop");
				positionDiv();
				lay.style.display = '';
				lay.style.display = "inline";
				lay.style.visibility = "visible";
			}
			
			function closeSurveysurveypopUp() {
				var lay = document.getElementById("surveypop");
				lay.style.display = "none";
				lay.style.visibility = "hidden";
				clearSurveyCookie();
			}
			function remindUserLater() {
				createSurveyCookie();
				window.surveyTimer = setTimeout('checkSurveyCookie()', 1000);
				closeSurveysurveypopUp();
			}

			function positionDiv() {
				var lay = document.getElementById("surveypop");
				var layerwidth = 700;
				var layerheight = 500;
				var width = screen.width;
				var height = screen.height;
				var top = parseInt((height - layerheight) / 2) - 100;
				var left = parseInt((width - layerwidth) / 2);
				lay.style.left = left+"px";
				lay.style.top = top+"px";
			}
			
function surveypopUp() {
		window.surveyTimer = setTimeout("checkSurveyCookie()", 1000);	
		document.write('		<div id="surveypop" style="display:none;position:absolute;background:#FFFFFF;z-index:1000;">');
		document.write('			<table width="670" border="0" cellpadding="0" cellspacing="0" bgcolor="#FE0000">');
		document.write('				<tr> ');
		document.write('					<td colspan="2">');
		document.write('						<table width="100%" cellspacing="0" style="border: 8px solid #606060 ; background-color: #000000 ; padding: 16px 16px 16px 16px ;">');
		document.write('							<tr>');
		document.write('								<td style="padding: 10px 10px 10px 10px ; color : #ffffff ;  font-family : Verdana, Geneva, Arial, Helvetica, sans-serif ;  font-size : 12px ;">');
		<!--document.write('								<h2 style="color : #ffffff ; font-size:1.6em; padding-bottom: 6px;">BIMM OPEN DAYS  APRIL 2009</h2>');-->
		<!--document.write('								<p><strong>BIMM</strong> is now taking applications to start in September 2010! Please call the admissions department on 0844 2 646 666 to book an assessment, or email <a href="mailto:info@bimm.co.uk" style="font-weight:bold; color:#f60;">info@bimm.co.uk</a> to request a brochure.</p>');-->
		document.write('									<p><strong>BIMM</strong> is now taking applications to start in September 2010, and is holding open days at both <strong>Brighton</strong> and <strong>Bristol</strong></p>');	
		document.write('							        <h2 style="color:#f60; font-size:1.6em; padding-bottom: 6px;">BIMM OPEN DAYS</h2>');
		document.write('							        <h2 style="color : #ffffff ; font-size:1.6em; padding-bottom: 6px;">BIMM BRISTOL  - Saturday 23rd January 2010</h2>');
		document.write('							        <h2 style="color : #ffffff ; font-size:1.6em; padding-bottom: 6px;">BIMM BRIGHTON - Saturday 30th January 2010</h2>');		
		document.write('							        <p>Call 0844 2 646 666 to book your place* , request a brochure or book  an assessment.</p>');
		document.write('							        <p style="font-weight:bold; color:#f60;">*Places must be booked in advance</p>');
		document.write('							        <h2 style="color : #ffffff ; font-size:1.6em; padding-bottom: 6px;">PLUS! NEW COURSE FOR 2010/11</h2>');
		document.write('							        <p>BIMM Professional Diploma in Acoustic Guitar <br>Available at BIMM Bristol. Please call for details!</p>');
		document.write('									<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="padding: 5px 5px 5px 5px;">');
		document.write('										<tr> ');
		document.write('											<td align="center"><a href="javascript:closeSurveysurveypopUp()" style="font-weight:bold; color : #f60;">Close Window</a></td>');
		document.write('										</tr>');
		document.write('									</table>');
		document.write('								</td>');
		document.write('							</tr>');
		document.write('						</table>');
		document.write('					</td>');
		document.write('				</tr>');
		document.write('			</table>');
		document.write('		</div>');
		positionDiv();

}