//COOKIE CONTROL>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>STARTS

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
function setExpire(DURATION){//EG <a href="#" onclick="setCookie('brochureRequested','yes',setExpire(365 * 24 * 60 * 60 * 1000))">setcookie yes</a>
	var now = new Date();
    fixDate(now);//calls fixDate which seems to be needed to fix netscape bug
    now.setTime(now.getTime() + DURATION);//1 yr  365 * 24 * 60 * 60 * 1000
//	alert(now.toGMTString()); //myDEbug
	return now;
}
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

//COOKIE CONTROL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ENDS


//WINDOW OPEN NO FRAMES or iFRAMES>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>STARTS
function windopen(URLorOTHER,LEFT,TOP,WIDTH,HEIGHT,TYPE){
	switch (TYPE){
		case "info"://everything off
			windoptions='status=no,toolbar=no,menu=no,scrollbars=no,resizable=no,';
			break;
		case "infoscroll"://everything off except scroll
			windoptions='status=no,toolbar=no,menu=no,scrollbars=yes,resizable=no,';
			break;
		case "scrollresize":
			windoptions='status=no,toolbar=no,menu=no,scrollbars=yes,resizable=yes,';
			break;
		case "statusresize":
			windoptions='status=no,toolbar=no,menu=no,scrollbars=no,resizable=yes,';
			break;
		case "statusresizelocation":
			windoptions='status=no,location=yes,toolbar=no,menu=no,scrollbars=no,resizable=yes,';
			break;
		case "statuscrollresize":
			windoptions='status=yes,toolbar=no,menu=no,scrollbars=yes,resizable=yes,';
			break;
		case "statuscrollresizelocation":
			windoptions='status=yes,location=yes,toolbar=no,menu=no,scrollbars=yes,resizable=yes,';
			break;
		case "resizeonly":
			windoptions='status=no,toolbar=no,menu=no,scrollbars=no,resizable=yes,';
			break;
		case "noscroll":
			windoptions='status=yes,toolbar=yes,menu=yes,scrollbars=no,resizable=yes,';
			break;
		case "noscrollnoresize":
			windoptions='status=yes,toolbar=yes,menu=yes,scrollbars=no,resizable=no,';
			break;
		case "scrollnoresize":
			windoptions='status=yes,toolbar=yes,menu=yes,scrollbars=yes,resizable=no,';
			break;
		default:
			windoptions='status=yes,toolbar=yes,menu=yes,scrollbars=yes,resizable=yes,';
	}

	//centre in window SWITCH -take left and top match right and bottom and centre in window
	if(WIDTH==1000){
		WIDTH=screen.width-(LEFT);//AMENDED WAS just -50
		LEFT=LEFT/2;
	}
	
	if(HEIGHT==1000){
		HEIGHT=screen.height-(TOP);//AMENDED WAS JUST -100
		TOP=TOP/2;
	}

	//centre in window SWITCH - specific width and height
	if(LEFT==1000){
		LEFT=(screen.width-20-WIDTH)/2;//AMENDED WAS just -50
		alert(LEFT);
	}
	
	if(TOP==1000){
		TOP=(screen.height-20-HEIGHT)/2;//AMENDED WAS JUST -100
	}

	//FULLSCREEN SWITCH
	if(WIDTH==0){
		WIDTH=screen.width-50-LEFT;//AMENDED WAS just -50
	}
	
	if(HEIGHT==0){
		HEIGHT=screen.height-100-TOP;//AMENDED WAS JUST -100
	}


	windowprops = "left="+(LEFT)+",top="+(TOP)+","+(windoptions)+"width=" + (WIDTH) + ",height=" + (HEIGHT);

	switch(URLorOTHER){
	case"ON_FLY"://GENERATE ON FLY
			popwindow = window.open("", "popwindow", windowprops);
			popwindow.document.open();
			popwindow.document.write(doOnFlyText);//text created elsewhere. doOnFlyText is var which is passed on thus:
			//										 javascript: var doOnFlyText=doGeneralInfo();               windopen('ON_FLY',20,10,500,350,'infoscroll');
			//																		^ generate the html in a js     ^and then it is used in this js here
			popwindow.document.close();
			break;
	case "":	//not implemented at present but could be used for EG one line of text etc
			alert("Debug Error"+URLorOTHER);// DEBUG ONLY similar to above
			popwindow = window.open("", "popwindow", windowprops);
			popwindow.document.open();
			popwindow.document.write("Hello world");//text
			popwindow.document.close();
			break;
	default://actual www URL - OPEN URL IN WINDOW
		popwindow = window.open(URLorOTHER, "popwindow", windowprops);
	}
}
//WINDOW OPEN NO FRAMES or iFRAMES<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ENDS


//OTHER WINDOW FUNCTIONS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>STARTS
function repos_resizefull(){
self.moveTo(10,0);
self.resizeTo(screen.width-30, screen.height-70);
}


//OTHER WINDOW FUNCTIONS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>STARTS
function repos_resize720x530p(){
self.moveTo(20,10);
self.resizeTo(720, 530);
}

function refresh()
{
    window.location.reload( false );
}
//OTHER WINDOW FUNCTIONS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ENDS


//LOCATION used for emailaddress<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<STARTS
function getLocation(){
	var path = "";
	var href = document.location.href;
	var s = href.split("/"); 
	for (var i=3;i<(s.length-1);i++) {//WAS 2
		path+="<A HREF=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"/\">"+s[i]+"</A>"+">"; // last char inside quote was space/space NOW > with no spaces
	}
	var navurl = path;// REMOVEDwindow.location.protocol + "//" + 
	i=s.length-1;
	var urhere=s[i];// new bit
	path+="<A HREF=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"\">"+s[i]+"</A>";//complete path his line retained
	//realurl = window.location.protocol + "//" + path;
	if(urhere.indexOf('_')>0){//ONLY if page ends _??.html   THIS also strips out security line!!!
		var thePage_array=urhere.split("_");//split genre from ?.html
		var Genre=thePage_array[0];//the bit before the _ in the file name
		var pageNo=thePage_array[1];//correct
		var thePageNo_array=pageNo.split(".");//split ? from html
			pageNo=thePageNo_array[0];//correct
			urhere=Genre+'_'+pageNo;
	}
	else{
		var thePage_array=urhere.split(".");//split genre from ?.html
		var Genre=thePage_array[0];//the bit before the _ in the file name
		urhere=Genre;
	}
	return urhere;
}
//LOCATION used for emailaddress<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ENDS


// Navigation you are here top of page
function doNavline(){
var theCheck='';//?checkvar=12XaQbZ3494nNE3QB3EOiLl10O88868&x=38&y=6
var navFlag=1;
var path = "";
var href = document.location.href;
var s = href.split("/"); 
for (var i=3;i<(s.length-1);i++) {//WAS 2
path+="<A HREF=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"/\">"+s[i]+"</A>"+">"; // last char inside quote was space/space NOW > with no spaces
}
var navurl = path;// REMOVEDwindow.location.protocol + "//" + 
i=s.length-1;
var urhere=s[i];// new bit
path+="<A HREF=\""+href.substring(0,href.indexOf(s[i])+s[i].length)+"\">"+s[i]+"</A>";//complete path his line retained
//realurl = window.location.protocol + "//" + path;
var defhome="<A HREF=\"http://www.definitiveshopping.com/\">HOME</A>";
if(urhere=="index.html"){//process navigation line ending
	urhere="";
	navFlag=1;
}
// SET NUMBER OF PAGES IN EACH SECTION FURTHER DOWN PAGE MARKED BY >> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// PAGE NUMBER NAVIGATION start for bottom of page navigation links 1 2 3 4 etc||||||||||||||||||||||||||||||||||||||||||||||||||||
// PLUS MUCH MORE      ------------------------ AND NEXT THING IS UNDERSCORE ON CURRENT PAGE USING eg A:smi.xxxx				
if(urhere.indexOf('_')>0){//ONLY if page ends _??.html
	var thePage_array=urhere.split("_");//split genre from ?.html
	var theGenre=thePage_array[0];//the bit before the _ in the file name
	var thePageNo=thePage_array[1];//correct
	var thePageNo_array=thePageNo.split(".");//split ? from html
    	thePageNo=thePageNo_array[0];//correct
    var theNoOfPages=0;
	var theNameOfPages="";
	var pageWord="Page ";//default
//	var bottomNavLine=theNameOfPages+" ";" . "//" | "
		navFlag=0;
	switch (theGenre){
		case "debug":
			theNoOfPages=2;//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++SET NUMBER OF DEBUG PAGES HERE
			theNameOfPages="DEBUG";
			break;
		case "intro": 
			theNoOfPages=3;//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++SET NUMBER OF INTRO PAGES HERE
			theNameOfPages="Introduction";
			break;
		case 'about': 
			theNoOfPages=6;//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++SET NUMBER OF INTRO PAGES HERE
			theNameOfPages="About Gilmour Print";
			break;
		case 'testims': 
			theNoOfPages=8;
			theNameOfPages="Client Testimonials";
			break;
		case 'eight': 
			theNoOfPages=8;
			theNameOfPages="Eight Reasons Why . . . Gilmour Print can take the pain out of printing for you<br><br>";
			pageWord="Reason ";
			break;
		case 'samples': 
			theNoOfPages=5;
			theNameOfPages="Some examples of our work";
			break;
		case 'brochure': 
			var formFilled=getCookie('brochureRequested');
			if(formFilled!='yes'){
				theNoOfPages=1;
				}
			else{
				theNoOfPages=2;
				}
			theNameOfPages="A brochure by post";//A brochure by post or online pdf
			break;
		case 'what': 
			theNoOfPages=2;
			theNameOfPages="What's new";
			break;
		case 'contact': 
			theNoOfPages=1;
			theNameOfPages="How to contact us";
			break;
		case 'more': 
			theNoOfPages=1;
			theNameOfPages="Under construction";
			break;
		case 'businesscard': 
			theNoOfPages=2;
			theNameOfPages="Buy business cards online";
			break;
		case 'shop': 
			//not used in shop for now
			theNoOfPages=1;
			theNameOfPages="";
			break;
		case 'ARTinfo': 
			theNoOfPages=5;
			theNameOfPages="Information on artwork";
			theCheck='?checkvar=12XaQbZ3494nNE3QB3EOiLl10O88868&x=38&y=6';//NEEDED in frames when trapping wong access
			break;
		default : 
			navFlag=1;
			alert("Debugging case GenreNotTrapped Navbar");//DEBUG
	}
	var bottomNavLine="<span class=\"likeNorm\">"+theNameOfPages+"</span>";//moved and changed
	var spaceBefore="<span class=\"spacedark\">....</span>";//what you want to put between each
	var thePageNav_array=new Array(theNoOfPages+1);//for bottom of page +1 means that [0] is ignored
	var linkClass;
		for (var i=1; i <= theNoOfPages; i++ ) {
//NEW OUT			thePageNav_array[i]=i.toString();//   
			if(i.toString()==thePageNo){//NEW amended
				linkClass="class=\"linkOver\""; //sets current page to be undersored in nav bar
				}
			else{
				linkClass="class=\"linkNorm\"";//resets
				}																								//theCheck HERE
			bottomNavLine+=spaceBefore+"<a href=\"javascript:self.location='"+theGenre+"_"+i.toString()+".html"+theCheck+"'\""+linkClass+">Page "+i.toString()+"</a>"; 
		}
	//NOW ADD PREVOUS AND NEXT if more than one page
//-	if(theNoOfPages>1){
//-		i=parseInt(thePageNo)-1;// i reused   DO PREVIOUS FIRST----------
//-		if (i==0){
//-			i=theNoOfPages;// ie last page
//-			}
//-		var theEndBits=i.toString();
//-		bottomNavLine="<a href=\"javascript:self.location='"+theGenre+"_"+theEndBits+".html'\"><<< PREVIOUS PAGE</a>"+bottomNavLine;
//-		i=parseInt(thePageNo)+1;// i reused   THEN DO NEXT----------
//-		if (i>theNoOfPages){
//-			i=1;// ie last page
//-			}
//-		theEndBits=i.toString();
//-		linkClass="class=\"linkNorm\"";//off for end bit
//-		bottomNavLine=bottomNavLine+"<a href=\"javascript:self.location='"+theGenre+"_"+theEndBits+".html'\""+linkClass+">NEXT PAGE >>></a>";
//-		}
}
// PAGE NUMBER NAVIGATION end|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(navFlag==0){
	urhere="<font color='201F1F'>YOU ARE HERE: </font>"+defhome+">"+navurl+"<font color='FF7E20'>"+theNameOfPages+" - page "+thePageNo+" of "+theNoOfPages+"</font>";// after defhome was space/space NOW > with no spaces
	}
else
	{
	urhere="<font color='201F1F'>YOU ARE HERE: </font>"+defhome+">"+navurl;
	}
return bottomNavLine;
}	
//End Navigation you are here

//Navigation Check - Did user come from correct page---------------------------------------------
//var locate='';
function doCheck(locate,theGenre){
	var start = locate.indexOf('=')+1;
	var stop = locate.indexOf('&');
	var getCheck = locate.substring(start,stop);
	start = getCheck.indexOf('Z3')+2;
	stop = getCheck.indexOf('NE');
	getCheck = getCheck.substring(start,stop);
	if(getCheck != '494n'){   //goto sitemap
				window.location.href='http://www.ictus.co.uk/404.html';//redirect to correct page
	}
}
//End Navigation Check - Did user come from correct page--------------------------------------------

//START Navigation QuicklinkPopup--------------------------------------------START
function qLink(where){
	if(where!=''){
		window.location=where;
	}
}
//End Navigation QuicklinkPopup--------------------------------------------END

function windAlert(LEFT,TOP,WIDTH,HEIGHT,theMessage){//knock down version of windopen
	var windoptions='status=no,toolbar=no,menu=no,scrollbars=no,resizable=no,';
	var windowprops = "left="+(LEFT)+",top="+(TOP)+","+(windoptions)+"width=" + (WIDTH) + ",height=" + (HEIGHT);
	popwindow = window.open("", "popwindow", windowprops);
	popwindow.document.open();
	popwindow.document.write(theMessage);
	popwindow.document.close();
}

function doPageNum(){
	var pageNum=document.location.href;
	var ref=pageNum.lastIndexOf('_');
	pageNum=pageNum.substring(ref+1);
	ref=pageNum.lastIndexOf('.');
	pageNum=pageNum.substring(0,ref);
	document.write('Page '+pageNum);
}


