// feedback.js
// Byde Heating & Plumbing Ltd

// GLOBAL
var i;

window.onload = initialize; 

// onload
function initialize () {
	if (!W3CDOM) return;

	var obj;	
	var rimg = new Array(1);

	// Common (main.js)
	setCommonElements();

	// Rollovers	
	obj = document.getElementById('hd_showerwater');
	if (obj) {
		rimg['hd_showerwater'] = new RolloverImg(104,104,'/img/hd_showerwater_off.gif','/img/hd_showerwater.gif');	
		obj.onmouseover = function() {this.src = rimg['hd_showerwater'].imgOver.src;}
		obj.onmouseout = function() {this.src = rimg['hd_showerwater'].imgOut.src;}			
	}
	
	// Setup Feedback page...
	// FID defined in feedback.php
	showFB(FID);
}

// OPEN WINDOW WITH IMAGE (funcs.js)
function showImg(Image,Desc,W,H) {
  var t ='';
	var max_height, height_adjust, wtitle;
	
	// Init
	max_height = screen.height - 50;
	height_adjust = 75;	// 95
	wtitle = Desc + ' - Customer Feedback';

  t = '<html><head>';
  t += '<title>' + wtitle + '</title>';
	t += '<meta http-equiv="imagetoolbar" content="no" />';
  t += '<link rel="stylesheet" type="text/css" href="/css/popup.css" />';
  t += '</head>';

  t += '<body>';
  t += '<div>Byde Heating &amp; Plumbing Ltd - Customer Feedback';
	if (Desc > ' ') {t += '<br /><span class="descfont">' + Desc + '</span>';}
	t += '</div>';

	// Clicking on image also closes window
  t += '<a href="javascript:window.close();">';
  t += '<img style="border:1px solid #999999;margin-top:2px;"';
	t += ' src="' + Image + '" width=' + W + ' height=' + H;
	t += ' alt="' + Desc + '" title="' + Desc + '" />';
	t += '</a>';

  t += '<div style="text-align:right;">';
  t += '<a href="javascript:window.close();">Close Window</a>';
  t += '</div>';
	
	/*
  t += '<div class="noprint" style="float:right;padding:5px;">';
  t += '<INPUT STYLE="width:80px;" TYPE="button" VALUE="Print" onClick="javascript:window.print();"> ';
  t += '<INPUT STYLE="width:80px;" TYPE="button" VALUE="Close" onClick="javascript:window.close();">';
	t += '</div>';
	*/

  t += '</body></html>';

  // ADJUST FOR WINDOW WIDTH/HEIGHT
  if (W < 700) {
    W += 40;
    if (W < 300) {
      W = 300
    }
  } else {
    W = 740;
  }	

	// 5th Nov 2005 - Allows for different screen resolutions
	// Assigned earlier
  if (H < (max_height - height_adjust)) {
    H += height_adjust;
  } else {
    H = max_height;
  }
	
  var imgwin = window.open('about:blank','imgwin','resizable=yes,scrollbars=yes,width=' + W + ',height=' + H);

  imgwin.document.open();
  imgwin.document.write(t);
  imgwin.document.title = wtitle;
  imgwin.document.close();
}

// Displays the Feedback/Testimonial with 'id' 0..max
function showFB(id) {
	var i, t, obj, f, url, efn, el;
	var minbtn, maxbtn, desc;
	
	// Store id in Cookie... (cookies.js)
	setCookie('fid',id);	
	
	// Const
	var NUMBTN = 10;	// Number of page buttons to show
	var MAXDATA = data.length - 1;
	//var RANGE = 3;

	// Init
	t = '';
	
	// Calc Min and Max Btn Page
	if (id < (NUMBTN / 2)) {
		// Near Start 
		minbtn = 0;
		maxbtn = NUMBTN - 1;
	} else if (id > (MAXDATA - (NUMBTN / 2))) {
		// Near End 
		minbtn = MAXDATA - NUMBTN + 1;
		maxbtn = MAXDATA;
	} else {
		// Somewhere in middle
		minbtn = id - (NUMBTN / 2) + 1;
		maxbtn = minbtn + NUMBTN - 1;
	}
	
	// CONTROL BAR...
	// Previous Btn
	//t = '<form action="javascript:;">';
	t += '<input style="width:50px;" type="button" value="&lt; Prev" ';
	if (id == 0) {
		t += 'disabled="disabled" ';
	} else {
		t += 'onclick="javascript:showFB(' + (id - 1) + ');" ';
	}
	t += ' />';
	
	// Pages Btns...
	for(i=minbtn; i <= maxbtn; i++) {
		if (i == id) {
//			t += '<span style="width:20px;font-weight:bold;text-align:center;border:1px solid #666666;background-color:#ffffff" ';
//			t += 'class="smallfont">' + (i+1) + '</span>';
			t += '<input style="width:25px;font-weight:bold;" type="button" value="' + (i+1) + '" ';
			t += 'disabled="disabled" />';
		} else {
			t += '<input style="width:25px;" type="button" value="' + (i+1) + '" ';
			t += 'onclick="javascript:showFB(' + i + ');" />';			
		}	
	}

	// Next Btn
	t += '<input style="width:50px;" type="button" value="Next &gt;" ';
	if (id == (data.length - 1)) {
		t += 'disabled="disabled" ';
	} else {
		t += 'onclick="javascript:showFB(' + (Number(id) + 1) + ');" ';
	}
	t += ' />';
	//t += '</form>';
	
	// Write to 'fb_ctrl' div
	obj = document.getElementById('fb_ctrl');
	if (obj) {obj.innerHTML = t;}
	
	// Read data and split into fields
	f = data[id].split('|');
	
	// DESCRIPTION...
	// Write to 'fb_desc' div
	desc = f[6] + ' <span style="font-weight:normal;color:#999999;">(' + (Number(id) + 1) + '/' + (MAXDATA+1) + ')</span>';
	obj = document.getElementById('fb_desc');
	if (obj) {obj.innerHTML = desc;}
	
	// ENLARGED VERSION?
	t = '';
	if (f[3] == 'e') {
		efn = f[0].substring(0,f[0].length-4) + '_e' + f[0].substring(f[0].length-4); 
		el = '<a href="/fb/' + efn + '" onclick="javascript:showImg(\'/fb/' + efn + '\',\'' + f[6] + '\',' + f[4] + ',' + f[5] + ');return false;">';
		//t = el + '<img style="position:relative;top:2px;margin-right:5px;" src="/img/viewlarger.gif" width="13" height="13" alt="Enlarge" border="0" />Click here or on the letter above to enlarge it.</a>';
		t = el + '<img src="/img/clickanywhere_anim.gif" width="319" height="44" border="0" alt="Click anywhere on the letter to enlarge it" title="Click anywhere on the letter to enlarge it" /></a>';	
	}
	
	// Write to 'fb_enlarge' div
	obj = document.getElementById('fb_enlarge');
	if (obj) {obj.innerHTML = t;}
	
	// LETTER (img)...
	t = '<div style="position:absolute;left:4px;top:4px;width:' + f[1] + 'px;height:' + f[2] + 'px;background-color:#cccccc;"></div>';
	if (f[3] == 'e') {t += el;}
	t += '<img style="position:absolute;left:0px;top:0px;" src="/fb/' + f[0] + '" width="' + f[1] + '" height="' + f[2];
	t += '" alt="Letter from ' + f[6] + '" title="Letter from ' + f[6] + '" border="0" />';
	if (f[3] == 'e') {t += '</a>';}	 
	
	// Write to 'fb_letter' div
	obj = document.getElementById('fb_letter');
	if (obj) {obj.innerHTML = t;}

	// URL...
	url = 'http://' + window.location.hostname + '/feedback.php?id=' + (Number(id) + 1);
	t = '<img style="position:relative;top:-1px;margin-right:3px;" src="/img/dots_anim.gif" width="5" height="5" alt="Bullet" /><a href="' + url + '" title="Permanent link to this page... ' + url + '">Permalink</a>';
	
	// Write to 'fb_url' div
	obj = document.getElementById('fb_url');
	if (obj) {obj.innerHTML = t;}
}

// Data
var data = new Array();

i = 0;
// Filename|Width|Height|Enlarged Version?(e/-)|EWidth|EHeight|Description
data[i++] = "fb_weavers.gif|355|263|-|0|0|Weavers Cottage, Berkshire.|?";
data[i++] = "fb_twilliamson.jpg|362|348|e|550|538|Mr T.Williamson, Maidenhead, Berkshire|8/1/2004";
data[i++] = "fb_mckay.gif|362|348|e|564|540|Mr &amp; Mrs Mckay, Charvil, Berkshire|11/2/2002";
data[i++] = "fb_jhall.jpg|362|348|e|573|540|Mrs J Hall, Gosport, Hants|23/9/2003";
data[i++] = "fb_pg.jpg|252|348|e|400|553|Peter from Sonning, Berkshire|13/1/2003";
data[i++] = "fb_wkdougan.gif|362|348|e|558|540|Mr W Dougan, Caversham Park, Reading|17/5/2002";
data[i++] = "fb_dwrigley.gif|362|348|e|610|540|Mr D Wrigley, Caversham Park Village, Reading|24/12/2002";
data[i++] = "fb_cvass.jpg|298|348|e|463|540|Mr &amp; Mrs Vass, Twyford, Reading|4/2/2002";
data[i++] = "fb_cwills.jpg|362|338|e|579|540|Mrs C Wills, Twyford, Berkshire|21/7/2002";
data[i++] = "fb_jbrisden.gif|332|348|e|516|540|Mrs J Brisden, Maidenhead, Berkshire|10/12/2002";
data[i++] = "fb_nicholls.jpg|362|177|e|620|302|Mrs &amp; Mrs Nicholls, Charvil, Berkshire|9/4/2003";
data[i++] = "fb_twilliamson_2nd.jpg|362|242|e|620|415|Mr T.Williamson, Maidenhead, Berkshire|11/3/2004";
data[i++] = "fb_dixon.gif|362|348|e|546|540|Mr Dixon, Reading, Berkshire|6/7/2004";
data[i++] = "fb_mrsh.jpg|327|348|e|508|540|Mrs H, Twyford, Berkshire|?";
data[i++] = "fb_pawsey.jpg|337|348|e|522|540|Mr J Pawsey, Maidenhead, Berkshire|14/10/2005";
data[i++] = "fb_karenian.jpg|263|348|e|409|540|Karen &amp; Ian, Wargrave, Berkshire|30/12/2002";
data[i++] = "fb_mhall.jpg|303|348|-|0|0|Mrs Hall, Charvil, Berkshire|6/6/2005";
