/* Image makeBodyPix functions modif for W3G 
05-12 added var MigImgPath 
DVA CLEANUP 04-12-08 of 03-12-08  
DVA Added function zoomWindow 18-12-08
IIC Added ara language URL replacement + "_" replacement
DVA 06-04-11 Added function w3gurl - replaces old code above for legacy Photo URL replacement
*/
function hidemail(name,part1,part2,visiblelink)
{
	if(visiblelink){
		visiblelink=visiblelink;
	}
	else{
		visiblelink="E-mail";
	}
	HTML="<a href='mailto:";
	HTML+=name+ "@" + part1 + "." + part2 + "'>";
	show=visiblelink + "</a>"
	return HTML + show;
}

function w3gurl(imgurl) {
var pathArray = imgurl.split("/");
switch(pathArray[3].toLowerCase())
{
	case "siteeng0.nsf" :
	MigImgPath = "/eng/assets/images/other/";
	break;
	case "sitefre0.nsf" :
	MigImgPath = "/fre/assets/images/other/";
	break;
	case "siteara0.nsf" :
	MigImgPath = "/ara/assets/images/other/";
	break;
	case "sitespa0.nsf" :
	MigImgPath = "/spa/assets/images/other/";
	break;
	case "sitepor0.nsf" :
	MigImgPath = "/por/assets/images/other/";
	break;
	case "siterus0.nsf" :
	MigImgPath = "/rus/assets/images/other/";
	break;
	case "sitechi0.nsf" :
	MigImgPath = "/chi/assets/images/other/";
	break;
	default :
	MigImgPath = "";  // legacy image path is not any above then keep the original 
}  //END SWITCH

if (MigImgPath != "")
{
var srcString = MigImgPath + pathArray[7].toLowerCase(); 
return(srcString);
}
else {
return(imgurl.toLowerCase());
} // END IF
} // END FUNCTION w3gurl

function makeBodyPix(position,imgWidth,ImgFileURL,ImgAlt,credit,caption,zoomImg,zoomImgAlt,zoomSize,zoom,codetest) 
{ 
// strip blank spaces
position = position.replace(/\s+/g,'');
imgWidth = imgWidth.replace(/\s+/g,'');
ImgFileURL = ImgFileURL.replace(/\s+/g,'_');
credit = credit.replace(/\s+/g,'');
caption = caption.replace(/\s+/g,'');
zoomImg = zoomImg.replace(/\s+/g,'_');
zoomSize = zoomSize.replace(/\s+/g,'');
zoom = zoom.replace(/\s+/g,'');

/* Test for version with DIV and errors 
NOTE 04-12 08 SAVE FOR NOW FOR OLDER VERSIONS OF Encadre function with photos */
try
{
credit= document.getElementById(credit).innerHTML;
}
catch (errMsg){onerror=null;
}
try
{
caption= document.getElementById(caption).innerHTML;
}
catch (errMsg){onerror=null;}


var basicHTML = "";
var insetHTML = "";
var ImgFileURL = w3gurl(ImgFileURL);  //06-04-11 NEW Migration image path - Medium
var captionstuff = "<p>"+caption+"<br /><span class='grey'>"+credit+"</span></p>";

/* CK IF no caption */
if (caption == "" | caption == "&nbsp;")
	{
	//alert("NO CAPT");
	var captionstuff = "<p><span class='grey'>"+credit+"</span></p>";
	altstuff = credit;
	caption = "&nbsp;";
	}

if (credit == "")
	{
	//alert("NO CAPT");
	credit = ImgAlt;
	}


/* CK IF NEITHER credit nor caption */
if (caption == "" & credit == "")
	{
	var captionstuff = "";
	altstuff = ImgAlt;
	}

var altstuff = caption+" "+credit;

/* CK IF ZOOM */
if (zoom.toLowerCase()!="yes" ) 
	{ 
	//NO ZOOM 
	basicHTML = "<img width='" + imgWidth + "' src='"+ImgFileURL+"' longdesc='' title='"+credit+"' alt='"+altstuff+"'/><span/>"+captionstuff;
	}
		else 
	{
	//YES ZOOM 
	var zoomImg = w3gurl(zoomImg);//06-04-11 NEW Migration image path - Zoom size

	basicHTML = "<a href='"+zoomImg+"' rel='lightbox' class='magnify' title='"+caption+"'><img width='" + imgWidth + "' src='"+ImgFileURL+"' longdesc='' title='"+credit+"' alt='"+caption+"'/><span> </span></a>"+captionstuff;
	}

/* NOTE PROBLEMS WITH LIGHTBOX JS- The IMG attibute LONGDESC is used for Download path/link in lightBox display. 
DVA modified the LightBox JS to test if longdesc EMPTY, then no Download link displayed. 
ALSO NOTE - The IMG attibute TITLE is used for the Credit text in lightBox display. 
So, no way to set ALT without this text being used as the Credit text in LightBox display. */

insetHTML = "<div class='insetimage'>" + basicHTML + "</div>";

/* CK CODE - works OK only in IE not FF */
if (codetest=="yes") 
	{
	var MyAnswer = "";
	MyAnswer = prompt("Check code",insetHTML);
		if (MyAnswer) 
			{
			//alert (MyAnswer);
			return insetHTML;
			}
			else {
			return insetHTML;
			}
	}
//END CK CODE

/* CK IF left OR right THEN USE insetHTML IN BODY  
IF nofloat THEN USE basicHTML for COLUMN leg2 */

if (position.toLowerCase()=="right" | position.toLowerCase()=="left"){
		return insetHTML;
	}
	else {
		return basicHTML;
	}
//END CK

}  
/* END function MakeBodyPix */


/* DVA Added function zoomWindow 18-12-08  */
function zoomWindow(imgurl,winname,w,h) {
windowleft = (screen.width - w)/40;
windowtop = (screen.height - h)/20;
myImage = "<a href=\"javascript:window.close()\"><img src=\""+imgurl+"\" border=0></a>";
myBody = "<html><head><title>zoom</title></head><body bgcolor=\"#000000\"  leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"+myImage+"</body></html>";
settings = '"toolbar=no,directories=no,menubar=0,scrollbars=no,resizable=no,status=no,width='+w+',height='+h+ ',left='+windowleft+',top='+windowtop+'"';
closeZoomWindow();
newWin = window.open("",winname,settings);
newWin.document.write(myBody);
newWin.document.close();
newWin.focus();
}

function closeZoomWindow() {
if (newWin && !newWin.closed) {
newWin.close();}
}

