// JavaScript Document
//need global var to save the large image source in?
window.self.defaultStatus="Jon Cruttenden Photography - welcome to the website";

function errmsg(message,url,line) {
	
	var errmsg="";
	
	errmsg+="JAVASCRIPT ERROR" +"\n";
	errmsg+=" Error Message: " + message +"\n"; 
	errmsg+=" URL: " + url +" \n";
	errmsg+="Line#: " + line +"\n";
	errmsg+="Please contact the webmaster about this error";
	alert (errmsg);
	return true;
	
	}
//=======================================================
window.onerror = errmsg;
//=======================================================
// Dynamic Iframe loader
function loadIframe(theURL) {
	document.getElementById("press_box").src=theURL;
}

// resizes Iframe according to content
function resizeMe(obj){ 
//alert("resize");
docHeight = press_box.document.body.scrollHeight + 10;
 obj.style.height = docHeight + 'px';
 } 

//======================================================
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function clear_text(){
	// clear the phobia name and description boxes when user types new search term
	var P = (document.all) ? document.all("txtphobia") : document.getElementById("txtphobia");// the phobia name text box
	var D = (document.all) ? document.all("txtdescription") : document.getElementById("txtdescription"); //the the phobia description text box
	(P.value="") ? P.value="" : P.value="";
	(D.value="") ? D.value="" : D.value="";

}

function search_list(srch,phb,desc){  //sends the id names of the text boxes
	// search the DL list of phobias return the name (dt) and description (dd) to the text boxes
//search_list('txtsearch','txtphobia','txtdescription')
// text box elements
	var S = (document.all) ? document.all(srch) : document.getElementById(srch);//the search text input DD
	var P = (document.all) ? document.all(phb) : document.getElementById(phb);// the phobia name text box
	var D = (document.all) ? document.all(desc) : document.getElementById(desc); //the the phobia description text box
// loop through the list in the DD tags only to search for the ENGLISH word
//set the answer box to the corrsponding DT+DD text
	var phobia = document.getElementsByTagName('dt'); //ARRAY OF DT ELEMENTS
	var description = document.getElementsByTagName('dd');  //ARRAY OF DD ELEMENTS
//	alert ("Phobia-search word=" + S.value );
	P.value=""; // clear the answer box
	D.value="";

if (S.value=="" || !S.value){
	alert ("You must enter a search term!");
	S.focus();
	return ;
	}
	
//	alert("index 0:" + description[0].innerHTML + " phobia:" + phobia[0].innerHTML);
	for (var i = 0; i < description.length; i++) {
		var Dsc=description[i].innerHTML; //DD PHOBIA DESCRIPTION
		var Pho=phobia[i].innerHTML; //DT PHOBIA NAME
       
	   if(Dsc.toLowerCase().indexOf(S.value.toLowerCase())>0){  // matched search word or phrase
		//alert ("SEARCH:" + S.value + " PHOBIA NAME:"+ Pho +" DESCRIPTION:" + Dsc + " INDEX: " + i );
	//write the values
	P.value=Pho;
	D.value=Dsc;
	S.focus();
	return ;
	}
     }
	alert ("Search Term:\n '"+ S.value + "'\n not found!\n \nPlease try again!");
	S.focus();
	return; // dont actually submit the form
	}
	
function change_font(elemID) {
var elem = (document.all) ? document.all(elemID) : document.getElementById(elemID);
var fnt = (document.all) ? document.all("fontlist") : document.getElementById("fontlist");
var sz = (document.all) ? document.all("sizelist") : document.getElementById("sizelist");

//fnt=document.getElementById("fontlist");
//sz=document.getElementById("sizelist");
//obj=document.getElementById(id);
//alert ("elem=" + elemID+" Class=" +elem.className+" FONT=" + fnt.value + " SIZE=" + sz.value);
//elem.style.fontFamily=fnt.value;
elem.className=fnt.value;
elem.style.fontSize=sz.value+"px";
}
function secure_link(pg){
//access the page through a secure LINUX HOSTING channel
var Lnk="https://secure.hosts.co.uk/~joncruttendenphotography.co.uk/"+pg;
window.location.href=Lnk;
}
function show_pic(img){
// CONVENTIONS: whole filepath sent
//THUMBNAILS HAVE THE SAME FILENAME AS THE ORIGINAL
//PHP GLOBAL CONSTANTS _UPLOAD_ & _THUMBS_
//shows thw large picture in the large div when mousing over the thumbnails	
//GET THE FILENAME ONLY FROM THE IMG PATH SENT
// example ./images/thumbs/img.jpg is thumbnail
/// ./images/img.jpg is large image
//pos=img.src.indexOf("thumbs/"); //now remove the directory frm the path to give the full image
//var newpath=img.src.substr(0,pos);
//var newfile=img.src.substr(pos+7);	
//	document.getElementById("large_img").src=newpath+newfile;
//=============================================
//img is the IMAGE SOURCE PATH
//try putting image as background to '"large_div"	
var newimg=img; // default path
pos=img.indexOf("thumbs/");
if (pos>0){// is from the UPLOAD directory i.e. 
newimg=img; //LEAVE AS IS - and show the large image
}
pos2=img.indexOf("thmb_"); //both thumb and large image exist in the SAME directory
if (pos2>0){
newimg=img.replace(/thmb_/i, "");//remove the 'thmb_' from the path of the image and show large image
}
var dv=document.getElementById("large_div")	;
if (dv) {
dv.style.border="1px solid #000000";
 dv.style.background=	"#000000 url(" + newimg + ") no-repeat center center";  	
// alert ("NEW IMAGE SOURCE PATH=" + newimg + " <br/> ORIGINAL=" + img);
} else{
//alert ("Error showing image - please contact the webmaster");
}//if
} //fn
	
	function show_blank(){
//on mouseout of thumb put large blank picture in the large image placeholder		
//		document.getElementById("large_img").src="./images/instructions.gif";
var dv=document.getElementById("large_div")	;
if (dv){
	dv.style.border="1px solid #CC3300";
 dv.style.background=	"#000000 url(../images/instructions.gif) no-repeat center top";
} else{
//alert ("Error showing BLANK image - please contact the webmaster");
}//if
}//fn

function resizeMe(obj){ 
//the IFRAME object (obj) is processed to alter the height automatically
//this function is called from the onload event of the iframe
//===================================================
var currentHeight=obj.clientHeight; //FRAME HEIGHT Height ; //obj.offsetHeight; current height of frame
var newdoc=obj.offsetHeight;  // FRAME HEIGHT
var contentDoc=obj.contentDocument;
var contentWin=obj.contentWindow;
var diff=eval(docHeight-currentHeight);
 var docHeight = testimonial.document.body.scrollHeight + 10 ; //DOCUMENT           //scrollHeight + 10;

// var docHeight = magpage_frame.document.body.scrollHeight + 10 ; //DOCUMENT           //scrollHeight + 10;

/* alert( obj.name + 
	   "\n Current FRAME Client Height=" + currentHeight 
	   + "\n newdoc FRAME offsetHeight=" + newdoc 
	   + " \n DOC Scroll Height (pixel height)=" + docHeight
	   +"\n" 
	   + " \n difference = " + diff
	   );*/

 obj.style.height = docHeight+'px'; // + 'px';
 
//  if (docHeight > currentHeight) {
// 	obj.style.height = docHeight+'px'; // + 'px';
//  } else{
//	obj.style.height=docHeight +'px'; // + 'px';             //style.height=currentHeight+'px';
// }
 
 } 
