$(document).ready(function() {
  
  // hides the slickbox as soon as the DOM is ready (a little sooner that page load)
  // $('#slickbox').hide();

  var http_host_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");


  if(readCookie('nccmenuhide')){
	$('#slickbox').hide();
	$('#slick-slidetoggle').html("<span>Show Main Menu</span>")
	$('#slick-slidetoggle').css({'background-image': 'url(\''+http_host_protocol+'www.newcastle.gov.uk/2010/if/showsitemap-trans.png\')'});
	
  }else{
	$('#slick-slidetoggle').html("<span>Hide Main Menu</span>")
	$('#slick-slidetoggle').css({'background-image': 'url(\''+http_host_protocol+'www.newcastle.gov.uk/2010/if/hidesitemap-trans.png\')'});  
  }
  // shows and hides and toggles the slickbox on click  
  $('#slick-show').click(function() {
    $('#slickbox').show('fast');
    return false;
  });
  $('#slick-hide').click(function() {
    $('#slickbox').hide('fast');
    return false;
  });
  $('#slick-toggle').click(function() {
    $('#slickbox').toggle(400);
    return false;
  });

 // slides down, up, and toggle the slickbox on click    
  $('#slick-down').click(function() {
    $('#slickbox').slideDown('fast');
    return false;
  });
  $('#slick-up').click(function() {
    $('#slickbox').slideUp('fast');
	var str = $('#slick-slidetoggle').text();
	if (str == "Show Main Menu")
		{
			$('#slick-slidetoggle').html("<span>Hide Main Menu</span>")
			$('#slick-slidetoggle').css({'background-image': 'url(\''+http_host_protocol+'www.newcastle.gov.uk/2010/if/hidesitemap-trans.png\')'});
			eraseCookie('nccmenuhide');
		}
	else
		{
			$('#slick-slidetoggle').html("<span>Show Main Menu</span>")
			$('#slick-slidetoggle').css({'background-image': 'url(\''+http_host_protocol+'www.newcastle.gov.uk/2010/if/showsitemap-trans.png\')'});
			createCookie('nccmenuhide','1','');	

		}
    return false;
  });
  $('#slick-slidetoggle').click(function() {
    $('#slickbox').slideToggle(400);
	var str = $('#slick-slidetoggle').text();
	if (str == "Show Main Menu")
		{
			$('#slick-slidetoggle').html("<span>Hide Main Menu</span>")
			$('#slick-slidetoggle').css({'background-image': 'url(\''+http_host_protocol+'www.newcastle.gov.uk/2010/if/hidesitemap-trans.png\')'});
			eraseCookie('nccmenuhide');
		}
	else
		{
			$('#slick-slidetoggle').html("<span>Show Main Menu</span>")
			$('#slick-slidetoggle').css({'background-image': 'url(\''+http_host_protocol+'www.newcastle.gov.uk/2010/if/showsitemap-trans.png\')'});
			createCookie('nccmenuhide','1','');			

		}
    return false;
  });
});

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	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 eraseCookie(name) {
	createCookie(name,"",-1);
}

function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

function launchMemo() {

	if (document.memo.TandC_Check.checked) {
		openNemo();
	} else {
		alert("You must accept the License agreement Terms and Conditions before continuing.")
	}
}

function openNemo(call_type) {
  var wid;
  var hgt;
    if(navigator.appName == "Netscape"){

    wid = window.screen.availWidth;
 	hgt = window.screen.availHeight;
 	browsertype = "ns"

    }else if(navigator.appName == "Microsoft Internet Explorer"){

    wid = window.screen.availWidth;
    hgt = window.screen.availHeight;
    browsertype = "ie"

    }else{

    wid = 1024;
	hgt = 623;
	browsertype = "ns"

  	}
  	if(wid>1280){
  	wid = 1280;
  	}
  	if (wid<800){
  	wid = 800;
  	}
  	if (wid>801 && wid <1024){
  	wid = 1024;
  	}
  	if (wid>1025 && wid <1151){
  	wid = 1152;
  	}
  	if (wid>1153 && wid <1279){
  	wid = 1280;
  	}

	var winwid = wid * 0.98;
	var winhgt = hgt * 0.95;

	Stamp = new Date();
	var Hours;
	var Mins;
	var Secs;
	var Time;
	Hours = Stamp.getHours();
 	Mins = Stamp.getMinutes();
 	Secs = Stamp.getSeconds();
 	Time = Hours + Mins + Secs;
 	
	var winwid = wid + 8;
	var winhgt = hgt + 8;
	window.moveTo(-4, -4);
	window.resizeTo(winwid, winhgt);
	
if (call_type=="NNIS")
	{
	//window.open("http://gis.newcastle.gov.uk/nemow3c/Map.asp?wid=" + wid + "&amp;browsertype=" + browsertype + "&amp;WinHeight=" + hgt + "&amp;Wheight=" + winhgt + "&amp;Wwidth=" + winwid  + "&amp;nnisvitality=true&amp;SCI=true&amp;CGD=true&amp;nnis=Vitality - Ranked Position_04","Nemo" + Time + "Map","height=" + winhgt + ",width=" + winwid + ",scrollbars=no,status=yes,toolbar=no,menubar=no,location=no,resizable=no,top=0,left=0");
	window.location = "http://gis.newcastle.gov.uk/mapsonline/map.asp?wid=" + wid + "&browsertype=" + browsertype + "&ID=100004" + "&amp;nnis=Vitality - Ranked Position_04";
	} else 
	{
  	//window.open("http://gis.newcastle.gov.uk/nemow3c/map.asp?wid=" + wid + "&amp;browsertype=" + browsertype + "&amp;WinHeight=" + hgt + "&amp;Wheight=" + winhgt + "&amp;Wwidth=" + winwid ,"Nemo" + Time + "Map","height=" + winhgt + ",width=" + winwid + ",scrollbars=no,status=yes,toolbar=no,menubar=no,location=no,resizable=no,top=0,left=0");
  	window.location = "http://gis.newcastle.gov.uk/mapsonline/map.asp?wid=" + wid + "&browsertype=" + browsertype;
	}
}

function launchRoadWorksMap() {

	if (document.memo.TandC_Check.checked) {
		window.open("http://gis.newcastle.gov.uk/iframemap/getmap.html")
	} else {
		alert("You must accept the License agreement Terms and Conditions before continuing.")
	}

}

function launchRecyclingRouteSearch() {

	if (document.forms[0].PostCode.value=="") 
	{
		alert("Please enter a Post Code");
		document.forms[0].PostCode.focus();
		return false;
	}
	
	if (document.forms[0].HouseNumber.value=="") 
	{
		alert("Please enter a House Number");
		document.forms[0].HouseNumber.focus();
		return false;
	}
	
	window.location="/wsapp.nsf/soapweb/RecyclingRoutes?opendocument=1&ct=RecyclingRoutes&PC=" + document.forms[0].PostCode.value + "&HN=" + document.forms[0].HouseNumber.value;

}

function launchparkingmap() {

	if (document.memo.TandC_Check.checked) {
		openParking();
	} else {
		alert("You must accept the License agreement Terms and Conditions before continuing.")
	}

}

function launchGambleViewer() {

	if (document.memo.TandC_Check.checked) {
		window.location.href="http://gis.newcastle.gov.uk/olga/"
	} else {
		alert("You must accept the License agreement Terms and Conditions before continuing.")
	}

}

function launchLicViewer() {

	if (document.forms[0].TandC_Check.checked) {
		window.location.href="http://gis.newcastle.gov.uk/Licensing/home.aspx"
	} else {
		alert("You must accept the License agreement Terms and Conditions before continuing.")
	}

}

function openParking() {
  var wid;
  var hgt;
    if(navigator.appName == "Netscape"){

    wid = window.screen.availWidth;
 	hgt = window.screen.availHeight;
 	browsertype = "ns"

    }else if(navigator.appName == "Microsoft Internet Explorer"){

    wid = window.screen.availWidth;
    hgt = window.screen.availHeight;
    browsertype = "ie"

    }else{

    wid = 1024;
	hgt = 623;
	browsertype = "ns"

  	}
  	if(wid>1280){
  	wid = 1280;
  	}
  	if (wid<800){
  	wid = 800;
  	}
  	if (wid>801 && wid <1024){
  	wid = 1024;
  	}
  	if (wid>1025 && wid <1151){
  	wid = 1152;
  	}
  	if (wid>1153 && wid <1279){
  	wid = 1280;
  	}

	var winwid = wid * 0.98;
	var winhgt = hgt * 0.95;

	Stamp = new Date();
	var Hours;
	var Mins;
	var Secs;
	var Time;
	Hours = Stamp.getHours();
 	Mins = Stamp.getMinutes();
 	Secs = Stamp.getSeconds();
 	Time = Hours + Mins + Secs;
 	
	var winwid = wid + 8;
	var winhgt = hgt + 8;
	window.moveTo(-4, -4);
	window.resizeTo(winwid, winhgt);
	
	window.location = "http://gis.newcastle.gov.uk/ray_map/ray_map.asp?wid=" + wid + "&browsertype=" + browsertype;

  }
  
  function launchLibNemo(library) {
  
    var wid;
    var hgt;
      if(navigator.appName == "Netscape"){
  
      wid = window.screen.availWidth;
   	hgt = window.screen.availHeight;
   	browsertype = "ns"
  
      }else if(navigator.appName == "Microsoft Internet Explorer"){
  
      wid = window.screen.availWidth;
      hgt = window.screen.availHeight;
      browsertype = "ie"
  
      }else{
  
      wid = 1024;
  	hgt = 623;
  	browsertype = "ns"
  
    	}
    	if(wid>1280){
    	wid = 1280;
    	}
    	if (wid<800){
    	wid = 800;
    	}
    	if (wid>801 && wid <1024){
    	wid = 1024;
    	}
    	if (wid>1025 && wid <1151){
    	wid = 1152;
    	}
    	if (wid>1153 && wid <1279){
    	wid = 1280;
    	}
  
  	var winwid = wid * 0.98;
  	var winhgt = hgt * 0.95;
  
  	Stamp = new Date();
  	var Hours;
  	var Mins;
  	var Secs;
  	var Time;
  	Hours = Stamp.getHours();
   	Mins = Stamp.getMinutes();
   	Secs = Stamp.getSeconds();
   	Time = Hours + Mins + Secs;
   	
  	var winwid = wid + 8;
  	var winhgt = hgt + 8;
  	window.moveTo(-4, -4);
  	window.resizeTo(winwid, winhgt);
  	
  window.location = "http://gis.newcastle.gov.uk/mapsonline/map.asp?wid=" + wid + "&browsertype=" + browsertype + "&ZTL=true&Lib_Name=" + library;
  
}

function launchNNIS() {

	if (document.nemonnis.TandC_Check.checked) {
		openNemo("NNIS");	
	} else {
		alert("You must accept the License agreement Terms and Conditions before continuing.")
	}

}

function validatebsifrm(){

	var x = document.forms[2].txtLibNo.value;
	
	var xarray = x.split("");
	var chk="false";
	var len=x.length;

	if(len<11 && len>8){
		for (i=0;i<len;i++){
				if(xarray[0]=="D" || xarray[0]=="d")	{chk="OK";}else{chk="false"; break;}
				if(i>0){
					if(xarray[i]=="0" || xarray[i]=="1" || xarray[i]=="2" || xarray[i]=="3" || xarray[i]=="4" || xarray[i]=="5" || xarray[i]=="6" || xarray[i]=="7" || xarray[i]=="8" || xarray[i]=="9")
					{chk="OK";}else{chk="false"; break;}
				}
		}

	} else if(len==8) {
			for (i=0;i<len;i++){
					if(xarray[i]=="0" || xarray[i]=="1" || xarray[i]=="2" || xarray[i]=="3" || xarray[i]=="4" || xarray[i]=="5" || xarray[i]=="6" || xarray[i]=="7" || xarray[i]=="8" || xarray[i]=="9")
					{chk="OK";}else{chk="false"; break;}
		}
	}

	if(chk=="OK"){
	window.location="/apps002.nsf/bsigoto?openform";
	//document.forms[0].submit();
	}else{
	alert("Invalid Library Card Number. Please try again.");
	}

}

function launchPlanningv2() {
	if (document.planning.TandC_Check.checked) {
		window.location.href="http://planningapplications.newcastle.gov.uk/online-applications";
	} else {
		alert("You must accept the License agreement Terms and Conditions before continuing.")
	}
}
