var theDomain = "www.sfae.com/";
var t;
var st;
var holdThePhone = false;
var theBlock = null;
var req = null;
var activeFrame = 1;
var to = null;
var to2 = null;

function closeBalloon(){
	document.getElementById('balloon').style.opacity = 0;
	document.getElementById('balloon').style.top = "-1000px";
}

function disableTextSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

function updateCard1(thePriceID){
	activeFrame = 1;
	serviceCall = 'http://'+theDomain+'/xml/update-card.xml.php?item='+thePriceID;
    loadXMLDoc(serviceCall, processUpdateCard); 
}

function updateCard2(thePriceID){
	activeFrame = 2;
	serviceCall = 'http://'+theDomain+'/xml/update-card.xml.php?item='+thePriceID;
    loadXMLDoc(serviceCall, processUpdateCard); 
}

function processUpdateCard(){ 
            	var data =  req.responseXML.getElementsByTagName('data')[0].firstChild.data;

           	data =  replaceAll(data, "[", "<");
			data =  replaceAll(data, "]", ">");
			// var myString = data;
			// var obs = myString.split("+");
			
			if (activeFrame == 1){
				var target = "";
			} else {
				var target = "2";
			}
			data =  replaceAll(data, "%", target);
			//alert(data);
	document.getElementById("plaque"+target).innerHTML = data;

}

function defineShipping(){
	var e = window.event;
	// alert(e.clientX);
	var theoffset = Math.floor((document.body.clientWidth - 960) / 2);
	var theBalloon = document.getElementById("balloon");
	var thepos = e.clientX - theoffset;
	theBalloon.style.left = (e.clientX - 170) + "px";
	theBalloon.style.top = (e.clientY + 5) + "px";
	theBalloon.style.height = "auto";
	theBalloon.style.opacity = 0;
	//alert(theBalloon.style.top);
	//alert(thepos);
	//alert(document.getElementById("menu-top").style.width);
 //   serviceCall = 'http://'+theDomain+'/xml/terms.xml.php?item='+theTerm;
 //   loadXMLDoc(serviceCall, processHelpfulTerm); 
	var contents = document.getElementById("balloon-contents");
	var holder = document.getElementById("balloon");
	var theBalloonTable = document.getElementById("balloon-table");
	theBalloonTable.className = "up";
	//var theTerm = items[0].term;
	var theDefinition = "We usually ship via UPS because they offer insurance against loss or damage while in transit. With smaller items like books we will most often ship via the US Postal Service. We'll make sure your purchase is well packed for a safe journey to your door. Our shipping department has high standards and holds an excellent record of shipping artwork around the world. We carefully pack everything using insulated packaging. As an added security measure we require shippers (UPS, for example) to get a signature from someone on the delivery end. In other words, we won't let them leave your package at your door without getting someone to sign for it.";
	contents.innerHTML = '<h1>Shipping & handing</h1><p>'+theDefinition+'</p>';
	holder.className = 'alpha_100';
	holder.style.opacity = '1.0';
}



function define(theTerm){
	var e = window.event;
	// alert(e.clientX);
	var theoffset = Math.floor((document.body.clientWidth - 960) / 2);
	var theBalloon = document.getElementById("balloon");
	var thepos = e.clientX - theoffset;
	theBalloon.style.left = (e.clientX - 170) + "px";
	theBalloon.style.top = (e.clientY + 5) + "px";
	theBalloon.style.height = "auto";
	theBalloon.style.opacity = 0;
	//alert(theBalloon.style.top);
	//alert(thepos);
	//alert(document.getElementById("menu-top").style.width);
    serviceCall = 'http://'+theDomain+'/xml/terms.xml.php?item='+theTerm;
    loadXMLDoc(serviceCall, processHelpfulTerm); 
}

function processHelpfulTerm(){ 
	if (requestSuccessful()) {
          theResponse = formatResponse();
          if (theResponse.Error){
            alert(theResponse.Error.Description);
          } else {
          //  theItems = theResponse.Terms;
          //  alert(theItems);
            displayHelpfulTerm(theResponse.Items);
          }
  } else {
      //  alert('Unable to download search results.');
  }
}

function displayHelpfulTerm(items){
 //   var termItems = termItems.split("+");
	var contents = document.getElementById("balloon-contents");
	var holder = document.getElementById("balloon");
	var theBalloonTable = document.getElementById("balloon-table");
	theBalloonTable.className = "up";
	var theTerm = items[0].term;
	var theDefinition = items[0].description;
	
	contents.innerHTML = '<h1>'+theTerm+'</h1><p>'+theDefinition+'</p>';
	holder.className = 'alpha_100';
	holder.style.opacity = '1.0';
}

function displayWhat(which){
	var e = window.event;
	var theoffset = Math.floor((document.body.clientWidth - 960) / 2);
	var theBalloon = document.getElementById("balloon");
	var theBalloonTable = document.getElementById("balloon-table");
	theBalloonTable.className = "down";
	// alert(document.getElementById("page").scrollTop);
	var thepos = e.clientX - theoffset;
	theBalloon.style.left = (e.clientX - 170) + "px";
	theBalloon.style.top = (e.clientY - 250 + document.body.scrollTop) + "px";
	theBalloon.style.height = "auto";
	theBalloon.style.opacity = 0;
	var contents = document.getElementById("balloon-contents");
	var holder = document.getElementById("balloon");
	var theTerm = 'MyGallery';
	var theDefinition = "MyGallery is a private viewing area where you can collect your favorite images for later review. You can view items in a scaled environment and compare different sizes or items. Click the button to add this item to the MyGallery area; use the link at upper right of page to review your collection.";


	
	contents.innerHTML = '<h1>'+theTerm+'</h1><p>'+theDefinition+'</p>';
	holder.className = 'alpha_100';
	holder.style.opacity = '1.0';

}


function expandNotes(){
	document.getElementById("collectors").style.whiteSpace = 'normal';
	document.getElementById("collectors").style.overflow = 'hidden';
	document.getElementById("collectors").style.height = '375px';
	children = document.getElementById("collectors").getElementsByTagName("p");
	for (i=0;i < children.length;i++){
		children[i].style.whiteSpace = 'normal';
		children[i].style.overflow = 'visible';
		children[i].style.height = 'auto';
	}
	document.getElementById("showmore").style.display = 'none';
	document.getElementById("showless").style.display = 'inline';
}

function collapseNotes(){
	document.getElementById("collectors").style.whiteSpace = 'nowrap';
	document.getElementById("collectors").style.overflow = 'hidden';
	document.getElementById("collectors").style.height = '14px';
	children = document.getElementById("collectors").getElementsByTagName("p");
	for (i=0;i < children.length;i++){
		children[i].style.whiteSpace = 'nowrap';
		children[i].style.overflow = 'hidden';
		children[i].style.height = '14px';
	}
	document.getElementById("showmore").style.display = 'block';
	document.getElementById("showless").style.display = 'none';
}

function launchCollection(){
	document.getElementById("thePrint").className = "alpha_100";
	tt = setTimeout("launchCollectionTitle()",1500);
}

function launchCollectionTitle(){
	
	var colorClass = document.getElementById("color_overlay").className;
	//alert(colorClass);
	colorClass.replace("invisible","alpha_75");
	//alert(colorClass);
	document.getElementById("color_overlay").className = colorClass;
	
	if (colorClass == "invisible positive"){
	document.getElementById("color_overlay").className = "alpha_75 positive";
	
	} else {
	document.getElementById("color_overlay").className = "alpha_75 negative";
	
	}
	
	document.getElementById("overlay").className = "alpha_100";
}

function changeUp(howMany){
	if (howMany == 1){
		document.body.className = "palette_home one-up";
	} else {
		document.body.className = "palette_home two-up";
		activeFrame = 2;
		clearTimeout(to2);
		to2=setTimeout("fadePlaque2('75');",1000 * 2);
	}
}

function openLightboxHelp(){

	document.body.style.overflow = 'hidden';
	var thisone=document.getElementById("frame");
	document.getElementById("frame").innerHTML = "(help!)";
	document.getElementById("frame").style.padding = "0px";
	document.getElementById("frame").style.width = "900px";
	document.getElementById("frame").style.background = "transparent";
	thisone.style.width = '900px';
	thisone.style.height = '600px';

	var thisone=document.getElementById("easel");
	thisone.style.display = 'block';
	var thisone=document.getElementById("canvas");
	thisone.style.display = 'block';
		thisone.style.background = 'white';
	thisone.style.top = (document.documentElement.scrollTop + 26) + 'px';
	thisone.style.left = Math.floor((maxWidth()-900)/2) + 'px';
	thisone.style.height = '600px !important';
	thisone.style.width = '900px !important';
	thisone.style.display = 'block';
//	alert(thisone.style.height);
}

function showMore(theMore){
	var targetHeight;
	var thisone=document.getElementById("canvas");
	
	if (maxHeight() > 600){
		targetHeight = maxHeight() - 160;
		thisone.style.top = '80px';
	} else {
		targetHeight = maxHeight() - 26;
		thisone.style.top = (document.documentElement.scrollTop + 26) + 'px';
	}
	
	
	
	theMore = replaceAll(theMore,"+",String.fromCharCode(34));
	theMore = replaceAll(theMore,"^",String.fromCharCode(39));
	var innerCopy = '<div class="more_holder" id="more_holder" style="height:'+(targetHeight-74)+'px;overflow:scroll;">' + unescape(theMore) + '<p><a href="javascript:hideScreen();" class="button highlighted">Close</a></p></div>';
	document.getElementById("frame").innerHTML = innerCopy;
	document.getElementById("frame").style.padding = "0px";
	document.getElementById("frame").style.width = "500px";
	document.getElementById("frame").style.background = "transparent";
	document.getElementById("canvas").style.backgroundImage = "none";
	
	document.body.style.overflow = 'hidden';
	var thisone=document.getElementById("easel");
	thisone.style.display = 'block';
	var thisone=document.getElementById("canvas");
	thisone.style.display = 'block';
	var thisone=document.getElementById("canvas");
	thisone.style.top = (document.documentElement.scrollTop + 26) + 'px';
	thisone.style.left = ((maxWidth()-640)/2) + 'px';
	thisone.style.height = targetHeight + 'px';
	thisone.style.display = 'block';
}

function submitMail(){
	var params = '';
	var thereason = document.getElementById('issue').options[document.getElementById('issue').selectedIndex].value;
	var theissue = document.getElementById('issue').selectedIndex;
	var theq = document.getElementById('issue').options[document.getElementById('issue').selectedIndex].text;
	var theadd = document.getElementById('ema').value;
	var theph = document.getElementById('phone').value;
	var theui = document.getElementById('userid').value;
	var thelast = document.getElementById('previous').value;
	var thebr = document.getElementById('browser').value;
	var thecopy = document.getElementById('comment').value;
	
	if (thereason == "RSVP"){
		var rsvp = 1;
	
	} else {
		var rsvp = 0;
	}
	
	
	if (theadd == 'Your email address') {theadd = '';}
	if (theph == 'Your phone number') {theph = '';}
	
	if ((theadd == '') && (theph == '')){
		alert('Please enter either email address or phone so we can contact you.');
	} else {
		if ((thereason == '')){
			alert('Please indicate the nature of your issue so we can best route your request.');
		} else {
			if ((thecopy == '') && (thereason != 'rsvp')){
				alert('Please enter your message.');
			} else {
				document.getElementById('primary').disabled = true;
				serviceCall = 'http://'+theDomain+'/xml/send-mail.xml.php'+'?ema='+theadd+'&ph='+theph+'&ti='+theissue+'&rs='+rsvp+'&ui='+theui+'&ther='+thereason+'&br='+encodeURIComponent(thebr)+'&pr='+thelast+'&cmt='+escape(thecopy)+'&q='+escape(theq);
			//	alert(serviceCall);
				loadXMLDoc(serviceCall, processSendResults); 
			}
		}
	}
}

function processSendResults(){
	var html =  req.responseXML.getElementsByTagName('data')[0].firstChild.data;
	html = replaceAll(html, "[", "<");
	html =  replaceAll(html, "]", ">");
	document.getElementById('belongs').innerHTML =  html;
	document.getElementById('before').className = 'invisible';
	document.getElementById('after').className = 'alpha_100';
}

function submitList(){
	var params = '';
	for (i=1;i<=6; i++){
	
		if (document.getElementById('cb-'+i)){
			checkbox = document.getElementById('cb-'+i);
			if (checkbox.checked){
				params += "&cb-"+i+"=1";
			}
		}
	}
	
	theadd = document.getElementById('ema').value;
	if (theadd == 'Your email address'){
		alert('Please enter your email address.');
	} else {
		document.getElementById('primary').disabled = true;
		serviceCall = 'http://'+theDomain+'/xml/signup-mail.xml.php'+'?ema='+theadd+params;
		loadXMLDoc(serviceCall, processSignupMailResults); 
	}
}

function processSignupMailResults(){
	var html =  req.responseXML.getElementsByTagName('data')[0].firstChild.data;
	html = replaceAll(html, "[", "<");
	html =  replaceAll(html, "]", ">");
	document.getElementById('belongs').innerHTML = '<ul>' + html + '</ul>';
	document.getElementById('before').className = 'invisible';
	document.getElementById('after').className = 'alpha_100';
}

function cleanCardNumber(ccNumber){
	ccNumber =  replaceAll(ccNumber, "-", "");
	ccNumber =  replaceAll(ccNumber, " ", "");
	ccNumber =  replaceAll(ccNumber, ".", "");
	return ccNumber;
}

function luhn(num) {
	num = (num + '').replace(/\D+/g, '').split('').reverse();
	if (!num.length)
		return false;
	var total = 0, i;
	for (i = 0; i < num.length; i++) {
		num[i] = parseInt(num[i]);
		total += i % 2 ? 2 * num[i] - (num[i] > 4 ? 9 : 0) : num[i];
	}
	return (total % 10) == 0;
}

function checkoutSetCard(ccNumber){
	ccNumber = cleanCardNumber(ccNumber);

	var fld = document.getElementById("cc");
	var firstOne = ccNumber.substring(0,1);
	var firstTwo = ccNumber.substring(0,2);
	var ccv = document.getElementById("ccv-example");
	var notes = document.getElementById("ccv-notes");
	
	
	
	if ((ccNumber.length == 16) && (firstOne == "4")){
		<!-- visa -->
		fld.style.background = "#fff url(http://images.sfae.com/core/interface/visa.png) center right no-repeat";
		ccv.style.background = "#fff url(http://images.sfae.com/core/interface/checkout/ccv-visa.png) top left no-repeat";
		notes.innerText = "You can find this three-digit code on the back of your card.";
	} else {
		if ((ccNumber.length == 16) && ((firstTwo == "51") || (firstTwo == "52") || (firstTwo == "53") || (firstTwo == "54") || (firstTwo == "55"))){
		<!-- mastercard-->
		fld.style.background = "#fff url(http://images.sfae.com/core/interface/mastercard.png) center right no-repeat";
		ccv.style.background = "#fff url(http://images.sfae.com/core/interface/checkout/ccv-mastercard.png) top left no-repeat";
		notes.innerText = "You can find this three-digit code on the back of your card.";
		
		} else {

				if ((ccNumber.length == 15) && ((firstTwo == "34") || (firstTwo == "37"))){
					<!-- amex-->
					fld.style.background = "url(http://images.sfae.com/core/interface/amex.png) center right no-repeat";
					ccv.style.background = "url(http://images.sfae.com/core/interface/checkout/ccv-amex.png) top left no-repeat";
					notes.innerText = "You can find this four-digit code on the front of your card.";
				} else {
					
					var firstThree = parseInt(ccNumber.substring(0,3));
					var firstFour = ccNumber.substring(0,4);
					var firstSix = parseInt(ccNumber.substring(0,6));
					var OKTwo = (firstTwo == "65");
					var OKThree = ((firstThree >= 644) && (firstThree <= 649));
					var OKFour =  (firstFour == "6011");
					var OKSix = ((firstSix >= 622126) && (firstSix <= 622925));

					if ((ccNumber.length == 16) && (OKTwo || OKThree || OKFour || OKSix)){
					<!-- discover-->
					fld.style.background = "#fff url(http://images.sfae.com/core/interface/discover.png) center right no-repeat";
					ccv.style.background = "#fff url(http://images.sfae.com/core/interface/checkout/ccv-discover.png) top left no-repeat";
					notes.innerText = "You can find this three-digit code on the back of your card.";
					} else {
						fld.style.background = "#fff";
						ccv.style.background = "transparent";
				}
			}
		}
	}
}

function showCCVExample(){
		var cc = document.getElementById("cc");
		var ccvHolder = document.getElementById("ccv-holder");

//	if (cc.value == ''){
//						conveyInstruction('Please enter credit card to determine type.', cc);
	
//	} else {
		var ccv = document.getElementById("ccv-example");
		ccv.style.display = 'block';
		ccvHolder.style.height = "80px";
//	}

}

function checkoutValidCard(ccNumber){
	ccNumber = cleanCardNumber(ccNumber);
	var fld = document.getElementById("cc");
	
	if (!luhn(ccNumber)){
		return false;
	}
	
	
	var firstOne = ccNumber.substring(0,1);
	var firstTwo = ccNumber.substring(0,2);
		if ((ccNumber.length == 16) && ((firstOne == "4") || (firstTwo == "51") || (firstTwo == "52") || (firstTwo == "53") || (firstTwo == "54") || (firstTwo == "55"))){
			return true;
		} else {
			if ((ccNumber.length == 16) && ((firstTwo == "51") || (firstTwo == "52") || (firstTwo == "53") || (firstTwo == "54") || (firstTwo == "55"))){
				return true;
			} else {
				if ((ccNumber.length == 15) && ((firstTwo == "34") || (firstTwo == "37"))){
					<!-- amex-->
					return true;
				} else {
					
					var firstThree = parseInt(ccNumber.substring(0,3));
					var firstFour = ccNumber.substring(0,4);
					var firstSix = parseInt(ccNumber.substring(0,6));
					
					var OKTwo = (firstTwo == "65");
					var OKThree = ((firstThree >= 644) && (firstThree <= 649));
					var OKFour =  (firstFour == "6011");
					var OKSix = ((firstSix >= 622126) && (firstSix <= 622925));
	
					if ((ccNumber.length == 16) && (OKTwo || OKThree || OKFour || OKSix)){
						return true;
					} else {
						return false;
					}
				}
			}
		}
	}


function maxWidth(){
	return document.body.offsetWidth;
}

function maxHeight(){
	var IE = (document.all) || false;
	winW  = (IE) ? document.body.clientWidth  : window.innerWidth;
	winH = (IE) ? document.body.clientHeight : window.innerHeight;
	return winH;
}

function submitSearch(){
	var str = document.getElementById("searchbox").value;
	if (str != "Search sfae.com"){
		document.searchform.submit();
	} else {
		document.getElementById("searchbox").select();
	}
}

function searchTag(theLinkText){
	document.getElementById("searchbox").value = theLinkText.replace("_"," ");
	createCookie("search",document.getElementById("searchbox").value);
	document.forms["searchform"].submit(); 
}

function init(){

	if ("https:" == document.location.protocol){
		document.location = "http://" + document.location.hostname + document.location.pathname + document.location.search;
		//alert(document.location.pathname);
	}



	if (document.documentElement.scrollHeight < 800){
		document.getElementById("nightshade").style.top = document.documentElement.scrollHeight + "px";
	} else {
		document.getElementById("nightshade").style.top = document.documentElement.scrollHeight + "px";
	}

	boxObj = document.getElementById("searchbox");
	if (boxObj.addEventListener) {
		boxObj.addEventListener("keydown", function(e){
			keyCode = e.keyCode;
			autoComplete(boxObj.value+String.fromCharCode(keyCode));
		},true);
	} else {
		if (boxObj.attachEvent){
			boxObj.attachEvent("keydown", function(e){
				keyCode = e.keyCode;
				autoComplete(boxObj.value+String.fromCharCode(keyCode));
			});
		}
	}
	
	setTimeout("showMenu()",500);
	
}

function initSecure(){
	if (document.documentElement.scrollHeight < 800){
		document.getElementById("nightshade").style.top = document.documentElement.scrollHeight + "px";
	} else {
		document.getElementById("nightshade").style.top = document.documentElement.scrollHeight + "px";
	}

	boxObj = document.getElementById("searchbox");
	if (boxObj.addEventListener) {
		boxObj.addEventListener("keydown", function(e){
			keyCode = e.keyCode;
			autoComplete(boxObj.value+String.fromCharCode(keyCode));
		},true);
	} else {
		if (boxObj.attachEvent){
			boxObj.attachEvent("keydown", function(e){
				keyCode = e.keyCode;
				autoComplete(boxObj.value+String.fromCharCode(keyCode));
			});
		}
	}
	
	setTimeout("showMenu()",500);
}

function showMenu(){
	document.getElementById("fcs").style.top = "34px";
}

function autoComplete(theText){
    serviceCall = 'http://'+theDomain+'/ipad/xml/terms.xml.php?item='+theText.replace(" ","_");
    loadXMLDoc(serviceCall, processTermResults); 
}

function loadXMLDoc(url, notifyMe) {
  	if (window.XMLHttpRequest){
      	req = new XMLHttpRequest();
  	} else if(window.ActiveXObject){
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return;
	}
  req.onload = notifyMe;
  req.open('GET', url,true);
  req.send(null);
}

function processTermResults(){ 
	if (requestSuccessful()) {
          theResponse = formatResponse();
          if (theResponse.Error){
            alert(theResponse.Error.Description);
          } else {
            theItems = theResponse.Terms;
            displayAutoComplete();
          }
  } else {
      //  alert('Unable to download search results.');
  }
}

function displayAutoComplete(){
    var theTerm;
	var suggest = document.getElementById("suggest");
	var theSuggestions = '';
	if (theItems.length > 0){
		// initialize, clear contents
		suggest.innerHTML = '';
	 	theSuggestions = '<ul>';
		for (i=0;i < theItems.length;i++){
			theSuggestions += "<li><div class='term-count'>("+theItems[i].count+")</div><a href='#' onclick='searchTag(\""+theItems[i].name+"\");'>"+theItems[i].display + '</a></li>';
		}
	 	theSuggestions += '</ul>';
	 	suggest.innerHTML = theSuggestions;
		suggest.style.display = 'block';
	} else {
		suggest.style.display = 'none';
	}
}

function showFilters(){
	// empty
}

function noScreen(){
	document.getElementById("easel").style.display = 'none';
	document.getElementById("canvas").style.display = 'none';
	document.body.style.overflow = "visible";
	document.getElementById("easel").className = 'alpha_50';
	document.getElementById("canvas").className = 'alpha_100';
}

function someScreen(howMuch){
	document.getElementById("easel").className = howMuch;
	document.getElementById("canvas").className = howMuch;
}


function hideScreen(){
	t1 = setTimeout("someScreen('alpha_50');",50);
	t2 = setTimeout("someScreen('alpha_25');",150);
	t3 = setTimeout("noScreen();",250);
}

function hideFilters(){
	document.getElementById("suggest").style.display = 'none';
}

function hideFiltersDelayed(){
	tm = setTimeout("hideFilters()",500);
}

function searchFor(what){
	location.href = 'index.php?action=search&table=products&item='+what+'&scope=0';
}


function boxIt(theItem){
	activeFrame = 1;
	theURL = 'http://'+theDomain+'/xml/lightbox_update.xml.php?id='+theItem;
	ajaxLightboxUpdate(theURL);
}  

function boxIt2(theItem){
	activeFrame = 2;
	theURL = 'http://'+theDomain+'/xml/lightbox_update.xml.php?id='+theItem;
	ajaxLightboxUpdate(theURL);
}  

function refreshLightbox(data){
	data =  replaceAll(data, "[", "<");
	data =  replaceAll(data, "]", ">");
	var myString = data;
	var obs = myString.split("+");
	
	if (activeFrame == 1){
		var target = "";
	} else {
		var target = "2";
	}

	//alert(obs[3]);

	document.getElementById("lightimagemat"+target).innerHTML = obs[0];
	document.getElementById("prices"+target).innerHTML = obs[1];
	document.getElementById("plaque"+target).innerHTML = obs[3];

	document.getElementById("productID"+target).value = obs[4];
	document.getElementById("productPriceID"+target).value = obs[5];
	
//	alert(document.getElementById("productPriceID"+target).value);
	
	launchPlaque('25');
	if (activeFrame == 1){
		clearTimeout(to);
		// to=setTimeout("fadePlaque1('75');",1000 * 3);
	
	} else {
		clearTimeout(to2);
		// to2=setTimeout("fadePlaque2('75');",1000 * 3);
	}
	document.getElementById("lightimageframe"+target).className = "shadowed "+obs[2];
	document.getElementById("lightimagemat"+target).className = obs[2];
}

function firstFade(){
//	to=setTimeout("fadePlaque1('75');",1000 * 3);
}
//

function ajaxLightboxUpdate(file){
	var xmlObj = null;
	if (window.XMLHttpRequest){
      		xmlObj = new XMLHttpRequest();
  	} else if(window.ActiveXObject){
		xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return;
	}
	xmlObj.onreadystatechange = function(){
		if(xmlObj.readyState == 4){
			refreshLightbox(xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data);
		}
	}
	xmlObj.open ('GET', file, true);
	xmlObj.send ('');
}
  
//

function ajaxLightboxAdd(file){
	var xmlObj = null;
	if (window.XMLHttpRequest){
      		xmlObj = new XMLHttpRequest();
  	} else if(window.ActiveXObject){
		xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return;
	}
	xmlObj.onreadystatechange = function(){
		if(xmlObj.readyState == 4){
			updateBillboard('frame', xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data);
			
			
			if (xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data != 'login'){
			setTimeout("hideScreen();",5000);
			}
			
		}
	}
	xmlObj.open ('GET', file, true);
	xmlObj.send ('');
}
  
//

function ajaxLightboxRemove(file){
	var xmlObj = null;
	if (window.XMLHttpRequest){
      		xmlObj = new XMLHttpRequest();
  	} else if(window.ActiveXObject){
		xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return;
	}
	xmlObj.onreadystatechange = function(){
		if(xmlObj.readyState == 4){
			updateBillboard('frame', xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data);
			setTimeout("rewriteLightbox()",5000);
		}
	}
	xmlObj.open ('GET', file, true);
	xmlObj.send ('');
}
  
//

function rewriteLightbox(){
hideScreen();
//alert(window.location.href);
location.reload(true);
}

function updateBillboard(obj, data){

	if (data == 'login'){
		//location.href = 'index.php?action=myaccount';
		login();
	} else {
	
		data =  replaceAll(data, "[", "<");
		data =  replaceAll(data, "]", ">");

		document.getElementById(obj).innerHTML = '<div class="notify">'+data+'</div>';
		document.body.style.overflow = 'hidden';
		var thisone=document.getElementById("easel");
		thisone.style.display = 'block';
		var thisone=document.getElementById("canvas");
		thisone.style.display = 'block';
		var thisone=document.getElementById("canvas");
		thisone.style.top = (document.documentElement.scrollTop + 200) + 'px';
		
		thisone.style.left = ((maxWidth()-360)/2) + 'px';
		thisone.style.display = 'block';
	}
}

//

function addToLightbox(theItem,theID){
	theURL = 'http://'+theDomain+'/xml/lightbox_add.xml.php?id='+theItem+'&pID='+theID;
	ajaxLightboxAdd(theURL);
}  

//

function removeFromLightbox(theID,theItem){
	theURL = 'http://'+theDomain+'/xml/lightbox_remove.xml.php?id='+theItem+'&pID='+theID;
	ajaxLightboxRemove(theURL);
}  

//
  
function ajaxRead(file, collection){
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }
  xmlObj.onreadystatechange = function(){
    if(xmlObj.readyState == 4){
       updateObj('xmlobj', xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data, collection);
     }
    }
    xmlObj.open ('GET', file, true);
    xmlObj.send ('');
  }
  
  //
  
  var thumbSize = "medium";
  
function updateObj(obj, data, collection){
	var myString = data;
	var obs = myString.split("+");
	
	obs[3] =  replaceAll(obs[3], "[", "<");
	obs[3] =  replaceAll(obs[3], "]", ">");
	
	var target = "index.php?pg=3"+padLeft(obs[1],"0",5);
	if (collection > 0){
		target += "&c="+collection;
		}
	if (collection < 0){
		target += "&a="+collection;
		}
	//target += "'";
	var html = "<a href='"+target+"' style='position:absolute;top:0px;left:0px;display:block;' id='catcher'>&nbsp;</a><table border='0' style='position:absolute;z-index:555;'><tr><td valign='top' style='width:125px;'><div class='peektext'>"+obs[0]+"</div><div class='peekprice' style='font:normal 12px Verdana !important;'>"+obs[3]+"</div></td></tr><tr><td><ul><li><a href='javascript:addToLightbox("+'"'+obs[1]+'"'+","+'"'+obs[4]+'"'+");'>Add to MyGallery</a></li><li><a href='index.php?pg=3"+padLeft(obs[1],"0",5);
	if (collection > 0){
		html += "&c="+collection;
	}
	html +="'>View detail page</a></li></ul></td></tr></table>";
	// alert(data);
  
	document.getElementById(obj).innerHTML = html;
   	el = document.getElementById('xmlobj');
	el.style.display = 'block';
	if (thumbSize == "medium"){
	el.className = "medium alpha_100";
	} else {
	el.className = "large alpha_100";
	}
}

//

function padLeft(val, ch, num) {
	var re = new RegExp(".{" + num + "}$");
	var pad = "";

	do  {
		pad += ch;
	} while(pad.length < num)

	return re.exec(pad + val);
}

//

function imageClear(thePosition){
	el = document.getElementById('xmlobj');
	outOfBounds = true;
	var t=setTimeout("lastOneOut();",100);
}
 
function lastOneOut(){
	if (outOfBounds){
		if (!inBounds){
			//alert('not in bounds');
			fadeBalloon('75');
			theBlock.style.backgroundPosition = "0px 0px !important";
		//	alert(theBlock.style.backgroundPosition);
		}
	}
} 
  
var outOfBounds = true;
var inBounds = false;

function setBounds(theCall){
	inBounds = theCall;
	if (!theCall){
		var t=setTimeout(lastOneOut,30);

	} else {
	
		thisOne = 	'img' + theBlockRow + theBlockColumn;
		
		if (thisOne != 'img11' && document.getElementById('img11')){document.getElementById('img11').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img12' && document.getElementById('img12')){document.getElementById('img12').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img13' && document.getElementById('img13')){document.getElementById('img13').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img14' && document.getElementById('img14')){document.getElementById('img14').style.backgroundPosition = "0px 0px !important";}
//		if (thisOne != 'img15' && document.getElementById('img15')){document.getElementById('img15').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img16' && document.getElementById('img16')){document.getElementById('img16').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img22' && document.getElementById('img22')){document.getElementById('img22').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img23' && document.getElementById('img23')){document.getElementById('img23').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img24' && document.getElementById('img24')){document.getElementById('img24').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img33' && document.getElementById('img33')){document.getElementById('img33').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img34' && document.getElementById('img34')){document.getElementById('img34').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img35' && document.getElementById('img35')){document.getElementById('img35').style.backgroundPosition = "0px 0px !important";}
		if (thisOne != 'img36' && document.getElementById('img36')){document.getElementById('img36').style.backgroundPosition = "0px 0px !important";}

		theBlock = document.getElementById('img' + theBlockRow + theBlockColumn);
		
		combined = theBlockRow  + '' + theBlockColumn;
		large = ((combined == '16') || (combined == '22'));

		if (large){
			theBlock.style.backgroundPosition = "0px -310px !important";
		} else {
			theBlock.style.backgroundPosition = "0px -150px !important";
		}
	}
}
  
// 
  
function imageHover(theID, theRow, theColumn, thePosition, theClient, theCollection){
 	outOfBounds = false;
	el = document.getElementById('xmlobj');
	el.innerHTML = '';
	theBlock = document.getElementById('img' + theRow + theColumn);

	if (false){
		document.getElementById('img11').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img12').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img13').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img14').style.backgroundPosition = "0px 0px !important";
//		if (thisOne != 'img15'){document.getElementById('img15').style.backgroundPosition = "0px 0px";}
		document.getElementById('img16').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img22').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img23').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img24').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img33').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img34').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img35').style.backgroundPosition = "0px 0px !important";
		document.getElementById('img36').style.backgroundPosition = "0px 0px !important";
	}
	
	
	combined = theRow  + '' + theColumn;
	large = ((combined == '16') || (combined == '22'));
	if (large){
		theBlock.style.backgroundPosition = "0px -310px";
	} else {
		theBlock.style.backgroundPosition = "0px -150px";
	}
	theBlockRow = theRow;
	theBlockColumn = theColumn;
	
	if (combined == '16'){
		// upper right
		el.style.backgroundImage = 'url(http://images.sfae.com/core/interface/overlay_left.png)';
			el.style.width = '301px';
			el.style.height = '320px';
			el.style.paddingLeft = '15px';
			el.style.paddingRight = '165px';
thumbSize = "large";
//			alert(el.className);
			theLeft = 489;
			theTop = 3;
	} else {
		if (combined == '22'){
			// lower left
			el.style.backgroundImage = 'url(http://images.sfae.com/core/interface/overlay_right.png)';
			el.style.width = '146px';
			el.style.height = '320px';
			el.style.paddingLeft = '320px';
			el.style.paddingRight = '15px';
thumbSize = "large";
			theLeft = 12;
			theTop = 162;
			theLeft = 13;
			theTop = 161;
		} else {
			el.style.width = '140px';
			el.style.height = '160px';
thumbSize = "medium";
			if (theColumn < 4){
				theLeft = ((theColumn-1) * 159) + 12;
				el.style.backgroundImage = 'url(http://images.sfae.com/core/interface/overlay_small_right.png)';
				el.style.paddingLeft = '165px';
				el.style.paddingRight = '15px';
			} else {
				theLeft = ((theColumn-2) * 159) + 12;
				el.style.backgroundImage = 'url(http://images.sfae.com/core/interface/overlay_small_left.png)';
				el.style.paddingLeft = '15px';
				el.style.paddingRight = '165px';
			}
			theTop = (theRow * 160) - 158;
		}
	}
	
	if (theCollection == 0){
		theTop += 109;
	}
	
	el.style.left = theLeft+'px';
	el.style.top = theTop+'px';
	
	el.style.display = 'block';
	el.className = "alpha_100";

	theURL = 'http://'+theDomain+'/data.xml.php?id='+theID+'&client='+theClient;
	if ((theCollection != '') && (theCollection != 0)){
		theURL += '&c='+theCollection;
	}

	ajaxRead(theURL,theCollection);
}



function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



//

function showCanvas(theWidth){
		document.body.style.overflow = 'hidden';
		var thisone=document.getElementById("easel");
		thisone.style.display = 'block';
		thisone.style.background = 'white';
		var thisone=document.getElementById("canvas");
		thisone.style.display = 'block';
		var thisone=document.getElementById("canvas");
		thisone.style.top = '60px';
		thisone.style.top = (document.documentElement.scrollTop + 100) + 'px';
		thisone.style.left = ((maxWidth()-theWidth)/2) + 'px';
		thisone.style.display = 'block';
}


// actions //

function ajaxLogin(nm,pswd){
	showScreen();
    serviceCall = 'http://'+theDomain+'/xml/login.xml.php?n='+nm+'&p='+pswd;
    loadXMLDoc(serviceCall, processLogin); 
}

function logoff(){
	eraseCookie("sfae");
	location.href = 'index.php?action=logoff&href='+location.href;
}

function ajaxNewSignup(){
//	showScreen();
    serviceCall = 'http://'+theDomain+'/xml/new-signup.xml.php';
    loadXMLDoc(serviceCall, processNewSignup); 
}


// responses //

function processNewSignup()
{ 
	if (requestSuccessful()) {
          theResponse = formatResponse();
          if (theResponse.Error){
            alert(theResponse.Error.Description);
          } else {
          	return ;

          }
  } else {
       alert('Unable to login; please notify technical support.');
  }
}
//

function processLogin()
{ 
	if (requestSuccessfulCheckOnly()) {
          //theResponse = eval('('+req.responseText+')'); // parse json
          theResponse = formatResponse();
          if (theResponse.Error){
            alert(theResponse.Error.Description);
          } else {
          	if (theResponse.id != ''){
          		hideScreen();
				if (location.search == ''){
					var remoteParams = 'index.php?status=remote&client='+theResponse.id+'&href='+location.href + '?pg=0';
				} else {
					var remoteParams = 'index.php?status=remote&client='+theResponse.id+'&href='+location.href;
				}
				location.href = remoteParams;
				// need to refresh page with appropriate login...
			} else {
			//	alert('wrong password or name');
			
			document.getElementById('instruction-login').style.display = 'block';
			
			//	login();
			}
          }
  } else {
       alert('Unable to login; please notify technical support.');
  }
}
//


function formatResponse(){
    return eval('('+req.responseText+')');
}

function requestSuccessful(){
	//hideElement("screen");
	//hideElement("activity");
	hideScreen();
    return (req.readyState == 4 && req.status == 200 );
}

function requestSuccessfulCheckOnly(){
	//hideElement("screen");
	//hideElement("activity");
	// hideScreen();
    return (req.readyState == 4 && req.status == 200 );
}

function showScreen(){
//	document.getElementById("screen").style.visibility = 'visible';
//	document.getElementById("activity").style.visibility = 'visible';
//	document.getElementById("screen").style.display = 'block';
//	document.getElementById("activity").style.display = 'block';

}

function xmlLoaded(xmlRequest) {
	if (xmlRequest.status == 200) {
		// Parse and interpret results
		// XML results found in xmlRequest.responseXML
		// Text results found in xmlRequest.responseText
	}
	else {
		alert("Error fetching data: HTTP status " + xmlRequest.status);
	}
}

function replaceAll(string, pcFrom, pcTo){
	var c = string;
	var i = c.indexOf(pcFrom);
	while (i > -1){
		c = c.replace(pcFrom, pcTo);
		i = c.indexOf(pcFrom);
	}
	return c;
}
//
function removeDefault (which, theDefault) {
	if (which.value == theDefault){
		which.value = '';
		which.style.color = '#000000';	
	}
}
//
function addDefault (which, theDefault) {
	if (which.value == ''){
		which.value = theDefault;
		which.style.color = '#999999 !important';	
	} else {
		which.style.color = '#000 !important';	
	}
}

 function fadeSpotlight(theAlpha){
	el = document.getElementById('sl');
	el.className = "alpha_"+theAlpha;
	
	
	if (theAlpha == '75'){
		var t=setTimeout("fadeSpotlight('50');",40);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("fadeSpotlight('0');",40);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("fadeSpotlight('0');",40);
			} 
		}
	}
 }
 
 function fadeStrip(theAlpha){
	el = document.getElementById('strip-content');
	el.className = "alpha_"+theAlpha;
	
	
	if (theAlpha == '75'){
		var t=setTimeout("fadeStrip('50');",40);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("fadeStrip('0');",40);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("fadeStrip('0');",40);
			} 
		}
	}
 }
 
 function launchSpotlight(theAlpha){
	el = document.getElementById('sl');
	el.className = "alpha_"+theAlpha;
	
	if (theAlpha == '75'){
		var t=setTimeout("launchSpotlight('100');",50);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("launchSpotlight('75');",50);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("launchSpotlight('50');",50);
			} 
		}
	}
 }

 function fadePlaque0(theAlpha){
	if (activeFrame == 1){
		var target = "";
	} else {
		var target = "2";
	}
	el = document.getElementById('plaque'+target);
	
	if (theAlpha != "0"){
		el.className = "alpha_"+theAlpha;
	} else {
		el.className = "invisible";
	}
	
	if (theAlpha == '75'){
		var t=setTimeout("fadePlaque('50');",150);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("fadePlaque('0');",150);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("fadePlaque('0');",150);
			} 
		}
	}
 }

 function fadePlaque1(theAlpha){
	target = "";
	el = document.getElementById('plaque'+target);
	
	if (theAlpha != "0"){
		el.className = "alpha_"+theAlpha;
	} else {
		el.className = "invisible";
	}
	
	if (theAlpha == '75'){
		var t=setTimeout("fadePlaque1('50');",150);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("fadePlaque1('0');",150);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("fadePlaque1('0');",150);
			} 
		}
	}
 }

 function fadePlaque2(theAlpha){
		var target = "2";
	el = document.getElementById('plaque'+target);
	
	if (theAlpha != "0"){
		el.className = "alpha_"+theAlpha;
	} else {
		el.className = "invisible";
	}
	
	if (theAlpha == '75'){
		var t=setTimeout("fadePlaque2('50');",150);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("fadePlaque2('0');",150);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("fadePlaque2('0');",150);
			} 
		}
	}
 }

 function launchPlaque(theAlpha){
	if (activeFrame == 1){
		var target = "";
	} else {
		var target = "2";
	}
	el = document.getElementById('plaque'+target);
	el.className = "alpha_"+theAlpha;
	
	if (theAlpha == '75'){
		var t=setTimeout("launchPlaque('100');",150);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("launchPlaque('75');",150);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("launchPlaque('50');",150);
			} 
		}
	}
 }

function rollSpotlights(which,limit,gallery){
	if (which < limit){
	target = which + 1;
	} else {
	target = 1;}
	updateSpotlight(which, gallery);
	t=setTimeout("rollSpotlights("+target+","+limit+","+gallery+");",10000);
}

function rollStrip(which,limit){
	if (which < limit){
	target = which + 1;
	} else {
	target = 1;}
	updateStrip(which);
	st=setTimeout("rollStrip("+target+","+limit+");",15000);
}

function updateStrip(which, gallery){
	clearTimeout(st);
	el = document.getElementById('strip-content');
	el.innerHTML = '';
	fadeStrip('0');
	theURL = 'http://'+theDomain+'/xml/strip.xml.php?which='+which;
	ajaxStrip(theURL);
}

function updateSpotlight(which, gallery){
	clearTimeout(t);
	el = document.getElementById('sl');
	el.innerHTML = '';
	fadeSpotlight('0');
	theURL = 'http://'+theDomain+'/xml/spotlight.xml.php?which='+which+"&gallery="+gallery;
	ajaxSpotlight(theURL);
}

function ajaxStrip(file){
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }
  xmlObj.onreadystatechange = function(){
    if(xmlObj.readyState == 4){
       updateStripObj('strip-content', xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data);
     }
    }
    xmlObj.open('GET', file, true);
    xmlObj.send('');
  }
  
function updateStripObj(obj, data){
	var html =  replaceAll(data, "[", "<");
	html =  replaceAll(html, "]", ">");
	document.getElementById(obj).innerHTML = html;
	launchStrip('25');
}

 function launchStrip(theAlpha){
	el = document.getElementById('strip-content');
	el.className = "alpha_"+theAlpha;
	
	if (theAlpha == '75'){
	//	var t=setTimeout("launchStrip('100');",50);
	} else {
		if (theAlpha == '50'){
		//	var t=setTimeout("launchStrip('75');",50);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("launchStrip('50');",50);
			} 
		}
	}
 }



function ajaxSpotlight(file){
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }
  xmlObj.onreadystatechange = function(){
    if(xmlObj.readyState == 4){
       updateSpotlightObj('sl', xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data);
     }
    }
    xmlObj.open('GET', file, true);
    xmlObj.send('');
  }
  
function updateSpotlightObj(obj, data){
	var html =  replaceAll(data, "[", "<");
	html =  replaceAll(html, "]", ">");
	document.getElementById(obj).innerHTML = html;
	launchSpotlight('25');
}

 function launchBalloon(theAlpha){
	el = document.getElementById('spotlight');
	el.className = "alpha_"+theAlpha;
	if (theAlpha == '75'){
		var t=setTimeout("launchBalloon('100');",25);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("launchBalloon('75');",25);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("launchBalloon('50');",25);
			} 
		}
	}
 }
 
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function toggleSearch() {
	el = document.getElementById('search_list');
	if (el.style.visibility == 'visible'){
		el.style.visibility = 'hidden';
	} else {
		el.style.visibility = 'visible';
	}
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
    temp = unescape(dc.substring(begin + prefix.length, end));

  return temp;
}
 

 function fadeBalloon2(theAlpha){
	el = document.getElementById('spotlight');
	el.className = "alpha_"+theAlpha;
	if (theAlpha == '75'){
		var t=setTimeout("fadeBalloon('50');",30);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("fadeBalloon('0');",30);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("fadeBalloon('0');",30);
			} else {
			//	var t=setTimeout("fadeBalloon('0');",10);
			}
		}
	}
 }
 
//

 function fadeBalloon(theAlpha){
	el = document.getElementById('xmlobj');
	el.className = "alpha_"+theAlpha;
	
	
	if (theAlpha == '75'){
		var t=setTimeout("fadeBalloon('50');",50);
	} else {
		if (theAlpha == '50'){
			var t=setTimeout("fadeBalloon('25');",50);
		} else {
			if (theAlpha == '25'){
				var t=setTimeout("fadeBalloon('0');",50);
			} else {
				el = document.getElementById('xmlobj');
				el.className = 'alpha_100';
				el.style.display = 'none';
			}
		}
	}
 }
 

function addToCart(){
	document.sizes.submit();
}

function addToCartLightbox(){
	document.cart1.submit();
}

function addToCartLightbox2(){
	document.cart2.submit();
}

function shiftStrip(theDirection, leftLimit, rightLimit) {
	theStrip = 	document.getElementById('strip');
	theStripX = theStrip.style.left;
	theStripX = theStripX.replace('px','');
	theSlideWidth = 142;
	
	if (theDirection == 'forward'){
		if (theStripX >= leftLimit){
		theUpdate = (theStripX * 1) - theSlideWidth;
		} else {

		}
	
	} else {
		if (theStripX < 0){
			theUpdate = (theStripX * 1) + theSlideWidth;
		}
	}
	theStrip.style.left = theUpdate + "px";		

}

function lightboxLookup(theSelect){
	theData = theSelect.options[theSelect.selectedIndex].value;
	theParts = theData.split('*');
	theID = theParts[0];
//	alert(theID);
	theParts = theData.split('*');
	theID = theParts[0];
//	alert(theID);
	theIDs = theID.split('-');
	var productID = theIDs[0];
	var priceID = theIDs[1];
//	alert(priceID);
	
	
	thePrice = theParts[1];
	theMedium = theParts[2];
	theSizeClass = theParts[3];
	theSize = theParts[6];
	theSize = replaceAll(theSize,'%','"');
	
	
	
	// $price['ProductID'] . '-' . $price['ProductPriceID'] . '*'.$price['Price'].'*'.$price['name'].'*'.$sizeClass.'*'.$edition.'*'.$artist
	// 	$name = '<p><em>' . $title . '</em><br>' . $artist['Firstname'] . ' ' . $artist['Surname'] . '<br>' . $edition . ' ' . $medium['name'] .'<br>' .$firstSize.' at <span class="number">' . $value . '</span><span style="float:right;font-weight:bold;"><a href="#">Buy</a></span>'; // . ', ' . $medium['name'];
	
	
	if (theSelect.id == "prices"){
		theImage = "<div id='lightimagemat' class='"+theSizeClass+"'><img src='http://images.sfae.com/product_images/lightbox/"+theParts[0]+".jpg'></div>" ;
		document.getElementById('lightimageframe').innerHTML = theImage;
		document.getElementById('productPriceID').value = priceID;
		document.getElementById('productID').value = productID;
		// theEdition = replaceAll(theParts[4],"[","<");
		// theEdition = replaceAll(theEdition,"]",">");
		updateCard1(priceID);
		// document.getElementById('plaque').innerHTML = theParts[5] + '<br>' + theEdition + ' ' + theMedium + '<br>' + theSize + ' at ' + thePrice;
		
	} else {
		theImage = "<div id='lightimagemat2' class='"+theSizeClass+"'><img src='http://images.sfae.com/product_images/lightbox/"+theParts[0]+".jpg'></div>" ;
		document.getElementById('lightimageframe2').innerHTML = theImage;
		document.getElementById('productPriceID2').value = priceID;
		document.getElementById('productID2').value = productID;
		updateCard2(priceID);
	}
}

function priceLookupGrid(theData){
	theParts = theData.split('*');
	theID = theParts[0];
	thePrice = theParts[1];
	theMedium = theParts[2];
	if (thePrice != "Call for price"){
		thePrice = "$" + thePrice;
	}	
	theImage = "<img src='http://images.sfae.com/product_images/scaled/"+theParts[0]+".jpg'>" ;
	document.getElementById('scaled').innerHTML = theImage;
	// alert('the lookup');
}

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_address.shipping[0]) {
    document.checkout_address.shipping[buttonSelect].checked=true;
  } else {
    document.checkout_address.shipping.checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}


function setZIndex(id, z_index) {
	document.getElementById(id).style.zIndex = z_index;
}

function navigateEvents(theSelect){
	
	var theTarget = theSelect.options[theSelect.selectedIndex].value;
	location = theTarget;
}

//
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id) {
	//change the opacity for different browsers
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function changePages(theOldID,theNewID){
	document.getElementById(theNewID).style.display = 'block';
//	opacity(theOldID, 100, 0, 500);
//	opacity(theNewID, 0, 100, 500)
	document.getElementById(theOldID).style.display = 'none';
}

function conveyInstruction(message, fld){
	var theBillboard = document.getElementById('instruction');
	theBillboard.innerHTML = "<div class='icon'>&nbsp;</div><em>"+message+"</em>";
	theBillboard.className += " badTouchChad";
	if (fld){
	fld.style.borderColor = 'red';
	}
}

function resetInstruction(){
			var theBillboard = document.getElementById('instruction');
			theBillboard.innerHTML = "<div class='icon'>&nbsp;</div>Please enter your address and payment information.";
			theBillboard.className = "instruction";

}

function validateOnly(theField){
	var fieldname = theField.name;
	var theForm = document.getElementById("checkout_form");
	
	if (fieldname == 'cc'){
		if (!checkoutValidCard(theField.value)){
			conveyInstruction('Please enter a valid card number.', theField);
		} else {
			document.getElementById("cc").style.borderColor = "#ccc";
			resetInstruction();
		}
	}

	if (fieldname == 'cardholder'){
		if (theForm.cardholder.value == ''){
			conveyInstruction('Please enter cardholder name.', theField);
		} else {
			theField.style.borderColor = "#ccc";
			resetInstruction();
		}
	}

	if (fieldname == 'Email'){
		if (theForm.Email.value == ''){
			conveyInstruction('Please enter your email address.', theField);
		} else {
			theField.style.borderColor = "#ccc";
			resetInstruction();
		}
	}

	if (fieldname == 'ccv'){
		if (theForm.ccv.value == ''){
			conveyInstruction('Please enter the security code from your card.', theField);
		} else {
			theField.style.borderColor = "#ccc";
			resetInstruction();
		}
	}

	if (fieldname == 'creditexp'){
		if (theForm.creditexp.value == 'MM/DD'){
			if (checkoutValidCard(document.getElementById("cc").value)){
				// no need to throw an error if there's one already up
				conveyInstruction('Please enter credit card expiration.', theField);
			}
		} else {
			theField.style.borderColor = "#ccc";
			resetInstruction();
		}
	}
	
}



function verify(theForm){

	if (theForm.Firstname.value == ''){
		alert('Please enter your first name.');
	} else {
		if (theForm.Surname.value == ''){
			alert('Please enter your last name.');
		} else {
			if (theForm.Street.value == ''){
				alert('Please enter your street address.');
			} else {
				if ((theForm.Postcode.value == '') && (theForm.Country.options[theForm.Country.selectedIndex].value == 'United States')){
					conveyInstruction('Please enter your zip or postal code.');
				} else {
					if ((theForm.County.options[theForm.County.selectedIndex].value == 'Please select...') && (theForm.Country.options[theForm.Country.selectedIndex].value == 'United States')){
						conveyInstruction('Please select your state.');
					} else {
						if (theForm.Country.options[theForm.Country.selectedIndex].value == 'Please select...'){
							conveyInstruction('Please select your country.');
						} else {
							if (theForm.City.value == ''){
								conveyInstruction('Please enter your city.');
							} else {
								var cc = document.getElementById("cc").value;
								if (!checkoutValidCard(cc)){
									conveyInstruction('Please enter a valid card number.');
								} else {
									if (theForm.cardholder.value == ''){
										conveyInstruction('Please enter cardholder name.');
									} else {
										if (theForm.creditexp.value == 'MM/DD'){
											conveyInstruction('Please enter credit card expiration.');
										} else {
											if (theForm.Email.value == ''){
												conveyInstruction('Please enter your email address.');
											} else {
												if (theForm.ccv.value == ''){
													conveyInstruction('Please enter the security code from your card.');
												} else {
													theForm.submit();
												
												}
											
											}
										
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function verifySignup(theForm){

	if (theForm.Firstname.value == ''){
		conveyInstruction('Please enter your first name.');
	} else {
		if (theForm.Surname.value == ''){
			conveyInstruction('Please enter your last name.');
		} else {
			if (theForm.password.value == ''){
				conveyInstruction('Please enter your password.');
			} else {
				if (theForm.confirm_password.value == ''){
					conveyInstruction('Please verify your password.');
				} else {
					if (theForm.password.value != theForm.confirm_password.value){
						conveyInstruction('The passwords entered do not match.');
					} else {
						if (theForm.Email.value == ''){
							conveyInstruction('Please enter your email address.');
						} else {
								theForm.submit();
						}
					}
				}
			}
		}
	}
	
	
}



function showSlides(theCarouselID, slides, theLink){

	var thePos = (theCarouselID.substring(1,4) * 1) - 1;
	imgs = slides.split(", ");
	theParent = document.getElementById(theCarouselID);
	children = theParent.getElementsByTagName("div");
	for (i=0;i < children.length;i++){
		children[i].innerHTML = '<a href="'+theLink+'"><img src="http://images.sfae.com/product_images/animate/'+imgs[i]+'.jpg" width="72" height="72" border="0" align="middle" /></a>';
	}
	if (theCallArray[thePos] == 0){
		theCallArray[thePos] = 1;
		var t=setTimeout("fade('75','"+theCarouselID+"');",1000);
	}
}

function fade(theAlpha, theCarouselID){
	theParent = document.getElementById(theCarouselID);
	theImages = theParent.getElementsByTagName("div");
	var thePos = (theCarouselID.substring(1,4) * 1) - 1;
	
	for (i=0;i < theImages.length;i++){
		if (theImages[i].className.indexOf("alpha_0") < 0){
			theCurrentChild = i + 1;
			break;
		}
	}
	
	// get element and set class name to control opacity
	var theElement = theImages[theCurrentChild-1];
	var theScore = theElement.className.indexOf("_");
	theElement.className = theElement.className.substring(0,theScore+1)+theAlpha;
	
	// end of the opacity shift for current image, need to either get next image or stop if end of carousel
	if (theAlpha == '0'){
		if (theCurrentChild < theImages.length){
			theCurrentChild++;
			if (theCurrentChild == theImages.length){
				// the trick here is we're doubling the first image for a smooth transition;
				// at this point we're looking at a copy and can reset carousel opacity with no discernible impact
				for (i=0;i < theImages.length;i++){
					theImages[i].className= theImages[i].className.replace("alpha_0","alpha_100");
				}
				theCallArray[thePos] = 0;
				return;
			} else {
				// we're not at the end, start fading the new current image
				var tm=setTimeout("fade('75','"+theCarouselID+"');",1000);
			}
		} 
	} else {
		// non-zero alpha request
			var tm=setTimeout("fade('"+((theAlpha * 1) -25)+"','"+theCarouselID+"');",50);
	}
}

		function cleanUp(){
		//	alert("feed");
			var root = document.getElementById("feed-blog");
			if (root){
			var kids = root.getElementsByTagName("li");
			for (var i = 0; i < kids.length; i++) {

				var anchors = kids[i].getElementsByTagName("a");
				var spans = kids[i].getElementsByTagName("span");
				var contentHolder = kids[i].getElementsByTagName("div");
				var imgs = contentHolder[0].getElementsByTagName("img");
				var theImage = imgs[0];
					if ((imgs[0].src.indexOf("tracker") > 0)){
					var theImage = imgs[1];
					}
										
						if (theImage && (imgs.length > 0) && (theImage.src != '') && ((theImage.src.indexOf("jpg") > 0) || (theImage.src.indexOf("png") > 0))) {
							//	contentHolder[0].removeChild(imgs[0]);
							// alert(theImage.src);		
							//		alert(imgs[0].src);
							var holder = document.createElement('div');
							holder.className = 'img-holder';
							kids[i].appendChild(holder);
						
							var img = document.createElement('img');
							img.src = imgs[0].src;
							img.className = 'thumb';
							holder.appendChild(img);
							imgs[0].style.display = "none";
							
							//		kids[i].style.backgroundImage = "url("+imgs[0].src+")";
							//		kids[i].style.backgroundPosition = "top right";
							//		kids[i].style.backgroundRepeat = "no-repeat";
							//	alert(imgs[0].src);
						}
			} // end for i
			
			} // end if

		}
		
	//
	
function signIn() {

	var theForm = document.getElementById('form-signin'); 
	if (theForm.rbone[0].checked) {
			// new customer
			//	theForm.action.value = "account";
			//	theForm.status.value = "create_account";
		createCookie("last",location.href,3);
			//	alert('submitting');
			//	theForm.submit();
			//alert("send mail and confirm.");
	//	var innerCopy = "We just sent your mail.";
		
		
		location.href = 'index.php?pg=110010&email=' + theForm.username.value;
		
		
//		document.getElementById("frame").innerHTML = innerCopy;
//		document.getElementById("frame").style.padding = "0px";
//		document.getElementById("frame").style.width = "500px";
//		document.getElementById("frame").style.background = "transparent";
//		document.getElementById("canvas").style.backgroundImage = "none";
	
	//	var tm = setTimeout('document.getElementById("first").focus();',100);
		
	//	showCanvas(500);
		

		return true;


} else {
	theForm.action.value = "login";
	theForm.status.value = "finish_login";
	
	ajaxLogin(theForm.username.value, theForm.password.value);
	
	}
}

//
	
function login (){

	var email = '';
	var password = '';
	
	var innerCopy = '<div class="fieldset_holder"><div class="fieldset_rim"><div class="banner"><h1 class="signin">Please sign in&hellip;</h1></div><div style="position:absolute;right:20px;top:20px;color:white;z-index:4000;"><a href="javascript:hideScreen();" style="color:white !important;font-weight:bold;">Close</a></div><br clear="all">';
	innerCopy += '<fieldset style="padding-top:60px;"><form id="form-signin" action="javascript:signIn();" method="get"><table border="0" width="91%" style="margin-bottom:20px;"><tr style="margin-top:10px;">';

	innerCopy += '<td colspan="1" class="error" style="white-space:nowrap;"><div class="instruction badTouchChad" id="instruction-login"><div class="icon">&nbsp;</div>No matching record found.</div></td></tr><tr>';

	innerCopy += '<td colspan="1" class="label query" style="white-space:nowrap;">What is your e-mail address?</td></tr><tr>';
	innerCopy += '<td colspan="1" class="label answer"><div class="answer_holder label answer" style="height:16px;white-space:nowrap;">My e-mail address is: &nbsp;<input class="field" id="first" name="username" value="'+email+'" style="width:178px;float:right;margin-right:30px;"></div></td>';
	innerCopy += '</tr><tr><td colspan="1" class="label query">&nbsp;</td></tr><tr><td colspan="1" class="label query">Do you have an SFAE.com password?</td></tr>';
	innerCopy += '<tr><td colspan="1" class="label answer"><input type="radio"  style="margin-top:0px;" class="checkbox" id="newcustomer" name="rbone" ';
	
	if (email == '') {innerCopy += 'checked ';}
	
	innerCopy += 'value="noncustomer">&nbsp;No, I am a new customer&nbsp;</td></tr><tr><td colspan="1" class="label answer"><input type="radio" class="checkbox" name="rbone"  style="margin-top:0px;" id="havepass" value="customer" ';
	
	if (email != '') {innerCopy += 'checked ';}
	
	
	innerCopy += 'onclick="document.getElementById('+"'password'"+').focus();">&nbsp;Yes, I have a password:&nbsp;<input type="password" class="field password" onfocus="document.getElementById(' + "'havepass'"+').checked = true;" name="password" id="password" style="width:130px;float:right;margin-right:30px;" value="'+password+'">';
	
	innerCopy += '<script language="javascript" type="text/javascript">document.getElementById("form-signin").username.focus();</script>';
	innerCopy += '<input type="hidden" name="action" value="login"><input type="hidden" name="status" value="finish_login"></td></tr></tr>';
	innerCopy += '<tr><td colspan="1"><div style="position:relative;"><a href="javascript:signIn();" class="primary_action button" style="margin-top:20px;margin-bottom:20px;">Sign In</a>';
	innerCopy += '<div class="answer_holder label answer" style="height:16px;white-space:nowrap;margin-left:10px;display:inline-block;position:absolute;top:-5px;left:130px;">';
	innerCopy += '<input type="checkbox" style="width:auto !important;margin:4px auto 0px auto;" id="remember" ';
				 
	if (email != '') {innerCopy += 'checked ';}
				 
	innerCopy += 'name="remember" class="checkbox" value="1" style="width:16px;" /><label for="remember" class="label" style="display:inline !important;margin-left:0px;font-size:12px;color:#444;padding-left:5px;">&nbsp;Remember me on this computer</label></div></div></td></tr>';
	innerCopy += '<tr><td></td></tr></table></form></fieldset></div></div>';

	document.getElementById("frame").innerHTML = innerCopy;
	document.getElementById("frame").style.padding = "0px";
	document.getElementById("frame").style.width = "500px";
	document.getElementById("frame").style.background = "transparent";
	document.getElementById("canvas").style.backgroundImage = "none";

	var tm = setTimeout('document.getElementById("first").focus();',100);
	
	showCanvas(500);

//	return true;

}




