function zoom(val) {
HTML = '<form id="zoomForm">';
HTML += '<table cellpadding="0">';
imgLoc = "/gallery/"+val+"_lg.jpg";
HTML += '<tr><td><div onclick="close1();"><img id="bottom_image" src='+imgLoc+' width="650" height="650" border="0"></div></td></tr>';
HTML += '</table></form>';
HTML += '<span id="top_image" style="float:right; color:black; font-weight:bold; width="15px"; text-align:center; cursor:pointer" onclick="close1();">&nbsp;X&nbsp;</span>'
document.getElementById("zoomLayer2").innerHTML = HTML;
document.getElementById('zoomLayer1').style.visibility='visible';
}

function close1() {
	//alert("click");
	//document.getElementById('zoomLayer1').style.visibility='hidden';
}

function show(val,item,ajaxUrl) {
HTML = '<form id="emailForm">';
HTML += '<table cellpadding="8" cellspacing="8" width="550">';
HTML += '<tr><td>&nbsp;</td></tr>'
HTML += '<tr><td height="20" align="right" width="35%"><span  style="font-size:14px;font-weight:bold;">Your Email Address: </span></td>';
HTML += '<td height="20" align="left" style="padding-left:12px;"><input type="text" name="yourEmail" id="yourEmail" value="" size="53"></td></tr>';
HTML += '<tr><td width="35%"></td><td height="20" style="padding-left:12px;"><table border="0" width="98%"><tr><td align="light"><input type="checkbox" name="joinList" id="joinList" value="1" CHECKED> Add me to the mailing list </td>';
HTML += '<td align="right"><input type="checkbox" name="sendCopy" id="sendCopy" value="1" CHECKED> Send me a Copy</td></tr></table></td></tr>';
HTML += '<tr><td height="20" valign="top" align="right" width="35%" nowrap><span  style="font-size:14px;font-weight:bold;">Recipient&#39;s Email Address: </span><input type="hidden" name="id" id="id" value="" size="10"></td>';
HTML += '<td height="20" align="left" style="padding-left:10px;"><table><tr><td><input type="text" name="email" id="email" value="" size="53"></td></tr><tr><td align="center"><span style="font-size:8pt;" >(Separate multiple email address with commas)</span><input type="hidden" name="ajaxURL" id="ajaxURL" value="" size="10"></td></tr></table></td></tr>';
HTML += '<tr><td width="35%" valign="top" align="right"><table width="100%" border="0"><tr><td align="right" ><span  style="font-size:14px;font-weight:bold;">Message (Optional):</span></td></tr><tr><td height="130" align="right"><img src="/images/macklowe-gray-logo.jpg" width="150" height="67" border="0"></td></tr></table></td>';
HTML += '<td align="left" style="padding-left:12px;"><textarea name="message" id="message" rows="10" WRAP="SOFT" style="font-family:arial;width:98%;"></textarea><br \><span style="font-size:10px;">(500 Character Limit)</span></td></tr>';
HTML += '<tr><td width="35%"></td><td align="right" style="padding-right:4px;"><input type="button" name="send" Value="Send" style="width:80px;font-weight:bold;background-color:#E2E3E5;" onclick="sendEmail()"></td></tr>';
HTML += '</table></form>';
document.getElementById("layer2").innerHTML = HTML;
document.getElementById('layer1').style.visibility='visible';
document.getElementById('id').value = val;
document.getElementById('itemName').innerHTML = '<span style="font-weight:bold;font-size:16px;color:#bf620b;">'+unescape(item).replace(/\+/g," ").replace(/&amp;/g,"&")+'</span><br /><br /><span style="font-size:12px;font-style:italic;" >(A link to this page will be included in your message.)</span>';
document.getElementById('ajaxURL').value = ajaxUrl;
}

function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   return null;
 }

var req = createXMLHttpRequest();


function sendEmail1(frm, file) {
	str = getForm(frm);
	//alert ("str : " + str);
	url="http://macklowegallery.com/"+file+"?"+str;
	req.open("GET",url,true);
	req.onreadystatechange=handleResponse;
	req.send(null);
}

function sendEmail() {
frm = document.getElementById("emailForm")
file = "gallery-item-send-email.asp"
	str = getForm(frm);
	ajaxLink = document.getElementById('ajaxURL').value;
//	alert ("str : " + ajaxLink);

	url=ajaxLink+"/"+file+"?"+str;
	req.open("GET",url,true);
	req.onreadystatechange=handleResponse;
	req.send(null);
}

function handleResponse() { 

	if (req.readyState==4) {
		var response1
		var response = req.responseText;

		//alert (response);
		var splitResponse = response.split(";");

		if(splitResponse[0] == "Success") {
			//document.displayItem.submit();
			document.getElementById('layer1').style.visibility='hidden';
			window.open ("http://macklowegallery.com/gallery-item-request-success.asp/item/"+splitResponse[1]+"/eid/"+splitResponse[2],'_self');
			}	
		else{
			document.getElementById("itemName").innerHTML = "";
			document.getElementById("layer2").innerHTML = "</b>Error: " +response+"</b>";
  		}
	}
}

function getForm(fobj) {
 var str = "";
 var fv = "";
 var fn = "";
 var els = "";
 
 for(var i = 0; i < fobj.elements.length; i++) {
  els = fobj.elements[i];
  fv = els.value;
  fn = els.name;
  
 switch(els.type) {
  case "text":
  case "hidden":
  case "password":
  case "textarea":
  
  str += fn + "=" + encodeURI(fv) + "&";
  break; 

  case "checkbox":
  case "radio":
   if(els.checked) str += fn + "=" + encodeURI(fv) + "&";
	break;	

  case "select-one":
	str += fn + "=" +
	els.options[els.selectedIndex].value + "&";
  break;
  } // switch
 } // for
 str = str.substr(0,(str.length - 1));
 return str;
}
