/*
========================
SCRIPTS DEVELOPED BY: PAUL GARDNER 
codemonkey@backpacker.com
========================
*/

function preloadImages() {
if (document.images)
	{
	var btn_explore_roll = new Image
		btn_explore_roll.src = "images/btn_explore_over.png"
	var btn_whobasquiat_roll = new Image
		btn_whobasquiat_roll.src = "images/btn_whobasquiat_over.png"
	var btn_create_roll = new Image
		btn_create_roll.src = "images/btn_create_over.png"
	var btn_ecard_roll = new Image
		btn_ecard_roll.src = "images/btn_ecard_over.png"
	var btn_whatthink_roll = new Image
		btn_whatthink_roll.src = "images/btn_whatthink_over.png"
	var btn_createown_roll = new Image
		btn_createown_roll.src = "images/btn_createown_over.png"
	var btn_viewgallery_roll = new Image
		btn_viewgallery_roll.src = "images/btn_viewgallery_over.png"
	var btn_seeallartworks_roll = new Image
		btn_seeallartworks_roll.src = "images/btn_seeallartworks_over.png"
	}
}

function preloadHomeImages() {
if (document.images)
	{
	var btn_exploreH_roll = new Image
		btn_exploreH_roll.src = "images/btn_exploreH_over.png"
	var btn_whobasquiatH_roll = new Image
		btn_whobasquiatH_roll.src = "images/btn_whobasquiatH_over.png"
	var btn_createH_roll = new Image
		btn_createH_roll.src = "images/btn_createH_over.png"
	var btn_ecardH_roll = new Image
		btn_ecardH_roll.src = "images/btn_ecardH_over.png"
	var btn_whatthinkH_roll = new Image
		btn_whatthinkH_roll.src = "images/btn_whatthinkH_over.png"
	}
}


function changeImages(sName,sImage)
	{
	if (document.images)
		{
		document.images[sName].src = sImage
		}
	}

function openWindow(theURL,winName,features)
	{
	window.open(theURL,winName,features).focus();
	}

function closeWindow()
	{
	window.close();
	}

if (document.layers)
	{
	origWidth = innerWidth;
	origHeight = innerHeight;
	}
function reloadPage()
	{
	if (innerWidth != origWidth || innerHeight != origHeight)
	location.reload();
	}
if (document.layers)
	onresize=reloadPage;
	
function goHistory()
	{
	window.history.go(-1);
	}

for (i=1; i<11; i++)
	{
	tempVar="image_title";
	tempVar[i]="";
	}
	
var replaceChars=new Array();
replaceChars[0]=/''/g;

for (i=1; i<35; i++)
	{
	replaceChars[i]=eval("/&button_text"+((i-1)+1)+"=/g");
	}

for (i=10; i<35; i++)
	{
	replaceChars[i]=eval("/&popup_text"+((i-10)+1)+"=/g");
	}

for (i=35; i<45; i++)
	{
	replaceChars[i]=eval("/&image_title"+((i-35)+1)+"=/g");
	}

for (i=45; i<55; i++)
	{
	replaceChars[i]=eval("/&image_caption"+((i-45)+1)+"=/g");
	}

for (i=55; i<65; i++)
	{
	replaceChars[i]=eval("/&image_url"+((i-55)+1)+"=/g");
	}

for (i=65; i<75; i++)
	{
	replaceChars[i]=eval("/&image_width"+((i-65)+1)+"=/g");
	}

for (i=75; i<85; i++)
	{
	replaceChars[i]=eval("/&image_height"+((i-75)+1)+"=/g");
	}

replaceChars[85]=/&what_think=/g;
replaceChars[86]=/&more_paintings=/g;
replaceChars[87]=/&url_whatthink=/g;
replaceChars[88]=/&url_morepaintings=/g;
replaceChars[89]=/&back_up=/g;
replaceChars[90]=/&url_backup=/g;
replaceChars[91]=/&back_tothemes=/g;
replaceChars[92]=/&url_backtothemes=/g;

replaceChars[93]=/&image_num=/g;
replaceChars[94]=/&button_num=/g;
replaceChars[95]=/&popup_num=/g;
replaceChars[96]=/&text_num=/g;

for (i=97; i<107; i++)
	{
	replaceChars[i]=eval("/ADDTITLE"+((i-97)+1)+"/g");
	}

replaceChars[107]=/\|aacute/g;
replaceChars[108]=/\|eacute/g;
replaceChars[109]=/\|iacute/g;
replaceChars[110]=/\|oacute/g;
replaceChars[111]=/\|uacute/g;
replaceChars[112]=/\|Aacute/g;
replaceChars[113]=/\|Oacute/g;
replaceChars[114]=/\|iquest/g;
replaceChars[115]=/\|copy/g;
replaceChars[116]=/\|ntilde/g;
replaceChars[117]=/\|quot/g;
replaceChars[118]=/\|circ/g;
replaceChars[119]=/\|Uacute/g;
replaceChars[120]=/\|/g;
replaceChars[121]=/--/g;
replaceChars[122]=/<u>/g;
replaceChars[123]=/<\/u>/g;

for (i=124; i<219; i++)
	{
	replaceChars[i]=eval("/&text_item"+(i-123)+"=/g");
	}

function updateVariable(var_id)
	{
	this[var_id]=this[var_id].replace(replaceChars[0], "&quot;");
	for (i=1; i<97; i++)
		{
		this[var_id]=this[var_id].replace(replaceChars[i], "");
		}
	if (button_num !="none")
		{
		for (i=97; i<107; i++)
			{
			if (button_num>=(i-96))
				{
				this[var_id]=this[var_id].replace(replaceChars[i], "<strong>"+eval('button_text'+(i-96))+"</strong>");
				}
			}
		}
	
	this[var_id]=this[var_id].replace(replaceChars[107], "&aacute;");
	this[var_id]=this[var_id].replace(replaceChars[108], "&eacute;");
	this[var_id]=this[var_id].replace(replaceChars[109], "&iacute;");
	this[var_id]=this[var_id].replace(replaceChars[110], "&oacute;");
	this[var_id]=this[var_id].replace(replaceChars[111], "&uacute;");
	this[var_id]=this[var_id].replace(replaceChars[112], "&Aacute;");
	this[var_id]=this[var_id].replace(replaceChars[113], "&Oacute;");
	this[var_id]=this[var_id].replace(replaceChars[114], "&iquest;");
	this[var_id]=this[var_id].replace(replaceChars[115], "&copy;");
	this[var_id]=this[var_id].replace(replaceChars[116], "&ntilde;");
	this[var_id]=this[var_id].replace(replaceChars[117], "&quot;");
	this[var_id]=this[var_id].replace(replaceChars[118], "&circ;");
	this[var_id]=this[var_id].replace(replaceChars[119], "&Uacute;");
	this[var_id]=this[var_id].replace(replaceChars[120], "&amp;");
	this[var_id]=this[var_id].replace(replaceChars[121], "&#151;");
	this[var_id]=this[var_id].replace(replaceChars[122], '<span style="text-decoration:underline;">');
	this[var_id]=this[var_id].replace(replaceChars[123], "</span>");
	
	for (i=124; i<219; i++)
		{
		this[var_id]=this[var_id].replace(replaceChars[i], "");
		}
		
	return this[var_id];
	}
	
date1=false;
date2=false;
date3=false;
month1a=2;//changed from 3
month1b=6;
day1a=10;
day1b=6;
month2a=7;
month2b=10;
day2a=15;
day2b=9;
month3a=11;
month3b=2;
day3a=18;
day3b=12;
year1=2005;
year2=2006;

function todaysDate()
	{
	today=new Date();
	thisDay=today.getDate();
	thisMonth=today.getMonth()+1;
	thisYear=today.getYear();
	}
todaysDate();

if (thisYear<1000)
	{
	thisYear+=1900;
	}

if (((thisMonth>month1a || (thisMonth==month1a && thisDay>day1a)) && (thisMonth<month1b || (thisMonth==month1b && thisDay<month1b))) && thisYear==year1)
	{
	date1=true;
	}
	
if (((thisMonth>month2a || (thisMonth==month2a && thisDay>day2a)) && (thisMonth<month2b || (thisMonth==month2b && thisDay<month2b))) && thisYear==year1)
	{
	date2=true;
	}
	
if ((thisYear==year1 && (thisMonth>month3a || (thisMonth==month3a && thisDay>day3a))) || (thisYear==year2 && (thisMonth<month3b || (thisMonth==month3b && thisDay<day3a))))
	{
	date3=true;
	}
	
function addLogoBrooklyn()
	{
	if (date1==true)
   	 	{document.write('<a href="http://www.brooklynmuseum.org" target="_blank"><img src="images/logo_brooklynblueOn.png" width="170" height="35" alt="Brooklyn Museum logo" border="0" /><\/a>');}
	else
    	{document.write('<a href="http://www.brooklynmuseum.org" target="_blank"><img src="images/logo_brooklynblueOff.png" width="170" height="35" alt="Brooklyn Museum logo" border="0" /><\/a>');}
	}

function addLogoMOCA()
	{
	if (date2==true)
	    {document.write('<a href="http://www.moca.org/index.php" target="_blank"><img src="images/logo_mocablueOn.png" width="80" height="35" alt="MOCA logo" hspace="24" border="0" /><\/a>');}
	else
   	 	{document.write('<a href="http://www.moca.org/index.php" target="_blank"><img src="images/logo_mocablueOff.png" width="80" height="35" alt="MOCA logo" hspace="24" border="0" /><\/a>');}
	}
	
function addLogoMFAH()
	{
	if (date3==true)
    	{document.write('<a href="http://www.mfah.org" target="_blank"><img src="images/logo_mfahblueOn.png" width="98" height="35" alt="MFAH logo" border="0" /><\/a>');}
	else
    	{document.write('<a href="http://www.mfah.org" target="_blank"><img src="images/logo_mfahblueOff.png" width="98" height="35" alt="MFAH logo" border="0" /><\/a>');}
	}
	
function addLogoBrooklynSP()
	{
	if (date1==true)
   	 	{document.write('<a href="http://www.brooklynmuseum.org" target="_blank"><img src="images/logo_brooklynblueOn.png" width="170" height="35" alt="Brooklyn Museum insignia" border="0" /><\/a>');}
	else
    	{document.write('<a href="http://www.brooklynmuseum.org" target="_blank"><img src="images/logo_brooklynblueOff.png" width="170" height="35" alt="Brooklyn Museum insignia" border="0" /><\/a>');}
	}

function addLogoMOCASP()
	{
	if (date2==true)
	    {document.write('<a href="http://www.moca.org/index.php" target="_blank"><img src="images/logo_mocablueOn.png" width="80" height="35" alt="MOCA insignia" hspace="24" border="0" /><\/a>');}
	else
   	 	{document.write('<a href="http://www.moca.org/index.php" target="_blank"><img src="images/logo_mocablueOff.png" width="80" height="35" alt="MOCA insignia" hspace="24" border="0" /><\/a>');}
	}
	
function addLogoMFAHSP()
	{
	if (date3==true)
    	{document.write('<a href="http://www.mfah.org" target="_blank"><img src="images/logo_mfahblueOn.png" width="98" height="35" alt="MFAH insignia" border="0" /><\/a>');}
	else
    	{document.write('<a href="http://www.mfah.org" target="_blank"><img src="images/logo_mfahblueOff.png" width="98" height="35" alt="MFAH insignia" border="0" /><\/a>');}
	}
	
function addComma()
    {
    if (errors>0)
        {
        formMessage+=', ';
        }
    }

function submitForm()
    {
    formMessage="";
    errors=0;
    if (window.document.formContainer.firstname.value=="")
        {
        formMessage+='First Name';
        errors+=1;
        }
    if (window.document.formContainer.email.value=="")
        {
        addComma();
        formMessage+='E-Mail';
        errors+=1;
        }
    else if (!(check_email(window.document.formContainer.email.value)))
        {
        addComma();
        formMessage+='Invalid E-Mail address';
        errors+=1;
        }
    if (window.document.formContainer.message.value=="")
        {
        addComma();
        formMessage+='Message';
        errors+=1;
        }
    if (errors>0)
        {
        alert ('Please fill in these field(s): '+formMessage+'.   ');
        }
    else
       {
       window.document.formContainer.submit();
       }
    }
    
// Email Validation. Written by PerlScriptsJavaScripts.com
function check_email(e) {
  ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
  
  for(i=0; i < e.length ;i++){
    if(ok.indexOf(e.charAt(i))<0){ 
      return (false);
    }	
  } 
  
  if (document.images) {
    re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
    re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (!e.match(re) && e.match(re_two)) {
      return (-1);		
    } 
  }
}
	
function getNoFlashWhoWas(language)
	{
	altFlashContent='<div class="comments">';
	for (h=1; h<(Math.ceil(text_num-10)+1); h++)
		{
		if (h!=6 && h!=7)
			{
			altFlashContent+=updateVariable("text_item"+h);
			}
		else if (h==6)
			{
			if (language=="ENG")
				{
				altFlashContent+=' Who was Basquiat? ';
				}
			else
				{
				altFlashContent+=' &iquest;Qui&eacute;n fue Basquiat? ';
				}
			}
		}
		
	altFlashContent+='<\/div>';
		
	document.write(altFlashContent);
	/*for (h=1; h<(Math.ceil(popup_num)+1); h++)
		{
		document.write('<div>'+updateVariable("popup_text"+h)+'<\/div>');
		}*/
	}
	
function upgradeFlash(language)
	{
	if (language=="ENG")
		{
		currMessage='<p class="comments">This page contains a zoomable image from the Basquiat website. It requires the Flash '+versionNum+'+ plug-in. <a href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" class="maroon12px">Get Flash<\/a> (for free!)<\/p>';
		}
	else
		{
		currMessage='<p class="comments">Esta p&aacute;gina contiene una imagen ampliable tomada del sitio web de Basquiat. Necesita el plug-in '+versionNum+'. <a href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" class="maroon12px">Obtener Flash</a> (&iexcl;gratis!)<\/p>';
		}
	}
	
function getAltWhoWas(language)
	{
	if (language=="ENG")
		{
		currMessage='<p class="comments">This page contains a Flash interactive from the Basquiat website. It requires the Flash '+versionNum+'+ plug-in. <a href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" class="maroon12px">Get Flash<\/a> (for free!)<\/p>';
		}
	else
		{
		currMessage='<p class="comments">Esta p&aacute;gina contiene un R&aacute;pido recíproco del sitio web de Basquiat. Necesita el plug-in '+versionNum+'. <a href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" class="maroon12px">Obtener Flash</a> (&iexcl;gratis!)<\/p>';
		}
	
	currMessage+='<div class="comments">';
	for (h=1; h<(Math.ceil(text_num-14)+1); h++)
		{
		if (h!=6 && h!=7)
			{
			currMessage+=updateVariable("text_item"+h);
			}
		else if (h==6)
			{
			if (language=="ENG")
				{
				currMessage+=' Who was Basquiat? ';
				}
			else
				{
				currMessage+=' &iquest;Qui&eacute;n fue Basquiat? ';
				}
			}
		}
	currMessage+='</div>';
	/*
	for (h=1; h<(Math.ceil(popup_num)+1); h++)
		{
		currMessage+='<div>'+updateVariable("popup_text"+h)+'<\/div>';
		}*/
	updateVariable('currMessage');
	}
	
function getNoFlashContent()
	{
	for (h=1; h<(Math.ceil(image_num)+1); h++)
		{
		document.write('<div><img src="../images/'+updateVariable("image_url"+h)+'" width="'+updateVariable("image_width"+h)+'" height="'+updateVariable("image_height"+h)+'" alt="'+updateVariable("image_title"+h)+'" \/><\/div>');
		document.write('<div class="caption"><strong>'+updateVariable("image_title"+h)+'</strong><br />'+updateVariable("image_caption"+h)+'<\/div><div><br /><\/div>');
		}
	}
	
function getAltContent(language)
	{
	upgradeFlash(language);
	
	for (h=1; h<(Math.ceil(image_num)+1); h++)
		{
		currMessage+='<div><img src="../images/'+updateVariable("image_url"+h)+'" width="'+updateVariable("image_width"+h)+'" height="'+updateVariable("image_height"+h)+'" alt="'+updateVariable("image_title"+h)+'" \/><\/div>';
		currMessage+='<div class="caption"><strong>'+updateVariable("image_title"+h)+'</strong><br />'+updateVariable("image_caption"+h)+'<\/div><div><br /><\/div>';
		}
	}
	
function getAltEcardContent(language)
	{
	upgradeFlash(language);
	
	for (h=1; h<(Math.ceil(image_num)+1); h++)
		{
		currMessage+='<div><img src="../images/'+updateVariable("image_url"+h)+'" width="'+updateVariable("image_width"+h)+'" height="'+updateVariable("image_height"+h)+'" alt="'+updateVariable("image_title"+h)+'" \/><\/div>';
		currMessage+='<div class="caption"><strong>'+updateVariable("image_title"+h)+'</strong><br />'+updateVariable("image_caption"+h)+'<\/div><div><br /><\/div>';
		}
	currMessage+='<div><br /><a href="#" onclick="goHistory(); return false" onkeypress="goHistory(); return false" class="maroon12px">'+updateVariable("back_up")+'<\/a><\/div>';
	}
	
function getNoFlashMainContent()
	{
	altFlashContent='<div><img src="../images/'+updateVariable("image_url1")+'" width="'+updateVariable("image_width1")+'" height="'+updateVariable("image_height1")+'" alt="'+updateVariable("image_title1")+'" \/><\/div>';
	altFlashContent+='<div class="caption"><strong>'+updateVariable("image_title1")+'</strong><br />'+updateVariable("image_caption1")+'<\/div><div><br /><\/div>';

	for (h=1; h<(Math.ceil(popup_num)+1); h++)
		{
		altFlashContent+='<div class="comments">'+updateVariable("popup_text"+h)+'<\/div><div><br /><\/div>';
		}
	updateVariable('altFlashContent');
	document.write(altFlashContent);
	}
	
function getAltMainContent(language)
	{
	upgradeFlash(language);
	
	for (h=1; h<(Math.ceil(image_num)+1); h++)
		{
		currMessage+='<div><img src="../images/'+updateVariable("image_url"+h)+'" width="'+updateVariable("image_width"+h)+'" height="'+updateVariable("image_height"+h)+'" alt="'+updateVariable("image_title"+h)+'" \/><\/div>';
		currMessage+='<div class="caption"><strong>'+updateVariable("image_title"+h)+'</strong><br />'+updateVariable("image_caption"+h)+'<\/div><div><br /><\/div>';
		}
		
	for (h=1; h<(Math.ceil(popup_num)+1); h++)
		{
		currMessage+='<div class="comments">'+updateVariable("popup_text"+h)+'<\/div><div><br /><\/div>';
		}
		
	currMessage+='<div><a href="'+updateVariable("url_whatthink")+'" class="maroon12px">'+updateVariable("what_think")+'</a><\/div>';
	currMessage+='<div><br /><a href="'+updateVariable("url_morepaintings")+'" class="maroon12px">'+updateVariable("more_paintings")+'</a><\/div>';
	currMessage+='<div><br /><a href="'+updateVariable("url_backtothemes")+'" class="maroon12px">'+updateVariable("back_tothemes")+'</a><\/div>';
	}

function changeCreateKiosk(name)
	{
	var wholeCookie=document.cookie;
    var firstChar=wholeCookie.indexOf(name);
	if (firstChar != -1)
		{
		window.location.href="create_kiosk.php";
		}
	}
		
function changeHomeKiosk(name)
	{
	var wholeCookie=document.cookie;
    var firstChar=wholeCookie.indexOf(name);
	if (firstChar != -1)
		{
		window.location.href="home_kiosk.html";
		}
	}

function sessionExpired(name)
	{
	var wholeCookie=document.cookie;
    var firstChar=wholeCookie.indexOf(name);
	if (firstChar != -1)
		{
		window.location.href="../kiosk.html";
		}
	}
	
function writeUserLoc(name)
	{
	var wholeCookie=document.cookie;
    var firstChar=wholeCookie.indexOf(name);
	if (firstChar != -1)
		{
		userLocation=", at the exhibition";
		}
	else
		{
		userLocation=", on the Web";
		}
	}
	
function launchExternalLink(name)
	{
	var wholeCookie=document.cookie;
    var firstChar=wholeCookie.indexOf(name);
	if (firstChar == -1)
		{
		window.location.href=currURL;
		}
	}
	
function addBreaks(name,breakNum)
	{
	var wholeCookie=document.cookie;
    var firstChar=wholeCookie.indexOf(name);
	if (firstChar == -1)
		{
		for (i=1; i<eval(Math.floor(breakNum)+1); i++)
			{
			document.write('<div><br /></div>');
			}
		}
	}

var checkTime=window.setTimeout('sessionExpired(\'Basquiat\');', 300000);

// make sure we have a function to trim whitespace from the 
//   start and end of a string:
if (typeof String.prototype.trim == "undefined") {
    String.prototype.trim = function () {
        var s = this.replace(/^\s*/, "");
        return s.replace(/\s*$/, "");
    }
}

// trim whitespace from the start and end of a string:
function trim(s) {
  var str = new String(s);
  str = str.replace(/^\s*/, "");
  str = str.replace(/\s*$/, "");
  return str.valueOf();
}


function resetTimer()
	{
	clearTimeout(checkTime);
	checkTime=window.setTimeout('sessionExpired(\'Basquiat\');', 300000);
	}
