// You must keep these lines on when you copy the source
// ©2001 Mike Parker - http://www.patchworkgallery.co.uk

function check_context(req_url){
	var url = new RegExp(req_url+"$", "i");
	if (url.test(window.parent.location) != true && window.location.search != "?debug=true") {
		window.location = req_url;
	}
}

function scaled_page_heading(name,alt,height_large,width_large,height_small,width_small){
	if (window.screen.width < 1024 || window.screen.height < 768){
		var res = '800x600/';
		var height = height_small;
		var width = width_small;
	} else {
		var res = '1024x768/';
		var height = height_large;
		var width = width_large;
	}
	document.write('<IMG align=centre alt="'+alt+'" border=0 height='+height+' name="'+alt+'" src="images/'+res+name+'" width='+width+'>');
}

function scaled_menu_button(name,alt){
	if (window.screen.width < 1024 || window.screen.height < 768){
		var h = 29;
		var w = 87;
		var dir = '800x600/';
	} else {
		var h = 37;
		var w = 111;
		var dir = '1024x768/';
	}
	document.write('<IMG alt="'+alt+'" border=0 height='+h+' name="'+alt+'" src="menu/'+dir+name+'" width='+w+'></td>');
}

function scaled_image(name,x,y){
	if (window.screen.width < 1024 || window.screen.height < 768){
		var scale_factor = 768/600;
	} else {
		var scale_factor = 1;
	}
	var thumb_path = "photos/thumbs/"+name.replace(/\.\w{3}$/,"")+".jpg";
	if (name.indexOf(".pff") == -1) {
		name = "photos/"+name;
	}
	document.writeln("<a href=\"javascript:display_image('"+name+"',"+Math.round(x/scale_factor)+","+Math.round(y/scale_factor)+")\">");
	document.writeln('<img src="'+thumb_path+'" border="0" width="'+Math.round(((169/y)*x)/scale_factor)+'" height="'+Math.round(169/scale_factor)+'"></a>');
}

function select_css(a){
	if (window.screen.width < 1024 || window.screen.height < 768){
		document.writeln('<link rel="STYLESHEET" href="'+a+'800x600.css" type="text/css">');
	} else {
		document.writeln('<link rel="STYLESHEET" href="'+a+'1024x768.css" type="text/css">');
	}
}

function preload(img_array) {
  	var ar = new Array();
  	var arguments = img_array;
  	for (var i = 0; i < arguments.length; i++) {
    		ar[i] = new Image();
    		ar[i].src = arguments[i];
  	}
}

function adjust_navigator_fonts_open(){
	if(((navigator.userAgent.indexOf("SunOS") != -1) || (navigator.userAgent.indexOf("Linux") != -1)) && (navigator.appName == "Netscape")){
		document.writeln('<center><font size="1"  face="Arial, Helvetica, sans-serif">');
	} else {
		if(navigator.appName == "Netscape"){
			var fontsize = 8;
			var lineheight = 9;
		} else {
			var fontsize = 7;
			var lineheight = 8;
		}
		document.writeln('<h3 style="font-size: '+fontsize+'pt; line-height: '+lineheight+'pt">');
	}
}

function adjust_navigator_fonts_close(){
	if(((navigator.userAgent.indexOf("SunOS") != -1) || (navigator.userAgent.indexOf("Linux") != -1)) && (navigator.appName == "Netscape")){
                		document.writeln('</font></center>');
        	} else {
		document.writeln('</H3>');
        	}
}

function show_quest(new_visitor_flag,ref_page,page_path){
	if (new_visitor_flag == "new") {
		if(navigator.appName == "Netscape"){
			if (navigator.platform.match(/SunOS/)){
				var ysize=649;
			} else {
				var ysize=555;
			}
		} else {
				var ysize=525;
		}
		newwin=open(page_path+"pgquest.htm","dispwin","toolbar=no,directories=no,menubar=no,status=no,resizable=no,scrollbars=no,width=550,height="+ysize);
		newwin.ref = ref_page;
		newwin.document.close();
	} else return;
}

function check_cookie(){
	var visit=GetCookie("PGCOOKIE2");
	if (visit==null){
		var expire=new Date();
		flag = "new";
		ref = document.referrer;
		document.cookie="PGCOOKIE2=here; expires=Tue 01-01-2004 00:00:00 GMT;";
	}
}

function GetCookie(name) {
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i,j)==arg)
		return "here";
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}		
	return null;
}

function warn_screenres(){
	var warn = "";;
	var colerr = (window.screen.colorDepth < 16);
	var winerr = (window.screen.width < 1024 || window.screen.height < 768);
	if (colerr || winerr){
		if (colerr){
			warn += "The colour depth of your display is currently set to less  than 16bpp (bits per pixel). To maximise the quality of the photographic images contained within this site, it is recommended that you change the colour depth of your display to 16bpp or greater."; 
			if (colerr && winerr) {
				warn +="\n\nAlso, the ";
			} else {
				alert(warn);
				return;
			}
		}
		if (winerr){
			if (winerr && !colerr){
				warn += "The ";
			}
			warn += "resolution of your display is currently set to less than 1024 x 768 pixels. To permit the contents of all windows and frames to be viewable, it is recommended that you set your screen resolution to be 1024 x 768 pixels or greater.";
		}
		alert(warn);
	}
}
		

function display_image(name,x,y){
	if (navigator.appName == "Netscape"){
		var xsize = ysize = 0;
		var xmod = 21;
		var ymod = 64;
		if(typeof imageWin == "object" && typeof imageWin.window == "object"){
			var xpos = imageWin.screenX;
			var ypos = imageWin.screenY;
			imageWin.close();
		}
	} else {
		var xsize = x+31;
		var ysize = y+95;
		var xmod = 22;
		var ymod = 67;
	}
	if(typeof xpos == "undefined"){
		var xpos = ypos = 0;
	}
	var zoomify_doc = "";
	if (name.indexOf(".pff") != -1) {
		var zoomify_doc = "photos/zoomify/zoomdisp.htm?img_name="+name+";xsize="+x+";ysize="+y;
	}
	imageWin =open(zoomify_doc,"ImageDispWindow","height="+(y+ymod)+",width="+(x+xmod)+"menubar=no,left="+xpos+",top="+ypos);
	
	// Netscape bug - resizeTo tries to resize window to 0,0 - remedy by treating same as IE?
	
	imageWin.resizeTo(xsize,ysize);
	if (name.indexOf("pff") == -1) {
		var astr = "<html><head><title>The Patchwork Gallery Photo Archive</title>";
		astr += "</head><"+"script language=javascript>function click() {if (event.button==2) {";
		astr += "alert('The right mouse button is unavailable within this window');}}";
		astr += "document.onmousedown=click</"+"script><body bgColor=#000000 ";
		astr += "link=#FFFFFF alink=#FFFFFF vlink=#FFFFFF topmargin=8 leftmargin=8 rightmargin=8 ";
		astr += "bottommargin=8><table align=center border=1 cellpadding=0 ";
		astr += 'cellspacing=0><tr><td><img src="'+name+'" width='+x+' height='+y+'>';
		astr += '</td></tr></table><p align=center><a href="javascript:window.close()">';
		astr += '<font size=2 face="Arial,Helvetica,sans-serif">';
		astr += "<b>[close window]</b></font></a></p></body></html>"
		var doc = imageWin.document;
		doc.write(astr);
		doc.close();
	}
	imageWin.focus();
}
function validate(form) {
	form.referrer.value = window.ref;
	form.platform.value = navigator.appName+" "+navigator.appVersion+" ("+window.screen.width+" x "+window.screen.height+")";
	var res = form.country.options[form.country.selectedIndex].value;
	var oft = form.how_often.options[form.how_often.selectedIndex].value;
	var fnd = form.how_found.options[form.how_found.selectedIndex].value;
	var eng = form.search_engine.options[form.search_engine.selectedIndex].value;
	var prs = form.presentation.options[form.presentation.selectedIndex].value;
	var intrst = form.interests.selectedIndex;
	var cmt = form.comments.value;
	var inf = cat = shop = fseng = false;
	var start = "Please indicate ";
	var end = " before re-submitting this questionnaire.";
	for (i = 0; i < form.find_info.length; i++) {
		var inf = inf || form.find_info[i].checked;
	 }
	for (i = 0; i < form.catalogue.length; i++) {
		var cat = cat || form.catalogue[i].checked; 
	}
	for (i = 0; i < form.buy_online.length; i++) {
		var shop = shop || form.buy_online[i].checked;
	 }
	for (i = 0; i < form.fabric_search.length; i++) {
		var fseng = fseng || form.fabric_search[i].checked; 
	}
	if (fnd && (fnd != "Search engine")) {
		form.search_engine.selectedIndex = 0;
	}
	if (!res) {
		form.country.selectedIndex = 0;
		alert(start+"where you are presently resident"+end);
		return false;
	}
	else if (!oft) {
		alert(start+"how often you visit the Patchwork Gallery website"+end); 
		return false;
	}
	else if(!fnd) {
		alert(start+"how you first found our site"+end);
		return false;
	}
	else if((fnd == "Search engine") && !eng) {
		alert(start+"which search engine you used to find our site"+end);
		return false;
	}
	else if(!prs) {
		alert(start+"how you rate the presentation of our site"+end);
		return false;
	}
	else if(!inf) {
		alert(start+"whether you regularly find the information/product you're looking for"+end);
		return false;
	}
	else if(!shop) {
		alert(start+"whether you would buy online if we offered a secure shopping service"+end);
		return false;
	}
	else if(!cat) {
		alert(start+"whether you have looked at our online catalogue"+end);
		return false;
	}
	else if(!fseng) {
		alert(start+"whether you have used our online fabric search engine"+end);
		return false;
	}
	else if(intrst == -1) {
		alert(start+"which of the listed topics interest you"+end);
		return false;
	}
	else if((prs == "Poor" || prs == "Very poor") && !cmt){
		alert('Please comment on why you have rated the presentation of our site as "Poor" or "Very poor"'+end);
		return false;
	}
	return true;
}
function di(id,name){
	if (document.images) {
		homed2homeb = new Object(); 
		homed2homeb.src ='homeb.gif';
		homeb2homed = new Object();
		homeb2homed.src ='homed.gif';
		historyd2historyb = new Object(); 
		historyd2historyb.src ='historyb.gif';
		historyb2historyd = new Object();
		historyb2historyd.src ='historyd.gif';
		productd2productb = new Object(); 
		productd2productb.src ='prodb.gif';
		productb2productd = new Object();
		productb2productd.src ='prodd.gif';
		fabricsd2fabricsb = new Object(); 
		fabricsd2fabricsb.src ='fabricsb.gif';
		fabricsb2fabricsd = new Object();
		fabricsb2fabricsd.src ='fabricsd.gif';
		photosd2photosb = new Object(); 
		photosd2photosb.src ='photosb.gif';
		photosb2photosd = new Object();
		photosb2photosd.src ='photosd.gif';
		eventsd2eventsb = new Object(); 
		eventsd2eventsb.src ='eventsb.gif';
		eventsb2eventsd = new Object();
		eventsb2eventsd.src ='eventsd.gif';
		olinksd2olinksb = new Object(); 
		olinksd2olinksb.src ='linksb.gif';
		olinksb2olinksd = new Object();
		olinksb2olinksd.src ='linksd.gif';
		directd2directb = new Object(); 
		directd2directb.src ='directb.gif';
		directb2directd = new Object();
		directb2directd.src ='directd.gif';
		contusd2contusb = new Object(); 
		contusd2contusb.src ='contusb.gif';
		contusb2contusd = new Object();
		contusb2contusd.src ='contusd.gif';
		if (window.screen.width < 1024 || window.screen.height < 768){
			var a = 'menu/800x600/'+eval(name+'.src');
		} else {
			var a = 'menu/1024x768/'+eval(name+'.src');
		}
		document.images[id].src = a;
	}
}

