﻿// JavaScript Document
// SET Variables
var PORTFOLIO_IMAGE_SET = new Object;
var PORTFOLIO_DETAIL = new Object;
var PORTFOLIO_COLLECTION = new Object;
var RANDOM_TITLE = new Object;
var DATA_READY_FLAG = false;

var thisComments_Filter = true;

// Needs to be replaced by dynamic array from database
var thisWelcomeWord = [];
thisWelcomeWord["UK"] = ["Photography Books"];
thisWelcomeWord["GB"] = ["Photography Books"];
thisWelcomeWord["FR"] = ["Livres de Photographies"];
thisWelcomeWord["DE"] = ["Fotobildb&auml;nde"];
thisWelcomeWord["ES"] = ["Libros de Fotograf&iacute;as"];

var thisTitlesLinkText = [];
/*thisTitlesLinkText["GB"] = ["See<br \/>all our<br \/>titles"];
thisTitlesLinkText["FR"] = ["Voir<br \/>tous nos<br \/>titres"];
thisTitlesLinkText["DE"] = ["Sieh<br \/>unsere<br \/>Titel"];
thisTitlesLinkText["ES"] = ["Ver<br \/>nuestros<br \/>títulos"];*/
thisTitlesLinkText["GB"] = ["New<br \/>Titles"];
thisTitlesLinkText["FR"] = ["Nouveau<br \/>Titres"];
thisTitlesLinkText["DE"] = ["Neue<br \/>Titel"];
thisTitlesLinkText["ES"] = ["Nuevos<br \/>T&iacute;tulos"];

var thisFieldRequiredText = [];
thisFieldRequiredText["GB"] = ["Required"];
thisFieldRequiredText["FR"] = ["Obligatoire"];
thisFieldRequiredText["DE"] = ["Erforderlich"];
thisFieldRequiredText["ES"] = ["Se requiere"];

var thisPurchaseTandC = [];
thisPurchaseTandC["GB"] = ["Terms &amp; Conditions"];
thisPurchaseTandC["FR"] = ["Conditions G&eacute;n&eacute;rales"];
thisPurchaseTandC["DE"] = ["AGB"];
thisPurchaseTandC["ES"] = ["Cl&aacute;usulas y Condiciones"];

var thisLinkSectionText = [];
thisLinkSectionText["GB"]= [];
thisLinkSectionText["GB"][0] = ["Photographers"] ; 
thisLinkSectionText["GB"][1] = ["Book Designers"] ; 
thisLinkSectionText["GB"][2] = ["Post Production Imaging"]; 
thisLinkSectionText["GB"][3] = ["Copywriting & Editing"]; 
thisLinkSectionText["GB"][4] = ["Printers"];
/*thisLinkSectionText["GB"][5] = ["Book Finishers"];
thisLinkSectionText["GB"][6] = ["Publishers"]; 
thisLinkSectionText["GB"][7] = ["Agents"];*/

thisLinkSectionText["FR"]= [];
thisLinkSectionText["FR"][0] = ["Photographes"] ; 
thisLinkSectionText["FR"][1] = ["Graphistes"] ; 
thisLinkSectionText["FR"][2] = ["Traitement de l'image postproduction"]; 
thisLinkSectionText["FR"][3] = ["R&eacute;daction publicitaire et r&eacute;vision"]; 
thisLinkSectionText["FR"][4] = ["Imprimeurs"];
/*thisLinkSectionText["FR"][4] = ["Retouches"];
thisLinkSectionText["FR"][5] = ["Maisons d'édition"]; 
thisLinkSectionText["FR"][6] = ["Publishers"];*/

thisLinkSectionText["DE"]= [];
thisLinkSectionText["DE"][0] = ["Fotografen"] ;
thisLinkSectionText["DE"][1] = ["Buchgestaltung"] ; 
thisLinkSectionText["DE"][2] = ["Post Production-Bildbearbeitung"]; 
thisLinkSectionText["DE"][3] = ["Texte & Lektorat"]; 
thisLinkSectionText["DE"][4] = ["Druck"];
/*thisLinkSectionText["DE"][4] = ["Buchbindung"];
thisLinkSectionText["DE"][5] = ["Verlage"]; 
thisLinkSectionText["DE"][6] = ["Agenturen"];*/

thisLinkSectionText["ES"]= [];
thisLinkSectionText["ES"][0] = ["Fot&oacute;grafos"] ;
thisLinkSectionText["ES"][1] = ["Dise&ntilde;adores de libros"] ; 
thisLinkSectionText["ES"][2] = ["Posproducci&oacute;n de im&aacute;genes"]; 
thisLinkSectionText["ES"][3] = ["Redacci&oacute;n y Edici&oacute;n"]; 
thisLinkSectionText["ES"][4] = ["Impresores"];
/*thisLinkSectionText["ES"][4] = ["Encuadernadores"];
thisLinkSectionText["ES"][5] = ["Servicios de publicación"]; 
thisLinkSectionText["ES"][6] = ["Representantes"];*/

var thisLinkItemText = [];
thisLinkItemText[0] = [];

thisLinkItemText[0][0] = ["Clive Frost","","www.clivefrost.com"];
thisLinkItemText[0][1] = ["	L.J.A.D. Creyghton","","www.creyghton.com"];

thisLinkItemText[1] = [];
thisLinkItemText[1][0] = ["Marcus Haslam","marcus@hasdesign.co.uk",""];
thisLinkItemText[1][1] = ["Rudo Hartman","rhstudio@xs4all.nl",""];

thisLinkItemText[2] = [];
thisLinkItemText[2][0] = ["Joe Thomas","joe@joe-digital.com",""];

thisLinkItemText[3] = [];
thisLinkItemText[3][0] = ["Rachel Thomas","rachel@rachelcopywriter.com",""];

thisLinkItemText[4] = [];
thisLinkItemText[4][0] = ["Good News Press","","www.goodnewspress.co.uk"];
thisLinkItemText[4][1] = ["Printer Trento","","www.printertrento.it"];

var thisPDFLinkText = [];
thisPDFLinkText["gb"] = "<p>Click here to see a PDF preview of this page</p>";

thisPDFLinkText["es"] = "Haga clic aqu&iacute; para ver una vista anticipada de PDF de esta p&aacute;gina";

thisPDFLinkText["de"] = "<p>Klicken Sie hier, um eine PDF-Vorschau auf diese Seite anzusehen<\/p>";

thisPDFLinkText["fr"] = "Cliquez ici pour voir une avant-premi&egrave;re PDF de cette page";  

//var thisPaypalAlertText = [];
//thisPaypalAlertText["gb"] = "<p>All payments are handled by PayPal. You can use your credit/debit card or a PayPal account. The information you give is private and secure.<\/p><p>By proceeding with your order, you confirm that you have read our Terms and Conditions.<\/p>";

//thisPaypalAlertText["es"] = "Todos los pagos se procesan por PayPal. Puede utilizar su tarjeta de crédito/débito o una cuenta PayPal. Los datos se transmitirán de manera segura y confidencial.<\/p><p>Si procede con el pedido, está confirmando que ha leído y aceptado nuestras Cláusulas y condiciones.<\/p>";

//thisPaypalAlertText["de"] = "<p>Alle Zahlungen werden über PayPal abgewickelt. Sie können mit Ihrer Kredit-/Debitkarte oder Ihrem PayPal-Konto bezahlen. Die von Ihnen übermittelten Informationen sind privat und sicher.<\/p><p>Durch Ausführung Ihrer Bestellung bestätigen Sie, dass Sie unsere AGB gelesen haben und akzeptieren.<\/p>";

//thisPaypalAlertText["fr"] = "<p>Tous les paiements sont traités par PayPal. Vous pouvez utiliser votre carte de crédit/débit ou votre compte PayPal. Les informations communiquées sont confidentielles et sécurisées.<\/p><p>En passant votre commande, vous reconnaissez avoir lu et accepté nos conditions générales.<\/p>";

var thisBenefitsText = [] ;

thisBenefitsText["gb"] = "<iframe src ='benefits_gb.htm' width='425' height='250'></iframe>";

thisBenefitsText["es"] = "<iframe src ='benefits_es.htm' width='425' height='250'></iframe>";

thisBenefitsText["de"] = "<iframe src ='benefits_de.htm' width='425' height='250'></iframe>";

thisBenefitsText["fr"] = "<iframe src ='benefits_fr.htm' width='425' height='250'></iframe>";

var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}


var euFlag = true;
function submitMe(v){
	var str;
	str = "#frm_" + v;
	$(str).submit(); 	
	$("#dialog_orderalert").dialog('close');
 }
 

function checkTerms(v){
	var html_str = "<div id='order_discount_page'>";
	html_str += thisSITE_TEXT["ST10M"];
	var html_frm = '<form id="frm_checkdiscount"><input name="title_code" type="hidden" value="' +thisTitleChoice+'" /><input name="discount_code" type="text" /></form>';
	html_str += html_frm + "<p>" +  thisSITE_TEXT["ST13M"] + "</p><\/div>";
	$("#dialog_orderalert").html(html_str);
		if (v==1){
		 euFlag = false;
		}else{
		 euFlag = true;
		}
	$("#dialog_orderalert").dialog("open");
	$("#dialog_orderalert").dialog('option', 'buttons', { 'Continue': function() {JQdoDataAction("check_discount",{});},"Cancel": function() { $(this).dialog("close"); } });
	
   }
   
   function openDialog(params){
	   switch(params.dialog_name){
		   case "comment":
		   var commentFormHTML ='<form class="cmxform" id="emailCheckForm" method="post" action=""><fieldset><p><br />' + thisSITE_TEXT["ST14N"] + '</p><p><br /><label for="Comment_Email">' + translateFormField(thisLanguageChoice,"Email")+ '</label><input id="Comment_Email" name="Email" size="25"  class="required email" /></p><p align="right"><input id="btn_continue" name="btn_continue" type="button" class="submit" value="' + thisSITE_TEXT["ST14P"]+ '"/></p></fieldset></form><form class="cmxform" id="commentForm" method="get" action=""><fieldset><p><label for="User_Name">' + thisSITE_TEXT["ST14G"]+ ':</label><br /><input id="User_Name" name="User_Name" size="25"  class="required" /><em>*</em><br /><br /></p><p><label for="Comment_Text">' + thisSITE_TEXT["ST14H"] + ':</label><br /><textarea id="Comment_Text" name="Comment_Text" cols="54"  rows="3"class="required"></textarea><em>*</em><br/><br /></p><p><label for="Comment_Rating">' + thisSITE_TEXT["ST14J"]+ ':</label>  <div id="stars-wrapper999"><span id="stars-cap"></span><select name="Comment_Rating"><option value="1">Very poor</option><option value="2">Not that bad</option><option value="3">Average</option><option value="4">Good</option><option value="5">Perfect</option></select></div></p><br /><br /><p><img id="captcha" src="/includes/securimage/securimage_show.php" alt="CAPTCHA Image" /><br /><label for="Captcha">' + thisSITE_TEXT["ST14K"]+ ':</label><br /><input type="text" id="Captcha_Code" name="captcha_code" size="10" maxlength="6" /></p><p align="right"><input id="btn_submit" name="btn_submit" type="button" class="submit" value="' + thisSITE_TEXT["ST14L"]+ '"/></p></fieldset></form>';
		    $("#dialog_comment").html(commentFormHTML);
			$("#emailCheckForm").show();
			$("#commentForm").hide();
			$("#dialog_comment").dialog("open");
			$("#stars-wrapper999").stars({
			 inputType: "select"
			 });			
			break;
		   }
	   }

function x_checkTerms(){
	//return  confirm(thisPaypalAlertText[thisLanguageChoice]);
	return  confirm(thisPaypalAlertText[thisLanguageChoice]);
	}

// ==========================
// BASE DOM FUNCTIONS
// ==========================
function nada() { }

// FUNCTION THAT CHECKS THE DOM 
function getObj(name){
if (document.getElementById)
{this.obj = document.getElementById(name);}
else if (document.all)
{this.obj = document.all[name];}
else if (document.layers)
{this.obj = document.layers[name];}
}

// CENTER WINDOW //
function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight) == 'number') {
windowHeight = window.innerHeight;
}
else {
if (document.documentElement && document.documentElement.clientHeight) {
windowHeight = document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight = document.body.clientHeight;
}
}
}
return windowHeight;
}

function setSpacing() {
if (document.getElementById) {
var windowHeight = getWindowHeight();
if (windowHeight > 0) {
var contentElement = new getObj('wrapper');
var contentHeight = contentElement.obj.offsetHeight;
if (windowHeight - contentHeight > 0) {	
contentElement.obj.style.position = 'relative';
contentElement.obj.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
}
}
}
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}


function getRandomItemFromArray(thisArray) {
		if (thisArray.length){ 
		 var rndNUM =  getRandomNumber(thisArray.length);
		}else {
			if (typeof(thisArray) == 'object'){
				var i = 0;
				for (i in thisArray){
					i++;
				}
			 var rndNUM = getRandomNumber(i);
			}
		}
	return rndNUM;
	}

function getRandomNumber(n) {
	var Rnd = Math.floor(Math.random() * n);
	return Rnd;
	}


function doHide(theObject,theAction) {
	var thisHiding = new getObj(theObject);
	if(typeof thisHiding != "undefined") {
	if (theAction == "hidden") {
	thisHiding.obj.className = "make_hidden";	
	}
	else {
	thisHiding.obj.className = "make_none";	
	}
	}
}

function doShow(theObject, theAction) {
	var doAction = true;
	if((theObject=="footer_back" || theObject=="footer_contact") && isEmailFlag == true) {doAction = false;}
	if (doAction == true) {
	var thisShowing = new getObj(theObject);
	if(typeof thisShowing != "undefined") {
	if (theAction == "block") {
	thisShowing.obj.className = "make_block";	
	}
	else {
	thisShowing.obj.className = "make_visible";	
	}
	}
	} 
	//else {alert("Flag true");}
}

function doAddClass(theObject, theAction) {
	var thisDiv = new getObj(theObject);
	thisDiv.obj.className = theAction;
}

function setSelected(reqElement, reqID, reqClass) {
var el = document.getElementById(reqElement);
var thisList = el.getElementsByTagName('a');
//if (reqID != "Folio") {
for (var i=0;i<thisList.length;i++) {thisList[i].className = "";}
//if (reqElement == "top_nav") {thisList[0].className = "nav_first";}
//}
//alert(reqID);
doAddClass(reqID, reqClass);
}

// ==========================
// DOM Functions
// ==========================

function getMainNav(thisOffice) {
	//alert(thisOffice);
	var thisNav = new getObj('top_nav');
	var thisHTML = '<li><a href="Javascript:getContent(100,0)" id="top_nav1">' + thisSITE_NAV['NAV01'] + '</a></li>';
	thisHTML = thisHTML + '<li><a href="Javascript:getContent(3,0)" id="top_nav3">' +thisSITE_NAV['NAV03'] + '</a></li>';
	thisHTML = thisHTML + '<li><a href="Javascript:getContent(4,0)" id="top_nav4">' + thisSITE_NAV['NAV04'] + '</a></li>';
	thisHTML = thisHTML + '<li><a href="Javascript:getContent(2,0)" id="top_nav2">' +thisSITE_NAV['NAV02'] + '</a></li>';
	//This is the new blog menu to use below 
	thisHTML = thisHTML + '<li><a href="http://clivefrost.wordpress.com" target="_blank">' + thisSITE_NAV['NAV07'] + '</a></li>'; 
	thisHTML = thisHTML + '<li><a href="Javascript:getContent(6,0)" id="top_nav5">' + thisSITE_NAV['NAV05'] + '</a></li>'; 
	thisHTML = thisHTML + '<li><a href="Javascript:getContent(0,0)" id="top_nav6" onmouseover="getSubNav(\'subNav6\');" onmouseout="getSubNav();">' + thisSITE_NAV['NAV06'] + '</a></li>';	
	//thisHTML = thisHTML + '<li><a href="Javascript:nada();" onmouseover="getSubNav(\'subNav6\');" onmouseout="getSubNav();">' + thisSITE_NAV['NAV07'] + '</a></li>';
	


	thisNav.obj.innerHTML = thisHTML;
	}
function getSubNav(thisSubNav) {
	var d = document.getElementById(thisSubNav);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('subNav'+i)) {document.getElementById('subNav'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
	

	}
	
function getTitleThumbs(){	
	//var thisDiv = new getObj('right_wide');
	 i = 0 	
	 var thisHTML = "<ul id='book_thumbs'>";
		for (i in PORTFOLIO_IMAGE_SET){
			/* Thumbs Link */
		var thisImagePDF = PORTFOLIO_IMAGE_SET[i]["has_pdf"];
		var thisPDFClass = "";
		if (thisImagePDF > 0) {thisPDFClass = " class='PDF_border'";}
			thisHTML = thisHTML + "<li" + thisPDFClass + "><table><tr><td><a href='Javascript:getFullImage(" + i + ");'><img src='\/ti\/" + PORTFOLIO_IMAGE_SET[i]["filename"] + "'><\/a><\/td><\/tr><\/table></li>";	
		 	i++;
		}
	 thisHTML = thisHTML + "</ul>"
	 thisDiv = document.getElementById('right_wide');
	 thisDiv.innerHTML = thisHTML;
	}
	
function getFullImage(reqNum){	
	 var thisHTML;
	 if (!reqNum) { reqNum = 0; }
			thisHTML = "<div id='full_image'><table><tr><td><div id='shadow'><a href='Javascript:getTitleThumbs();'><img src='\/fi\/" + PORTFOLIO_IMAGE_SET[reqNum]["filename"] + "'><\/a><\/div><\/td><\/tr><\/table><\/div>";	
	var thisFullNav = getFullNav(reqNum);
	thisHTML = thisHTML + "<div id='image_nav'>" + thisFullNav + "<\/div>";			
	 thisDiv = document.getElementById('right_wide');
	 thisDiv.innerHTML = thisHTML;
	}
	
function getTitleImage(){	
	 var thisHTML;
	 //reqNum = 0;
	//thisHTML = "<div id='full_image'><table><tr><td><div id='shadow'><a href='Javascript:getTitleThumbs();'><img src='\/fi\/" + PORTFOLIO_IMAGE_SET[reqNum]["filename"] + "'><\/a><\/div><\/td><\/tr><\/table><\/div>";	
	//var thisFullNav = getFullNav(0);
	//thisHTML = thisHTML + "<div id='image_nav'>" + thisFullNav + "<\/div>";
	i = 0 	
	 var thisHTML = "<ul id='book_thumbs'>";
		for (i in PORTFOLIO_IMAGE_SET){var thisImagePDF = PORTFOLIO_IMAGE_SET[i]["has_pdf"];
		var thisPDFClass = "";
		if (thisImagePDF > 0) {thisPDFClass = " class='PDF_border'";}
			thisHTML = thisHTML + "<li" + thisPDFClass + "><table><tr><td><a href='Javascript:getFullImage(" + i + ");'><img src='\/ti\/" + PORTFOLIO_IMAGE_SET[i]["filename"] + "'><\/a><\/td><\/tr><\/table></li>";	
		 	i++;
		}
	 thisHTML = thisHTML + "</ul>"	
	 return thisHTML;
	}
	
function getFullNav(reqNum) {
	var thisNum = reqNum;
	var thisFolioLength =  PORTFOLIO_IMAGE_SET.length;
	if (reqNum > 0)
	{ var thisprevHTML = "<a href='Javascript:getFullImage(" + (thisNum-1) + ");'>&lt; prev<\/a>"; }
else { var thisprevHTML = "&lt; prev";}
if (thisNum < (thisFolioLength-1)) 
	{ var thisnextHTML = "<a href='Javascript:getFullImage(" + (thisNum+1) + ");'>next &gt;<\/a>"; }
else {var thisnextHTML = "next &gt;"; }
/* Image Count */
var thiscountHTML = "- page " + (reqNum+1) + " \/ " + thisFolioLength + " -";
/* Thumbs Link */
var thisThumbsLinkHTML = "<a href='Javascript:getTitleThumbs(" + reqNum + ");' id='butt_thumbs'><img src='graphics\/butt_thumbs.gif' alt='click here for book overview' \/><\/a>";
var thisImagePDF = PORTFOLIO_IMAGE_SET[reqNum]["has_pdf"];
var thisImageTitle = "";
if (thisImagePDF > 0) {var thisImagePDF=PORTFOLIO_IMAGE_SET[reqNum]["filename"]; thisImagePDF = thisImagePDF.substr(0,(thisImagePDF.length-4)) + ".pdf"; thisImageTitle = "<a href='bookPDFs\/" + thisImagePDF + "' target='_blank' id='bookPDF_link'>" + thisPDFLinkText[thisLanguageChoice] + "<\/a>";}
var thisNavHTML = thisThumbsLinkHTML + thisImageTitle + "<ul id='nav_butts'><li id='butt_prev'>" + thisprevHTML + "<\/li><li id='butt_count'>" + thiscountHTML + "<\/li><li id='butt_next'>" + thisnextHTML + "<\/li><\/ul>";
return thisNavHTML;
	}

function getTitleDetail (i) {
	var str;
	 		for (x in thisPortfolio_Collection){
				if (thisPortfolio_Collection[x]["TitleCode"]==i){
				 str = '<p class="book_title">' + thisPortfolio_Collection[x]["TitleLong"] + '</p>';
				 str =  str + '<p class="book_author">' + thisPortfolio_Collection[x]["TitleAuthor"] + '</p>';
				 str =  str + '<div class="book_descr">' + thisPortfolio_Collection[x]["TitleDesc"] + '</div>';
				}
		}
	 return str;
	}

function getTitleGrid(){
	 var str;
	 str = "TITLES WIll GO HERE";
	 i = 0 	
	 // str = "<div id='thumbs_page'><ul class='thumbs_grid'>";
	 str = "<div id='titles_page'><ul class='titles_list'>";
	 str = "<div id='titles_page'><dl>";
		for (i in thisPortfolio_Collection){
			str = str + "<dt><ul class='title_text'><li class='title_text_title'>" + thisPortfolio_Collection[i]["TitleLong"] + "<\/li><li class='title_text_author'>" +thisPortfolio_Collection[i]["TitleAuthor"] + "<\/li><li class='title_text_desc'>" + thisPortfolio_Collection[i]["TitleDesc"] + "<\/li><li class='title_text_link'><a href='#' onclick=\"getAppData('view_title',{'lang':'"+ thisLanguageChoice +"','title_code':'" + thisPortfolio_Collection[i]["TitleCode"] + "','page_no':7,'page_choice':'" + thisPortfolio_Collection[i]["TitleCode"] + "'})\">" + thisSITE_NAV["NAVB1"] + "<\/a><a class='title_text_review' href='#' onclick=\"getAppData('view_title',{'lang':'"+ thisLanguageChoice +"','title_code':'" + thisPortfolio_Collection[i]["TitleCode"] + "','page_no':13,'page_choice':'" + thisPortfolio_Collection[i]["TitleCode"] + "'})\">" + thisSITE_NAV["NAVB7"] + "</a><\/li><\/ul><\/dt><dd class='image_box'><table><tr><td><a href='#' onclick=\"getAppData('view_title',{'lang':'"+ thisLanguageChoice +"','title_code':'" + thisPortfolio_Collection[i]["TitleCode"] + "','page_no':7,'page_choice':'" + thisPortfolio_Collection[i]["TitleCode"] + "'})\"><div class='title_shadow'><img src='\/ti\/" + thisPortfolio_Collection[i]["TitleKeyImage"] + "'><\/div><\/a><\/td><\/tr><\/table><\/dd>";
		 	i++;
		}
	 str = str + "<\/dl><\/div>"
	 return str;
	}
	
/*function get(){
}*/

function getWelcomeWord(reqlang,tc) {
	var thisHTML = thisWelcomeWord[reqlang];
	var langCode = reqlang.toLowerCase();
	//alert(thisHTML);
	/*var tc = "";
		if (thisTitleChoice !=="xxx"){
		var tc = "&title_code=" + thisTitleChoice;
		}*/
	thisHTML = '<a href="?state=view_000&page=100' + tc + '&lang=' + langCode + '" >' + thisHTML + '<\/a>';
	var thisDiv = new getObj('welcome_word'); 
	thisDiv.obj.innerHTML = thisHTML;
	}
	
function doMailSignUp(reqlang) {
	$("#dialog_benefit").html(thisBenefitsText[thisLanguageChoice]);
	$("#dialog_benefit").dialog("open");
 }
	
function x_doMailSignUp(reqlang) {
	//var thisURL = 'mail_list_' + thisLanguageChoice + '.htm'
	var thisURL = 'benefits_' + thisLanguageChoice + '.htm'
	var winMailList = window.open(thisURL,'winMailList','width=460,height=260,scrollbars=yes, addressbar=no');
	winMailList.focus();
	}
	

function doBookOrderForm(reqOrder) {
	var thisDiv = new getObj('rh_panel_content');
	var thisHTML = thisSITE_TEXT["ST9RA"];
	/*	var thisHTML = '<p class="top">Your Order request</p><form action="xxx" method="post" name="orderForm"><ol>';
thisHTML = thisHTML + '<li><label for="Full_name">Name:</label><input id="Full_name" name="Full_name" class="text" maxlength="100" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Address1">Address:</label><input id="Address1" name="Address1" class="text" maxlength="100" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Address2">&nbsp;</label><input id="Address2" name="Address2" class="text" maxlength="100" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Address3">&nbsp;</label><input id="Address3" name="Address3" class="text" maxlength="100" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Postcode">Postcode:</label><input id="Postcode" name="Postcode" class="text" maxlength="50" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Country">Country:</label><input id="Country" name="Country" class="text" maxlength="100" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Telephone">Phone:</label><input id="Telephone" name="Telephone" class="text" maxlength="100" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Email">Email:</label><input id="Email" name="Email" class="text" maxlength="100" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Title">Title:</label><input id="Title" name="Title" class="text" maxlength="100" type="text"></li>';
	thisHTML = thisHTML + '<li><label for="Message">Message:</label><textarea id="Message" name="Message" cols="30" rows="5" class="textarea"></textarea></li>';
	thisHTML = thisHTML + '</ol><!--<input name="Submit" class="butt_submit" value="Send your Order request >" onclick="#" type="button">--></form>';
	thisHTML = thisHTML + '<p class="right"><a href="Javascript:alert(\'Test mode only\');">Send your Order request<\/a>&nbsp;&gt;<\/p>';*/
	thisDiv.obj.innerHTML = thisHTML;
	var thisDiv2 = new getObj('Title');
	thisDiv2.obj.value=reqOrder;
	}
	
function getContent(thisnum, thischoice) {
	var thisContent = new getObj('content');	
	var thisHTML = "";
	//alert("getcontent(" + thisnum+ "," + thischoice + ")")
	switch (thisnum) {
		 //Splash page with language selection
		 case 0:
		var tc = "";
		if (thisTitleChoice !=="xxx"){
			 var tc = "&title_code=" + thisTitleChoice;
			 }

		 	 var thisHTML = '<div id="langContent"><!--<table class="lang_home"><tr><td>--><div id="welcome_word"><a href="?state=view_000&page=100' + tc + '" >' + thisWelcomeWord[thisLanguageChoice.toUpperCase()] + '<\/a><\/div>';
		 thisHTML = thisHTML + '<div id="lang_choice_butts"><ol id="lang_choice"><li><a  href="?state=view_000&lang=fr&page=100' + tc + '" onmouseover="getWelcomeWord(\'FR\',\'' + tc + '\');">Fran&ccedil;ais</a><\/li><li>|<\/li><li><a href="?state=view_000&lang=de&page=100' + tc+  '" onmouseover="getWelcomeWord(\'DE\',\'' + tc + '\');">Deutsch</a><\/li><li>|<\/li><li><a  href="?state=view_000&lang=es&page=100' + tc + '" onmouseover="getWelcomeWord(\'ES\',\'' + tc + '\');">Espa&ntilde;ol</a><\/li><li>|<\/li><li><a href="?state=view_000&lang=gb&page=100' + tc + '" onmouseover="getWelcomeWord(\'GB\',\'' + tc + '\');">English</a><\/li><\/ol><\/div>';
		 
		 thisHTML = thisHTML + '<!--<\/td><\/tr><\/table>-->';
		 thisHTML = thisHTML + '<\/div>';
		 var thisResult = 0;
		if(document.getElementById("top_nav6")){ var thisMenuChoice = "top_nav6"; };
		 break;
		// Call Home page routines that get and set data for random title and finally call getcontent(1,0) below
		case 100:
		 JQdoDataAction("view_rand_title",{"title_code":thisStickyTitleChoice});
		 updatePageWhenReady({'page_no':1,'page_choice':'0'})
		/*var thisMenuChoice = "top_nav1";*/
		 break;
		// Home page
		case 1:
		//alert(1);
		/* Placeholders */	
		//featuredTitleNum = getRandomItemFromArray(thisPortfolio_Collection);
		featuredTitleNum = "\'" + RANDOM_TITLE[0].TitleCode + "\'";
var thumbs_url = "http://www.thepicture.co.uk/includes/y_imagethumb.php?s=http://www.thepicture.co.uk/fi/" + RANDOM_TITLE[0].filename + "&w=555&h=370";
	var thisImg = '<img src="' + thumbs_url + '"  alt="#" />';
		/* Random Title Info */
		var thisHTML = '<div id="left_wide"><table><tr><td>' + thisSITE_TEXT["ST1LA"] + '<\/td><\/tr><\/table><div id="left_wide_bottom">' + thisSITE_TEXT["ST1LB"] + '</div></div>';
		thisHTML = thisHTML + '<div id="right_narrow"><div id="home_image"><table class="img_home"><tr><td><div id="shadow">' + thisImg + '<\/div><\/td><\/tr><\/table><\/div><div id="right_narrow_bottom">';
		//thisHTML = thisHTML + '<div id="random_title_block"><p class="featured">' + thisSITE_NAV["NAVB0"] + ':</p><div id="title_info"><p class="black">' + RANDOM_TITLE[0].TitleLong  + '<br /><span class="white">' + RANDOM_TITLE[0].TitleAuthor + '</span></p><\/div><\/div>';
		thisHTML = thisHTML + '<div id="random_title_block"><a href="Javascript:doMailSignUp();"><p>' + thisSITE_NAV["NAVB0"] + '<\/p><\/a><\/div>';
		/* Book Links */
		//thisHTML = thisHTML + '<div id="book_links_block"><ul><li>- <a onclick="getAppData(\'view_title\', {\'title_code\':\'' + RANDOM_TITLE[0].TitleCode + '\',\'lang\':\'' + thisLanguageChoice + '\',\'page_no\':7,\'page_choice\':' + featuredTitleNum + '});" href="#">' + thisSITE_NAV["NAVB1"] + '</a></li><li>- <a onclick="getAppData(\'view_title\', {\'title_code\':\'' + RANDOM_TITLE[0].TitleCode + '\',\'lang\':\'' + thisLanguageChoice + '\',\'page_no\':9,\'page_choice\':' + featuredTitleNum + '});" href="#">' + thisSITE_NAV["NAVB2"] + '</a></li><li>- <a onclick="getAppData(\'view_title\', {\'title_code\':\'' + RANDOM_TITLE[0].TitleCode + '\',\'lang\':\'' + thisLanguageChoice + '\',\'page_no\':8,\'page_choice\':' + featuredTitleNum + '});" href="#">' + thisSITE_NAV["NAVB3"] + '</a></li><li>- <a onclick="getAppData(\'view_title\', {\'title_code\':\'' + RANDOM_TITLE[0].TitleCode+ '\',\'lang\':\'' + thisLanguageChoice + '\',\'page_no\':10,\'page_choice\':' + featuredTitleNum + '});" href="#">' + thisSITE_NAV["NAVB4"] + '</a></li></ul></div>';
		/* Titles Button */
		thisHTML = thisHTML + '<div id="butt_titles"><a href="Javascript:getContent(3,0)"><img src="graphics\/butt_titles.jpg" \/><div id="butt_titles_words">' + thisTitlesLinkText[thisLanguageChoice.toUpperCase()] + '<\/div><\/a><\/div>';
		thisHTML = thisHTML + '</div></div>';
		thisContent.obj.innerHTML = thisHTML;		
		 var thisMenuChoice = "top_nav1";
		break;
		// About page
		case 2:
		var thisHTML = '<div id="left_wide"><table><tr><td>' + thisSITE_TEXT["ST2LA"] + '<\/td><\/tr><\/table><div id="left_wide_bottom">' + thisSITE_TEXT["ST2LB"] + '<\/div><\/div>';
		thisHTML = thisHTML + '<div id="right_narrow" class="bg_about"><table><tr><td>' + thisSITE_TEXT["ST2RA"] + '<\/td><\/tr><\/table></div>';
		 var thisMenuChoice = "top_nav2";
		break;
		// Titles page
		case 3:
		var thisHTML = '<div id="left_wide"><table><tr><td>' + thisSITE_TEXT["ST3LA"] + '<\/td><\/tr><\/table><div id="nl_signup">' + thisSITE_TEXT["ST7LA"] + '<\/div><div id="left_wide_bottom">' + thisSITE_TEXT["ST3LB"] + '<\/div><\/div>';
		thisHTML = thisHTML + '<div id="right_narrow">' + getTitleGrid() + '</div>';
		 var thisMenuChoice = "top_nav3";
		break;
		// Photographers page - Text state
		case 4:
		var thisHTML = '<div id="left_wide"><table><tr><td>' + thisSITE_TEXT["ST4LA"] + '<\/td><\/tr><\/table><div id="left_wide_bottom">' + thisSITE_TEXT["ST4LB"] + '<\/div><\/div>';
		thisHTML = thisHTML + '<div id="right_narrow" class="bg_photographers"><table><tr><td>' + thisSITE_TEXT["ST4RA"] + '<\/td><\/tr><\/table><\/div>';
		 var thisMenuChoice = "top_nav4";
		break;
		// Email return page - Text State
		case 44:
		var thisHTML = '<div id="left_wide"><table><tr><td>' + thisSITE_TEXT["ST4LA"] + '<\/td><\/tr><\/table><div id="left_wide_bottom">' + thisSITE_TEXT["ST4LB"] + '<\/div><\/div>';
			switch (thisLanguageChoice) {
				case "fr":
				 thisHTML = thisHTML + '<div id="right_narrow" class="bg_contributors"><table id="photog_contact"><tr><td><p>Merci.</p><p>Vos d&eacute;tails ont &eacute;t&eacute; re&ccedil;us.</p><p>Nous vous contacterons bient&ocirc;t.</p><p><a onclick="getContent(4,0);" href="#">< OK</a></p><\/td><\/tr><\/table><\/div>';
				break;
				case "es":
				 thisHTML = thisHTML + '<div id="right_narrow" class="bg_contributors"><table id="photog_contact"><tr><td><p>Gracias.</p><p>Sus detalles han sido recibidos.</p><p>Nos pondremos en contacto con usted dentro de poco.</p><p><a onclick="getContent(4,0);" href="#">< OK</a></p><\/td><\/tr><\/table><\/div>';
				break;
				case "de":
				 thisHTML = thisHTML + '<div id="right_narrow" class="bg_contributors"><table id="photog_contact"><tr><td><p>Danke.</p><p>Ihre Details sind erhalten worden.</p><p>Wir werden uns mit Ihnen kurz in Verbindung setzen.</p><p><a onclick="getContent(4,0);" href="#">< OK</a></p><\/td><\/tr><\/table><\/div>';
				break;
				default :
				 thisHTML = thisHTML + '<div id="right_narrow" class="bg_contributors"><table id="photog_contact"><tr><td><p>Thank you.</p><p>Your details have been received.</p><p>We will contact you shortly.<\/p><p><a onclick="getContent(4,0);" href="#">< OK</a></p><\/td><\/tr><\/table><\/div>';
				break;
			 }
		
		 var thisMenuChoice = "top_nav4";
		break;
		// Photographers page - Form state
		case 5:
		var thisHTML = '<div id="left_wide"><table><tr><td>' + thisSITE_TEXT["ST4LA"] + '<\/td><\/tr><\/table><div id="left_wide_bottom">' + thisSITE_TEXT["ST4LB"] + '<\/div><\/div>';
		thisHTML = thisHTML + '<div id="right_narrow" class="bg_contributors"><table><tr><td>' + thisSITE_TEXT["ST5RA"] + '<\/td><\/tr><\/table><\/div>';
		 var thisMenuChoice = "top_nav4";
		break;
		// Contributors page
		case 6:
		var thisHTML = '<div id="left_wide"><table><tr><td>' + thisSITE_TEXT["ST6LA"] + '<\/td><\/tr><\/table><div id="left_wide_bottom">' + thisSITE_TEXT["ST6LB"] + '<\/div><\/div>';
		thisHTML = thisHTML + '<div id="right_narrow" class="bg_contributors"><table><tr><td><div id="rn_left_col"' + thisSITE_TEXT["ST6RA"] + '<ul class="link_list" >';
		thisSectionHTML_Builder = "";
		thisSectionHTML = "";
		 for (x in thisLinkSectionText[thisLanguageChoice.toUpperCase()]){ 
			 thisSectionHTML = thisSectionHTML + '<li>' + thisLinkSectionText[thisLanguageChoice.toUpperCase()][x][0] ;
			  var thisSubHTML = "";
			  var thisSubHTML_Builder = "";
					for (x_sub in thisLinkItemText[x]){
						thisSubHTML = "";
						var myComposer = "";
					   for (x_field in thisLinkItemText[x][x_sub]){
							if ( thisLinkItemText[x][x_sub][x_field] ==""){
						    }else{
								if (x_field==1){// Email
								thisSubHTML = thisSubHTML + myComposer + '<a href="mailto:' + thisLinkItemText[x][x_sub][x_field] + '">' + thisLinkItemText[x][x_sub][0] + '<\/a>' ;
								}else{
									if (x_field==2){ // URL
									thisSubHTML = thisSubHTML + myComposer + '<a target="_blank" href="http:\/\/' + thisLinkItemText[x][x_sub][x_field] + '">' + thisLinkItemText[x][x_sub][0] + '<\/a>' ;
									}else{ //NAME
									//thisSubHTML = thisSubHTML + myComposer +  thisLinkItemText[x][x_sub][x_field]   ;	
									}
								
								}							
							 //myComposer = "<br \/>";
							} 
						  
						}
					
						if (thisSubHTML !==""){
						 thisSubHTML_Builder = thisSubHTML_Builder + "<li>" + thisSubHTML  + "<\/li>" ;
						 }
					}
					
					if (thisSubHTML_Builder !==""){
					 thisSubHTML_Builder = "<ul class='link_items'>" + thisSubHTML_Builder + "<\/ul>";
					 thisSectionHTML = thisSectionHTML + thisSubHTML_Builder + '</li>';
					}else{
					 thisSectionHTML = "";
					}
			  thisSectionHTML_Builder =  thisSectionHTML_Builder  + thisSectionHTML ;
			  thisSectionHTML = "";
		}
		 
		 thisHTML = thisHTML + thisSectionHTML_Builder + '<\/ul><\/div>';
		 thisHTML = thisHTML + '<div id="rn_right_col"><p class="first">Our titles<\/p><ul id="rn_titles">';
		 // Each title looks like this
//onclick=\"getAppData('view_title',{'lang':'"+ thisLanguageChoice +"','title_code':'" + thisPortfolio_Collection[i]["TitleCode"] + "','page_no':7,'page_choice':'" + thisPortfolio_Collection[i]["TitleCode"] + "'})\"
		 for (v in thisPortfolio_Collection){
			  thisHTML = thisHTML + '<li><table><tbody><tr><td><a href="#"><div class="title_shadow"><img src="/ti/' + thisPortfolio_Collection[v]["TitleKeyImage"] +'" onclick=\"getAppData(\'view_title\',{\'lang\':\''+ thisLanguageChoice +'\',\'title_code\':\'' + thisPortfolio_Collection[v]["TitleCode"] + '\',\'page_no\':7,\'page_choice\':\'' + thisPortfolio_Collection[v]["TitleCode"] + '\'})\"></div></a></td></tr></tbody></table><div class="rn_titles_Title" ><a href=\"javascript:nada();\" onclick=\"getAppData(\'view_title\',{\'lang\':\''+ thisLanguageChoice +'\',\'title_code\':\'' + thisPortfolio_Collection[v]["TitleCode"] + '\',\'page_no\':7,\'page_choice\':\'' + thisPortfolio_Collection[v]["TitleCode"] + '\'})\">' + thisPortfolio_Collection[v]["TitleLong"] +'</a><\/div><div class="rn_titles_Author">' + thisPortfolio_Collection[v]["TitleAuthor"] +'<\/div><\/li>';
			 }
		 //thisHTML = thisHTML + '<li><table><tbody><tr><td><a href="#"><div class="title_shadow"><img src="/ti/CUBA_001.jpg"></div></a></td></tr></tbody></table><div class="rn_titles_Title">CUBA Cubanas y Cubanos<\/div><div class="rn_titles_Author">Clive Frost<\/div><\/li>';
		 // More sample titles - to remove
		 
		  //thisHTML = thisHTML + '<li><table><tbody><tr><td><a href="#"><div class="title_shadow"><img src="/ti/ATAD_001.jpg"></div></a></td></tr></tbody></table><div class="rn_titles_Title">Title - Atados al Mar<\/div><div class="rn_titles_Author">Clive Frost<\/div><\/li><li><table><tbody><tr><td><a href="#"><div class="title_shadow"><img src="/ti/HOLL_000.jpg"></div></a></td></tr></tbody></table><div class="rn_titles_Title">The Holland Album <\/div><div class="rn_titles_Author">L.J.A.D. Creyghton<\/div><\/li><li><table><tbody><tr><td><a href="#"><div class="title_shadow"><img src="/ti/PLAC_001.jpg"></div></a></td></tr></tbody></table><div class="rn_titles_Title">Places of Interest and Little Importance<\/div><div class="rn_titles_Author">Clive Frost<\/div><\/li>';
		  // End sample titles
		// End titles 
		 thisHTML = thisHTML + '<\/ul><\/div>';
		 thisHTML = thisHTML + '<\/td><\/tr><\/table><\/div>';
		 var thisMenuChoice = "top_nav5";
		break;		
		// Book page - Preview the Book state - FULL
		case 7:
		// Book page - Preview the Book state - THUMBS
		case 8:
		// Book page - About the Book state
		case 9:
		// Book page - Buy the Book state
		case 10:
		// Email return page 
		case 13:
		// Comments
		case 110:
		var thisHTML = '<div id="left_narrow">' + getTitleDetail(thischoice)  + '<div id="nl_signup">' + thisSITE_TEXT["ST7LA"] + '<\/div>'
		thisHTML = thisHTML + '<div id="book_links_block"><ul><li><a onclick="getContent(7, \'' + thischoice + '\');" href="#" id="PTB">'+ thisSITE_NAV["NAVB1"] + '</a></li><li><a onclick="getContent(9, \'' + thischoice + '\');" href="#"  id="ATB">' + thisSITE_NAV["NAVB2"] + '</a></li><li><a onclick="getContent(8, \'' + thischoice + '\');" href="#" id="ATA">' + thisSITE_NAV["NAVB3"] + '</a></li><li><a onclick="getContent(13, \'' + thischoice + '\');" href="#" id="CMT">' + thisSITE_NAV["NAVB7"] + '</a></li><!--<li><a onclick="getContent(10, \'' + thischoice + '\');" href="#" id="BTB">' + thisSITE_NAV["NAVB4"] + '<\/a><\/li>--><\/ul><\/div>';	
		var linkLangChoice = thisLanguageChoice.toUpperCase();
		//thisHTML = thisHTML + '<div id="left_narrow_bottom"><ul id="bookOrder_buttons"><li><a href="pdfs/thePICTURE_PURCHASER_TandC_' + linkLangChoice + '.pdf" target="_blank">' + thisPurchaseTandC[linkLangChoice] + '<\/a><\/li><li><a href="Javascript:alert(\'Order through PayPal here (EU)\');"><img src="/graphics/PP_Button_EU_' +  linkLangChoice + '.jpg" \/><\/a><\/li><li><a href="Javascript:alert(\'Order through PayPal here (Non-EU)\');"><img src="/graphics/PP_Button_xEU_' +  linkLangChoice + '.jpg" \/><\/li><\/ul><\/div><\/div>';
		thisHTML = thisHTML + '<div id="left_narrow_bottom"><ul id="bookOrder_buttons"><li><a href="pdfs/thePICTURE_PURCHASER_TandC_' + linkLangChoice + '.pdf" target="_blank">' + thisPurchaseTandC[linkLangChoice] + '<\/a><\/li>' + BOOK_TEXT[2]["book_text"]  +  '<\/ul><\/div><\/div>';
				switch (thisnum){
				// Book page - Preview the Book state
				case 7:
				var thisSelectDiv = 'book_links_block';
				var thisSelectID ='PTB';
				 thisHTML = thisHTML + '<div id="right_wide" >' + getTitleImage() +'<\/div>';
				break;
				// Book page - About the Author  state
				case 8:
				var thisSelectDiv = 'book_links_block';
				var thisSelectID ='ATA';
				thisHTML = thisHTML + '<div id="right_wide" class="bg_book"><p class="first">' +thisSITE_NAV["NAVB3"]+'</p>' + BOOK_TEXT[0]["book_text"]  +  '<\/div>';
				break;
				// Book page - About the Book state
				case 9:
				var thisSelectDiv = 'book_links_block';
				var thisSelectID ='ATB';
				thisHTML = thisHTML + '<div id="right_wide" class="bg_book"><p class="first">' +thisSITE_NAV["NAVB2"]+'</p>' + BOOK_TEXT[1]["book_text"]  +  '</div>'
				break;
				// Book page - Buy the Book state
				case 10:
				var thisSelectDiv = 'book_links_block';
				var thisSelectID ='BTB';
				thisHTML = thisHTML + '<div id="right_wide" class="bg_book"><p class="first">' +thisSITE_NAV["NAVB4"]+'</p>' + BOOK_TEXT[2]["book_text"] +  '<\/div>';
				break;
				
				case 13:
					var thisSelectDiv = 'book_links_block';
					var thisSelectID ='CMT';
					
					var comment_builder = '<ol id="commentList">';
					var comment_rate = 0;
					var comment_filter_str = "Show All";
					var rate_count = 0;	
					var	rate_count_widget = 0;
						//<ol id="commentList">
				//<li>&lt;!-- 1st Comment -->
				//<span class="commentDate">[DATE]</span>
				//<dl><dt>Comment by: <span class="commentName">[NAME]</span>
				//Rating:<span class="commentRating">[RATING IMAGE]</span></dt>
				//<dd>[COMMENT]</dd></dl>
				//<p class="commentBase">&lt;&nbsp;</p>
				//</li>
						
						for (v in COMMENT_SET){
						  if (thisComments_Filter){
							if (COMMENT_SET[v]["language_code"]==thisLanguageChoice && (thisComments_Filter)){
							//comment_builder = comment_builder + "<li>" + COMMENT_SET[v]["comment_text"] + " - " + COMMENT_SET[v]["rating"] + "<\/li>";
							//COMMENT_SET[v]["rating"]
							rating_builder = '<div id="stars-wrapper'+rate_count_widget+'"><select name="Comment_Rating">';
							var option_builder = "";
								
								for (i=0;i<=5;i++){
								  if (i==COMMENT_SET[v]["rating"]){
								  option_builder = option_builder + '<option value="'+i+'" selected="selected">'+i+'</option>';
								  }else{
								   option_builder = option_builder + '<option value="'+i+'">'+i+'</option>';}
								  }
								  
							rating_builder = rating_builder + option_builder + '</select></div>';
							comment_builder = comment_builder + '<li>';
							comment_builder = comment_builder + '<span class="commentDate">' + COMMENT_SET[v]["format_date"] + '</span>';
							comment_builder = comment_builder + '<dl><dt>'+ thisSITE_TEXT["ST14E"]+': <span class="commentName">' + COMMENT_SET[v]["user_name"] + '</span><span class="commentLang">(' + translateFormField(COMMENT_SET[v]["language_code"],"Lang_long") +')</span>'+ thisSITE_TEXT["ST14F"]+':<span class="commentRating">' + rating_builder+ '</span></dt><dd>' + COMMENT_SET[v]["comment_text"]+ '</dd></dl>';
							comment_builder = comment_builder + '<p class="commentBase"><img src="graphics/bg_comments_tag.gif" width="16" height="13" alt="#" /></p>';
							comment_rate = parseInt((comment_rate + parseInt(COMMENT_SET[v]["rating"])));
								if (COMMENT_SET[v]["rating"]>0){
								 rate_count++;
								}
							rate_count_widget++;
							}
						    comment_filter_str = "Show All";
						  }else{
						   //comment_builder = comment_builder + "<li>" + COMMENT_SET[v]["comment_text"] + " - " + COMMENT_SET[v]["rating"] +"<\/li>";
						   rating_builder = '<div id="stars-wrapper'+rate_count_widget+'"><select name="Comment_Rating">';
							var option_builder = "";
								for (i=0;i<=5;i++){
								  if (i==COMMENT_SET[v]["rating"]){
								  option_builder = option_builder + '<option value="'+i+'" selected="selected">'+i+'</option>';
								  }else{
								   option_builder = option_builder + '<option value="'+i+'">'+i+'</option>';}
								  }
								  
							rating_builder = rating_builder + option_builder + '</select></div>';
						   
						   comment_builder = comment_builder + '<li>';
							comment_builder = comment_builder + '<span class="commentDate">' + COMMENT_SET[v]["format_date"] + '</span>';
							comment_builder = comment_builder + '<dl><dt>'+ thisSITE_TEXT["ST14E"]+': <span class="commentName">' + COMMENT_SET[v]["user_name"] + '</span><span class="commentLang">(' + translateFormField(COMMENT_SET[v]["language_code"],"Lang_long") +')</span>'+ thisSITE_TEXT["ST14F"]+':<span class="commentRating">' + rating_builder + '</span></dt><dd>' + COMMENT_SET[v]["comment_text"]+ '</dd></dl>';
							comment_builder = comment_builder + '<p class="commentBase"><img src="graphics/bg_comments_tag.gif" width="16" height="13" alt="#" /></p>';
						   comment_rate = parseInt((comment_rate + parseInt(COMMENT_SET[v]["rating"])));
						   comment_filter_str = "Show " + thisLanguageChoice;
						   		if (COMMENT_SET[v]["rating"]>0){
								 rate_count++;
								}
							rate_count_widget++;
						  }
						 
						}
					
					comment_rate = (comment_rate/(rate_count));
					comment_builder = comment_builder + "<\/ol>";
					//title bar
					//thisHTML = thisHTML + '<div id="right_wide" class="bg_book"><p class="first">Comments - <a id="comment_filter" href="#" onclick="doComments(); return false">' + comment_filter_str +'<\/a></p>';
					thisHTML = thisHTML + '<div id="right_wide" class="bg_book">';
					if (thisComments_Filter){
					 thisHTML = thisHTML + thisSITE_TEXT["ST14A"]  ;
						}else{
					 thisHTML = thisHTML + thisSITE_TEXT["ST14B"]  ;
					}
					
					
					if (rate_count==0){
					 comment_rate =0;	
					 	//left col	
					thisHTML = thisHTML + '<div id="left_col">' + thisSITE_TEXT["ST14D"]  + ' = Not rated'    ;
						}else{
							//left col	
							//var ave_rating_builder = '<div id="stars-wrapperAVE"><select name="Comment_Rating">';
							//var option_builder = "";
								//for (i=0;i<=5;i++){
									//  if (i==Math.round(comment_rate)){
									//  option_builder = option_builder + '<option value="'+i+'" selected="selected">'+i+'</option>';
									  //}else{
									 //  option_builder = option_builder + '<option value="'+i+'">'+i+'</option>';}
								 //}
							//ave_rating_builder  = ave_rating_builder + option_builder + '</select></div>';
							
					//thisHTML = thisHTML + '<div id="left_col">' + thisSITE_TEXT["ST14D"]  + ave_rating_builder + '&nbsp;(' + rate_count + ' votes, ' + comment_rate.toFixed(1) + ')'  ;
					thisHTML = thisHTML + '<div id="left_col"><strong>' + thisSITE_TEXT["ST14D"]  + ' = ' + comment_rate.toFixed(1) + '</strong>';
					}
					//left col	
					//thisHTML = thisHTML + '<div id="left_col">' + thisSITE_TEXT["ST14D"]  + ' = '+ comment_rate.toFixed(1)   ;
					
					thisHTML = thisHTML + "<br>" + thisSITE_TEXT["ST14C"] ;
				  // left comments
				  thisHTML = thisHTML + comment_builder ;
				  // left add comment link
				  //thisHTML = thisHTML + '<br>Click <a id="open_commentdialog" href="#" onclick="javascript: openDialog({\'dialog_name\':\'comment\'}); return false;">here</a> to add your comment on this book<\/div>';
				  if (rate_count>0){
				   thisHTML = thisHTML + thisSITE_TEXT["ST14C"] ;
				  }
				  thisHTML = thisHTML + '<\/div>';
				  //right col	
				  thisHTML = thisHTML + 	'<div id="right_col"><div id="rh_panel_top"></div><div id="rh_panel_content"><table><tbody><tr><td><div id="shadow"><img src="images/' + thisTitleChoice + '_ATB_IMG.jpg" alt="Cubanos 50 Years of Revolution"></div></td></tr></tbody></table></div><div id="rh_panel_bottom"></div><\/div><\/div>';
				
				
				
				
				break;
				
					// Book page - Buy the Book state
				case 110:
				 var thisSelectDiv = 'book_links_block';
				 var thisSelectID ='BTB';
					switch (thisLanguageChoice) {
					 case "fr":
					thisHTML = thisHTML + '<div id="right_wide" class="bg_book"><p class="first">FR: Thank you your request has been sent. We will contact you shortly.</p><p>thePicture</p></br>Please contact us at: <a href="mailto:recommend@thePicture.co.uk">recommend@thePicture.co.uk</a><\/div>';
					 break;
					 case "es":
					thisHTML = thisHTML + '<div id="right_wide" class="bg_book"><p class="first">ES: Thank you your request has been sent. We will contact you shortly.</p><p>thePicture</p></br>Please contact us at: <a href="mailto:recommend@thePicture.co.uk">recommend@thePicture.co.uk</a><\/div>';
					 break;
					case "de":
					thisHTML = thisHTML + '<div id="right_wide" class="bg_book"><p class="first">DE: Thank you your request has been sent. We will contact you shortly.</p><p>thePicture</p></br>Please contact us at: <a href="mailto:recommend@thePicture.co.uk">recommend@thePicture.co.uk</a><\/div>';
					 break;
					default :
					thisHTML = thisHTML + '<div id="right_wide" class="bg_book"><p class="first">GB: Thank you your request has been sent. We will contact you shortly.</p><p>thePicture</p></br>Please contact us at: <a href="mailto:recommend@thePicture.co.uk">recommend@thePicture.co.uk</a><\/div>';
					break;
				
					// Book page - Buy the Book state
				 }
		break;
		}
		 var thisMenuChoice = "top_nav3";
		break;
		case 11:
		var thisHTML = '<div id="left_wide">' + getTitleDetail(thischoice)  + thisSITE_TEXT["ST7LA"] + '<div id="left_wide_bottom">';
		thisHTML = thisHTML + '<div id="book_links_block"><ul><li>- <a onclick="getContent(9, ' + thischoice + ');" href="#">'+ thisSITE_NAV["NAVB1"] + '<\/a><\/li><li>- <a onclick="getContent(8, ' + thischoice + ');" href="#">'+ thisSITE_NAV["NAVB2"] + '</a></li><li>- <a onclick="getContent(10, ' + thischoice + ');" href="#">'+ thisSITE_NAV["NAVB3"] + '<\/a><\/li><li>- <a onclick="getContent(11, ' + thischoice + ');" href="#">'+ thisSITE_NAV["NAVB4"] + '<\/a><\/li><\/ul><\/div><\/div><\/div>';
		thisHTML = thisHTML + '<div id="right_narrow" class="tighter_text">BOOK INFORMATION HERE<\/div>';
		break;
		}
		
		switch (thisnum){
		 case 100: //Do nothing no html to update
		  break
		 default://Update content div
		 var tc = "";
		 if (thisTitleChoice !=="xxx"){var tc = "&title_code=" + thisTitleChoice;}
		 //if(thischoice != 0){ tc = "&title_code=" + thischoice;}
		 thisHTML = thisHTML + '<ol class="subNav" id="subNav6"><li><a href="?state=view_000&lang=gb&page=100' + tc + '" onmouseover="getSubNav(\'subNav6\');"  onmouseout="getSubNav();">English</a><\/li><li><a  href="?state=view_000&lang=es&page=100' + tc + '" onmouseover="getSubNav(\'subNav6\');"  onmouseout="getSubNav();">Espa&ntilde;ol</a><\/li><li><a href="?state=view_000&lang=de&page=100' + tc+  '" onmouseover="getSubNav(\'subNav6\');"  onmouseout="getSubNav();">Deutsch</a><\/li><li><a  href="?state=view_000&lang=fr&page=100' + tc + '" onmouseover="getSubNav(\'subNav6\');"  onmouseout="getSubNav();">Fran&ccedil;ais</a><\/li><\/ol>';
		  thisContent.obj.innerHTML = thisHTML;
			//ok are we on the coment list page?
			if (thisnum==13){
			  for(i=0;i<rate_count_widget;i++){
				  var str = "#stars-wrapper"+i;
				  $(str).stars({
								inputType: "select",
								disabled: true
				  });
			  }
			    var str = "#stars-wrapperAVE";
				  $(str).stars({
								inputType: "select",
								disabled: true
				  });
			  
			}
		  if (thisnum != 0) { getMainNav();  }
		  getSubNav();
		  if (thisSelectDiv) { setSelected(thisSelectDiv,thisSelectID,'selected');}
		  break;
		}
	if(thisMenuChoice) {setSelected("top_nav",thisMenuChoice,'selected');}
	}

// Array to use to translate form fields
function translateFormField(v1, v2) {
 var arrFormField = [];
 arrFormField["es"] = [[]];
	arrFormField["es"]["Full_name"] = "Nombre completo";
	arrFormField["es"]["Country"] = "País de residencia";
	arrFormField["es"]["Email"] = "Dirección de correo electrónico";
	arrFormField["es"]["Telephone"] = "Teléfono (prefijo nacional incluido)";
	arrFormField["es"]["Language"] = "Idioma preferido";
	arrFormField["es"]["Title"] = "Título del libro";
	arrFormField["es"]["Description"] = "Breve descripción del libro";
	arrFormField["es"]["Address1"] = "Dirección";
	arrFormField["es"]["Postcode"] = "Código postal";
	arrFormField["es"]["Comment_Text"] = "Revisión";
	arrFormField["es"]["User_Name"] = "Nombre";
	arrFormField["es"]["Lang_long"] = "Español";
	arrFormField["es"]["captcha_code"] = "Código";
arrFormField["gb"] = [[]];
	arrFormField["gb"]["Full_name"] = "Full name";
	arrFormField["gb"]["Country"] = "Country";
	arrFormField["gb"]["Email"] = "Email";
	arrFormField["gb"]["Telephone"] = "Telephone";
	arrFormField["gb"]["Language"] = "Language";
	arrFormField["gb"]["Title"] = "Title of book";
	arrFormField["gb"]["Description"] = "Brief description";
	arrFormField["gb"]["Address1"] = "Address";
	arrFormField["gb"]["Postcode"] = "Postcode";
	arrFormField["gb"]["Comment_Text"] = "Review";
	arrFormField["gb"]["User_Name"] = "Name";
	arrFormField["gb"]["Lang_long"] = "English";
	arrFormField["gb"]["captcha_code"] = "Code";
arrFormField["fr"] = [[]];
	arrFormField["fr"]["Full_name"] = "Votre nom complet";
	arrFormField["fr"]["Country"] = "Pays de résidence";
	arrFormField["fr"]["Email"] = "Adresse e-mail";
	arrFormField["fr"]["Telephone"] = "Téléphone";
	arrFormField["fr"]["Language"] = "Langue désirée";
	arrFormField["fr"]["Title"] = "Titre du livre";
	arrFormField["fr"]["Description"] = "Brève description du livre";
	arrFormField["fr"]["Address1"] = "Adresse";
	arrFormField["fr"]["Postcode"] = "Code postal";
	arrFormField["fr"]["Comment_Text"] = "Critiques";
	arrFormField["fr"]["User_Name"] = "Votre nom";
	arrFormField["fr"]["Lang_long"] = "Français";
	arrFormField["fr"]["captcha_code"] = "Code";
arrFormField["de"] = [[]];
	arrFormField["de"]["Full_name"] = "Ihr vollständiger Name";
	arrFormField["de"]["Country"] = "Land Ihres Wohnsitzes";
	arrFormField["de"]["Email"] = "Email-Adresse";
	arrFormField["de"]["Telephone"] = "Telefon";
	arrFormField["de"]["Language"] = "Bevorzugte Sprache";
	arrFormField["de"]["Title"] = "Buchtitel";
	arrFormField["de"]["Description"] = "Kurzbeschreibung des Buches";
	arrFormField["de"]["Address1"] = "Adresse";
	arrFormField["de"]["Postcode"] = "PLZ:";
	arrFormField["de"]["Comment_Text"] = "Bewertungen";
	arrFormField["de"]["User_Name"] = "Name";
	arrFormField["de"]["Lang_long"] = "Deutsch";
	arrFormField["de"]["captcha_code"] = "Code";
	
	return arrFormField[v1][v2];
	}

//REMOTE DATA FUNCTIONS	
 function JQdoDataAction(state,params){
   var  strAjaxPage = "ajax_data.php";
   var sUrl = strAjaxPage; 
	switch (state){
	 case 'check_discount':
	  var str = $("#frm_checkdiscount").serialize();
	  var pars = '&state=' + state + '&' +str +  '&lang=' + thisLanguageChoice + '&rnd='+ Math.random( );	
	  sUrl = sUrl + "?" + pars;
	  jQuery.getJSON( sUrl, function(data){
						for (v in thisPortfolio_Collection){
						 	if (thisPortfolio_Collection[v]["TitleCode"]==thisTitleChoice){
							var this_title = thisPortfolio_Collection[v]["TitleLong"];
							 var this_author = thisPortfolio_Collection[v]["TitleAuthor"];
							 var this_price = thisPortfolio_Collection[v]["Price"];
							 }
						 } 
						
						var build_str =  "<div id='order_butt_page'><p class='order_butt_title'>" + this_title + "</p><p class='order_butt_author'>" + this_author + "<\/p>";
						build_str = build_str +"<p class='order_butt_price'>" + this_price + "<\/p>";
							//if (data.discount_text[0].amount!="0"){
							 build_str = build_str +"<p class='order_butt_discount'>" + data.discount_text[0].description+"<\/p>";
							//}
						build_str = build_str +"<p>"+thisSITE_TEXT["ST11M"]+"<\/p><table class='order_butt_table'>";
								for (v in data.book_buttons_text){
								 build_str = build_str + '<tr><td><form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="paypal" id="frm_' + data.book_buttons_text[v].paypal_id + '"><input type="hidden" value="_s-xclick" name="cmd"/><input type="hidden" value="http://www.thepicture.co.uk" name="return"/><input type="hidden" value="'+data.book_buttons_text[v].paypal_id +'" name="hosted_button_id"/><a onclick="submitMe(\''+data.book_buttons_text[v].paypal_id +'\');" href="javascript:nada();"><table><tr><td>' + data.book_buttons_text[v].butt_text + '<\/td><\/tr><\/table><\/a><\/form><\/td><td>' + data.book_buttons_text[v].help_text  + '<\/td><\/tr>' ;		
								}
						build_str = build_str + "<\/table><p>"+thisSITE_TEXT["ST12M"]+"<\/p><\/div>";
						
						$("#dialog_orderalert").html(build_str);
						$("#dialog_orderalert").dialog('option', 'buttons', { "Cancel": function() { $(this).dialog("close"); } });
						
						}
					)
	  break;
	 case 'view_title':
	  //Set the global variable for choosen title
	  thisTitleChoice = params.title_code;
	  var pars = '&state=' + state + '&title_code=' + params.title_code +  '&lang=' + params.lang + '&rnd='+ Math.random( );	
	  sUrl = sUrl + "?" + pars;
	  jQuery.getJSON( sUrl, function(data){
							DATA_READY_FLAG = setArrays(data);								
						}
					)
	  break;
	  case 'view_rand_title':
			if (params.title_code=="xxx") {
			 var pars = '&state=' + state  + '&rnd='+ Math.random();	
			}else{
			 var pars = '&state=' + state  + '&title_code=' + params.title_code + '&rnd='+ Math.random();
			 thisStickyTitleChoice = "xxx"; // Set back to empty
			}
	 	
	    sUrl = sUrl + "?" + pars;
	    jQuery.getJSON( sUrl, function(data){	
							DATA_READY_FLAG = setArrays(data);
						}
					)
	  break;
	 case 'email_contributor':
		var reqFields = ['#Full_name', '#Country', '#Email', '#Telephone', '#Title', '#Description'];
		var chk = true;
		 $.each(reqFields, function(n, value) {
				if (chk){
				var name = $.name; 
				var j = $(value).val();
				if (j == "") {
					alert(translateFormField(thisLanguageChoice, $(value).attr("name")) + " " + thisFieldRequiredText[thisLanguageChoice.toUpperCase()] );
					
					//alert(translateFormField(thisLanguageChoice, $(value).attr("name")));
					 chk = false;
					 
				}
				}
			});		
	   	if (chk){
	   	 var str = $("#frm_contributor").serialize();
		 var pars = '&state=' + state + '&' + str + '&rnd='+ Math.random( );
		 sUrl =  "ajax_email.php?" + pars;
		 $.post(sUrl,function(data){
			if (data.indexOf('Thank')!==-1){
				 //Email good (prob); 
				  getContent(44,0)
				}else{
				 //Email bad (prob); 
				 alert(data);	
				}
			
		   }, "text");
	
		}
	    
	  break;
	 case 'email_order':
	  var reqFields = ['#Full_name','#Address1','#Postcode','#Country','#Telephone','#Email', '#Title'];
		var chk = true;
		 $.each(reqFields, function(n, value) {
				if (chk){
				var name = $.name; 
				var j = $(value).val();
				if (j == "") {
					alert(translateFormField(thisLanguageChoice, $(value).attr("name")) + " " + thisFieldRequiredText[thisLanguageChoice.toUpperCase()]  );
					 chk = false;
				}
				}
			});		
	   	if (chk){
	   	 var str = $("#orderForm").serialize();
		 var pars = '&state=' + state + '&' + str + '&rnd='+ Math.random( );
		 sUrl =  "ajax_email.php?" + pars;
		 $.post(sUrl,function(data){
			if (data.indexOf('Thank')!==-1){
				 //Email good (prob); 
				  getContent(110,params.title_code);
				}else{
				 //Email bad (prob); 
				 alert(data);	
				}
		   }, "text");
		}
	  break;
	case 'cre_comment':
		var reqFields = ['#User_Name', '#Comment_Text' , '#Captcha_Code'];
		var chk = true;
		 $.each(reqFields, function(n, value) {
				if (chk){
				//alert(value);
				var j = $(value).val();
				if (j == "") {
					alert(translateFormField(thisLanguageChoice, $(value).attr("name")) + " " + thisFieldRequiredText[thisLanguageChoice.toUpperCase()]  );
					 chk = false;
				}
				}
			});
		if (chk){
		 var is_registered = true;
			if (is_registered){
				if (confirm(thisSITE_TEXT["ST14R"])){
					var str = $("#commentForm").serialize();
		 			var pars = '&state=' + state + '&title_code=' + thisTitleChoice +   '&lang=' + thisLanguageChoice +  '&rnd='+ Math.random( );
		 			sUrl =  "ajax_data.php?" + pars;
					  $.post(sUrl,$("#commentForm").serialize(),function(data){
						if (data.err == true){
						 alert(data.err_message);
						}else{
						 COMMENT_SET= data.comment_set;
						 getContent(13,thisTitleChoice);
						 $("#commentForm").clearForm();
						 $("#dialog_comment").dialog('close');
						}
					   }, "json");
			    }
			}else{
			// alert("Sorry you need to register first");
			 alert(thisSITE_TEXT["ST14R"]);
			}	
		}
		
	break;
	case 'check_email':
	 //var str = $("#commentForm").serialize();
	 var pars = '&state=' + state + '&title_code=' + thisTitleChoice +   '&lang=' + thisLanguageChoice +  '&rnd='+ Math.random( );
	 sUrl =  "ajax_data.php?" + pars;
	 $.post(sUrl,$("#emailCheckForm").serialize(),function(data){
			if (data.err == true){
			// alert(data.err_message);
			alert(thisSITE_TEXT["ST14Q"]);
			
			}else{
			  $("#emailCheckForm").hide();
		 	  $("#commentForm").show();
			 //COMMENT_SET= data.comment_set;
			 //getContent(13,thisTitleChoice);
			 //$("#commentForm").clearForm();
			 //$("#dialog_comment").dialog('close');
			}
		}, "json");
	 break;
   } 
}


function doComments(){
  if (thisComments_Filter){
   thisComments_Filter = false;
  }else{
   thisComments_Filter = true;
  }
  getContent(13,thisTitleChoice);
 // $("#comment_filter").html("");	
}

function getAppData(thisType, params) {
 //alert(thisType + params.page_no + params.page_choice)
 var territory = thisType;
  DATA_READY_FLAG = false;
  JQdoDataAction(thisType,params);
  updatePageWhenReady(params);
 return "";
}

function setArrays(objData){
 DATA_READY_FLAG = false;
	 switch(objData.state){
	  case 'view_rand_title':
	     RANDOM_TITLE =  objData.random_title;
		 
		 DATA_READY_FLAG = true;
	   break;
	  case 'view_BTBTB':
	  case 'view_BTATB':
	  case 'view_BTATA':
	  case 'view_title': 
		 PORTFOLIO_IMAGE_SET = objData.portfolio_image_set;
		 BOOK_TEXT = objData.book_text;
		 COMMENT_SET= objData.comment_set;
		 DATA_READY_FLAG = true;
	   break ;
    }
 return DATA_READY_FLAG;
}

function updatePageWhenReady(params){
	if (DATA_READY_FLAG) {
	  //doPage(page_type);
	  //alert("updatePageWhenReady params_page_no = " + params.page_no)   
	  getContent(params.page_no, params.page_choice)
	 } else {        
	 
	 setTimeout("updatePageWhenReady({'page_no':" + params.page_no + ",'page_choice':'" + params.page_choice + "'})",500);     
	 }
 }
 //JQUERY function/plugins
 $.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};