﻿xmlDoc=loadXMLDoc("portfolio.xml");
var xmlPic=xmlDoc.getElementsByTagName("Picture");
xmlDoc=loadXMLDoc("Artist.xml");
var xmlArt=xmlDoc.getElementsByTagName("Artist");

var email     = "Jenny"
var emailHost = "JennyPrice"
var emaildom  = ".net"

xleng=xmlPic.length;

thumbsPerRow=4;
thumbCellWidth="20px";

i=geturlparam( 'picture' );

function loadXMLDoc(dname)
	{
	if (window.XMLHttpRequest)
	  {xhttp=new XMLHttpRequest();}
	else
	  {xhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	xhttp.open("GET",dname,false);
	xhttp.send("");
	return xhttp.responseXML;
	} 

function geturlparam( name )
	{  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
		var regexS = "[\\?&]"+name+"=([^&#]*)";  
		var regex = new RegExp( regexS );  
		var results = regex.exec( window.location.href );  
		if( results == null )    
	return "";  else    return results[1];
	}
	
function next()
	{
	if (i<xmlPic.length-1)
	  {i++;}
	  else
	  {i=0;}
	displaypicture();
	}

function previous()
	{
	if (i>0)
	  {i--;}
	  else
	  {i=xleng-1;}
	displaypicture();
	}
	
function displaypicture()
	{
	try {title		=(xmlPic[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);}			catch (er) {title	="untitled"; }
	try {year		=(xmlPic[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue);}			catch (er) {year	=2009; }
	try {desc		=(xmlPic[i].getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);}	catch (er) {desc	="not found"; 	}
	try {pic		=(xmlPic[i].getElementsByTagName("PIC")[0].childNodes[0].nodeValue);}		    catch (er) {pic		="MisssingPicture.png"; }
	try {price		=(xmlPic[i].getElementsByTagName("PRICE")[0].childNodes[0].nodeValue);}		    catch (er) {price	=0.00; 	}
	try {pnp		=(xmlPic[i].getElementsByTagName("PnP")[0].childNodes[0].nodeValue);}		    catch (er) {pnp		=0.00; 	}
	try {size		=(xmlPic[i].getElementsByTagName("Size")[0].childNodes[0].nodeValue);}			catch (er) {size	=""; }
	try {artistFN	=(xmlArt[0].getElementsByTagName("NameF")[0].childNodes[0].nodeValue);}    		catch (er) {artistFN="not found";}
	try {artistWN	=(xmlArt[0].getElementsByTagName("NameW")[0].childNodes[0].nodeValue);}    		catch (er) {artistwWN="not found";}
	try {A3print	=(xmlArt[0].getElementsByTagName("A3print")[0].childNodes[0].nodeValue);}    	catch (er) {A3print="N";}
	
	document.getElementById("showmenu").innerHTML=
 	  "<form name=\"Home\" 		action=\"index.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Home\" >		</form>"
 	+ "<form name=\"Portfolio\"	action=\"portfolio.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Portfolio\">	</form>"
 	+ "<form name=\"Profile\" 	action=\"profile.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Profile\">		</form>"
 	+ "<form name=\"Poems\" 	action=\"poems.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Poems\">		</form>"
 	+ "<form name=\"Email\" 	action=\"" + "mail" + "to:" + email + "@" + emailHost + emaildom + "\""
 	+ 														"style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Email\">		</form>"
	+ "<br>" 
	+ "<input type=\"button\" onclick=\"previous()\" style=\"width: 120px\" value=\"previous\">"
	+ "<input type=\"button\" onclick=\"next()\"     style=\"width: 120px\" value=\"next\"    >"
	+ "<br><br>" 
	+ title 
	+ "<br><br>" 
	+ desc 
    ;

	document.getElementById("showbody").innerHTML="<img src=\"portfolio/" + pic + "\" onclick=\"next()\" alt=\"\">"
	;

	document.getElementById("showprice").innerHTML=
	"<br>" 
	+ size 
	+ "<br><br>" 
	+ year 
	+ "<br><br>" 
	+ "£" + price + "<small> (+ PnP £" + pnp + ")</small>"
	+ "<br><br>" 
	
	+ "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">"
	+ "<input type=\"hidden\" name=\"cmd\" value=\"_xclick\">"
	+ "<input type=\"hidden\" name=\"business\" value=\"3SAHXU6PBXLMC\">"
	+ "<input type=\"hidden\" name=\"lc\" value=\"GB\">"
	+ "<input type=\"hidden\" name=\"item_name\" value=\""
	+ title
	+ " by "
	+ artistWN
	+ "\">"
	+ "<input type=\"hidden\" name=\"amount\" value=\""
	+ price
	+ "\">"
	+ "<input type=\"hidden\" name=\"currency_code\" value=\"GBP\">"
	+ "<input type=\"hidden\" name=\"button_subtype\" value=\"products\">"
	+ "<input type=\"hidden\" name=\"shipping\" value=\""
	+ pnp
	+ "\">"
	+ "<input type=\"hidden\" name=\"bn\" value=\"PP-BuyNowBF:btn_buynow_LG.gif:NonHosted\">"
	+ "<input type=\"image\" src=\"https://www.paypal.com/en_GB/i/btn/btn_buynow_LG.gif\" border=\"0\" name=\"submit\" alt=\"PayPal - The safer, easier way to pay online.\">"
	+ "<img alt=\"\" border=\"0\" src=\"https://www.paypal.com/en_GB/i/scr/pixel.gif\" width=\"1\" height=\"1\">"
	+ "</form>"

    ;

	}

function displayindex()
	{
	try {artistFN=(xmlArt[0].getElementsByTagName("NameF")[0].childNodes[0].nodeValue);}	catch (er)	 {artistFN="not found";}

	document.getElementById("showmenu").innerHTML=
 	  "<form name=\"Home\" 		action=\"index.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Home\"	disabled=\"disabled\" >	</form>"
 	+ "<form name=\"Portfolio\"	action=\"portfolio.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Portfolio\" >				</form>"
 	+ "<form name=\"Profile\" 	action=\"profile.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Profile\">					</form>"
 	+ "<form name=\"Poems\" 	action=\"poems.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Poems\">					</form>"
 	+ "<form name=\"Email\" 	action=\"" + "mail" + "to:" + email + "@" + emailHost + emaildom + "\""
 	+ 														"style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Email\">		</form>"
    ;
	}

function displayprofile()
	{
	try {artistFN=(xmlArt[0].getElementsByTagName("NameF")[0].childNodes[0].nodeValue);}	catch (er)	 {artistFN="not found";}

	document.getElementById("showmenu").innerHTML=
 	  "<form name=\"Home\" 		action=\"index.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Home\">					</form>"
 	+ "<form name=\"Portfolio\"	action=\"portfolio.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Portfolio\" >				</form>"
 	+ "<form name=\"Profile\" 	action=\"profile.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Profile\" disabled=\"disabled\" >	</form>"
 	+ "<form name=\"Poems\" 	action=\"poems.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Poems\">					</form>"
 	+ "<form name=\"Email\" 	action=\"" + "mail" + "to:" + email + "@" + emailHost + emaildom + "\""
 	+ 														"style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Email\">		</form>"
    ;
	}

function displaypoems()
	{
	try {artistFN=(xmlArt[0].getElementsByTagName("NameF")[0].childNodes[0].nodeValue);}	catch (er)	 {artistFN="not found";}

	document.getElementById("showmenu").innerHTML=
 	  "<form name=\"Home\" 		action=\"index.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Home\">					</form>"
 	+ "<form name=\"Portfolio\"	action=\"portfolio.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Portfolio\" >				</form>"
 	+ "<form name=\"Profile\" 	action=\"profile.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Profile\">					</form>"
 	+ "<form name=\"Poems\" 	action=\"poems.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Poems\"disabled=\"disabled\" >		</form>"
 	+ "<form name=\"Email\" 	action=\"" + "mail" + "to:" + email + "@" + emailHost + emaildom + "\""
 	+ 														"style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Email\">		</form>"
    ;
	}

function displaypoem()
	{
	try {artistFN=(xmlArt[0].getElementsByTagName("NameF")[0].childNodes[0].nodeValue);}	catch (er)	 {artistFN="not found";}

	document.getElementById("showmenu").innerHTML=
 	  "<form name=\"Hsome\" 		action=\"../index.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px;  color: #3CB371;\" value=\"Home\">				</form>"
 	+ "<form name=\"Portfolio\"	action=\"../portfolio.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Portfolio\" >				</form>"
 	+ "<form name=\"Profile\" 	action=\"../profile.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Profile\">				</form>"
 	+ "<form name=\"Poems\" 	action=\"../poems.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Poems\" >				</form>"
 	+ "<form name=\"Email\" 	action=\"" + "mail" + "to:" + email + "@" + emailHost + emaildom + "\""
 	+ 														"style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Email\">		</form>"
    ;
	}

function displayportfolio()
	{
	try {artistFN=(xmlArt[0].getElementsByTagName("NameF")[0].childNodes[0].nodeValue);}	catch (er)	 {artistFN="not found";}

	document.getElementById("showmenu").innerHTML=
 	  "<form name=\"Home\" 		action=\"index.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Home\">					</form>"
 	+ "<form name=\"Portfolio\"	action=\"portfolio.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Portfolio\" disabled=\"disabled\" >	</form>"
 	+ "<form name=\"Profile\" 	action=\"profile.html\" 	style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Profile\">					</form>"
 	+ "<form name=\"Poems\" 	action=\"poems.html\" 		style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Poems\">					</form>"
 	+ "<form name=\"Email\" 	action=\"" + "mail" + "to:" + email + "@" + emailHost + emaildom + "\""
 	+ 														"style=\"margin: 0px; padding: 0px\">	<input type=\"submit\" style=\"width: 120px\" value=\"Email\">		</form>"

	txt="<table border='0'><tr valign=\"top\" style=\"width: " + thumbCellWidth + "\">";

	r=0;
	for (i=0;i<xmlPic.length;i++)
		  {
		    try {
				smallpic=xmlPic[i].getElementsByTagName("PICS")[0].firstChild.nodeValue;
				title=xmlPic[i].getElementsByTagName("TITLE")[0].firstChild.nodeValue;
				}
		    catch (er) {
		    	smallpic="not found";
		    	title="not found";
		    	}
			{txt=txt 
		    	+ "<td><a href=\"picture.html?picture=" + i + "\"> <img src=\"Portfolio/" 
		    	+ smallpic
		    	+ "\" alt=\"click to see details\" style=\"border-style: none\"></a>"
	      		+ "<br>" 
	      		+ title 
	      		+ "</td>";
	      	}
			if ((i+1)%thumbsPerRow==0)
			  {txt=txt + "</tr><tr valign=\"top\" style=\"width: " + thumbCellWidth + "\">";}
		 }
	txt=txt + "</table>";
	document.getElementById('showbody').innerHTML=txt;
	}