//copyright Kieran Guckian 2003
picshown=0;
currentcount=0;
i=0;
endnum=0;
writestring="";

var price1;
var price2;

var message="";
var d="";
varstring=document.location.href;
var oneArray=varstring.split("?");
if(oneArray.length>1){
	var string1=oneArray[1];
	var twoArray = string1.split("&");
	customer=twoArray[0];
	customer = customer.replace(/%20/g," ");
	folder=twoArray[1];
	prefix=twoArray[2];
	totalpics=twoArray[3];
	d=twoArray[4];
	pathsmall=folder+"/"+prefix+"_";
	pathlarge=folder+"/"+prefix;
	if(d=="No"|| d=="no"){
	
		price1="25.00";
		price2="35.00";
	}else if(prefix=="marathon"){
		price1="10.00";
		price2="15.00";
	}else{
		price1="15.00";
		price2="20.00";
	}
}






function showForm(){
	alert(document.forms[0].elements["imageid"].value + "---" + document.forms[0].elements["imagenum"].value + "---" + document.forms[0].elements["shootid"].value);
}

function smallLink(){
	if(document.all){
				document.all['pic'].innerHTML=writestring;
	}else if(document.getElementById){
				n=document.getElementById("pic");
				n.innerHTML=writestring;
	}else if(document.layers){
				document.layers["pic"].document.open();
				document.layers["pic"].document.write(writestring)
       			document.layers["pic"].document.close();
	}
}



function clearPic(){
writestring=" ";
	if(document.all){
		document.all['pic'].innerHTML=writestring;
	}else if(document.getElementById){
		n=document.getElementById("pic");
		n.innerHTML=writestring;
	}else if(document.layers){
		document.layers["pic"].document.open();
		document.layers["pic"].document.write(writestring);
       	document.layers["pic"].document.close();
	}
}


	function showLarge(num){
		if(document.all){
			document.all['large'].innerHTML=(customer + '  ' + num + ' of ' + totalpics+'<br><img src="'+pathlarge+num+'.jpg" alt=" ">');
		}else if(document.getElementById){
			p=document.getElementById("large");
			p.innerHTML=('<img src="'+pathlarge+num+'.jpg" alt=" ">');
		}else if(document.layers){
			document.layers["large"].document.open();
			document.layers["large"].document.write('<img src="'+pathlarge+num+'.jpg" alt=" ">');
       			document.layers["large"].document.close();
		}
		writeForm(num);
	}




	function writeThumbs(){

		if(picshown>=totalpics){
			// do nothing
			
		}else if(picshown>(totalpics-6)){
			clearPic();
			startnum=i;//this is for back
				while(currentcount<(totalpics-picshown)){
					i++;
					writestring+='<a href="javascript:showLarge('+i+');"><img src="'+pathsmall+i+'.jpg"  class="thumb"></a>';
					currentcount++;
				}
				writestring+='<div class="rightholder"><a href="javascript:writeBack();" title="view previous six thumbnails">previous</a> | <a href="javascript:writeThumbs();" title="view next six thumbnails">next</a></div>';
				smallLink();
				endnum=i-startnum;
				currentcount=0;
				picshown=totalpics;
		}else{
			clearPic();
				while(currentcount<6){
					i++;
					writestring+='<a href="javascript:showLarge('+i+');"><img src="'+pathsmall+i+'.jpg" class="thumb"></a>';
					currentcount++;
				}
				writestring+='<div class="rightholder"><a href="javascript:writeBack();" title="view previous six thumbnails">previous</a> | <a href="javascript:writeThumbs();" title="view next six thumbnails">next</a></div>';
				smallLink();
				currentcount=0;
				picshown+=6;
		}

		
	}


	function writeBack(){
	
			if(picshown==6){
				
			}else if(picshown==totalpics){
				clearPic();
					if(endnum>0){
					i-=endnum+6;
					picshown-=endnum;
					}else{
					i-=12;
					picshown-=6;
					}
				
					while(currentcount<6){
						i++;
					writestring+='<a href="javascript:showLarge('+i+');"><img src="'+pathsmall+i+'.jpg" class="thumb"></a>';
						currentcount++;
					}
				writestring+='<div class="rightholder"><a href="javascript:writeBack();" title="view previous six thumbnails">previous</a> | <a href="javascript:writeThumbs();" title="view next six thumbnails">next</a></div>';
					smallLink();
					currentcount=0;

			}else if(picshown<6){
				picshown=6;
			}else{
				clearPic();
				i-=12;
				while(currentcount<6){
						i++;
						writestring+='<a href="javascript:showLarge('+i+');"><img src="'+pathsmall+i+'.jpg" class="thumb"></a>';
						currentcount++;
					}
				writestring+='<div class="rightholder"><a href="javascript:writeBack();" title="view previous six thumbnails">previous</a> | <a href="javascript:writeThumbs();" title="view six thumbnails">next</a></div>';
				smallLink();
				currentcount=0;
				picshown-=6;
			}

			
	}

function writeForm(num){

	
	n="";
	if(d=="No"|| d=="no"){
		n+='<h2>Buy this print:</h2>';
	}else{
		n+='<h2>Buy this print at the discount price:</h2>';
	}
	
	n+='<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
	n+='<input type="hidden" name="on0" value="size"><p>Choose size</p>';
	n+='<select name="os0" onChange="updateVal();">';
	n+='<option value="10x7 print">10x7: price '+price2+'</option>';
	n+='<option value="5x7 print">5x7: price '+price1+'</option>';
	n+='</select>';
	n+='<input type="image" style="margin-top:20px;" src="../images/pp.gif" border="0" name="submit" alt="add to pay pal cart">';
	n+='<input type="hidden" name="add" value="1">';
	n+='<input type="hidden" name="cmd" value="_cart">';
	n+='<input type="hidden" name="business" value="info@marknixon.com">';
	n+='<input type="hidden" name="item_name" value="Shoot id: '+customer + " Image number " + num +'">';
	n+='<input type="hidden" name="item_number" value="'+num +'">';
	n+='<input type="hidden" name="amount" value="'+price2+'">';
	n+='<input type="hidden" name="no_shipping" value="2">';
	n+='<input type="hidden" name="return" value="http://www.marknixon.com/thankyou.html">';
	n+='<input type="hidden" name="cancel_return" value="http://www.marknixon.com/cancel.com">';
	n+='<input type="hidden" name="currency_code" value="EUR">';
	n+='</form>';
	
	n+='<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
	n+='<input type="hidden" name="cmd" value="_cart">';
	n+='<input type="hidden" name="business" value="info@marknixon.com">';
	n+='<input type="image" style="margin-top:20px;" src="../images/vc.gif" border="0" name="submit" alt="View your pay pal shopping cart">';
	n+='<input type="hidden" name="display" value="1">';
	n+='</form>';
	
	if(document.getElementById){
		p=document.getElementById("subnav");
		p.innerHTML=(n);
	}else if(document.all){
		document.all['subnav'].innerHTML=n;
	}else if(document.layers){
		document.layers["subnav"].document.open();
		document.layers["subnav"].document.write(n)
       		document.layers["subnav"].document.close();
	}

}

function updateVal(){
	if(document.forms[0].elements["os0"].value=="5x7 print"){
		document.forms[0].elements["amount"].value=price1;
	}else if(document.forms[0].elements["os0"].value=="10x7 print"){
		document.forms[0].elements["amount"].value=price2;
	}
	
}


function writeVform(num, message){
	
	n="";
	
	n+='<h2>Gift Vouchers</h2>';
	n+='<h3>"Everyone deserves at least one good photograph!"</h3>';
	n+='<div class="box">';
	n+='<p>The perfect gift for...<br /><ul><li>new babies,</li><li>families,</li><li>parents,</li><li>grandparents,</li><li>birthdays,</li><li>christenings,</li><li>weddings,</li><li>anniversaries,</li><li>any occasion.</li></ul>';


n+='<p></p><p>Gift Vouchers can be purchased for any amount over &#8364;50.00 and will never expire! (There is no use by date). ';
n+='They can be used for a studio shoot, towards the cost of wedding photography or for any other service we provide.</p>';
n+='</div>';

n+='<div class="box">';
n+='<h3>Special Offer <span style="font-family: verdana, arial, sans-serif;font-size:80%;">*</span></h3>';
n+='<p>Buy a gift voucher for &#8364;85 or more and we will include a beautiful framed photograph.<br />*<em>applies to studio shoots only, one per shoot.</em></p>';
n+='<p>Vouchers can be sent directly to you or the recipient.<br />';
n+='Buy securely online with Paypal. </p>';
	
	
	n+='<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" >';
	n+='<p><label for="voucheramount">'+message+'Enter amount below, using numbers only e.g. 200.00, minimum amount of &#8364;50.00</p>';
	n+='<input type="text" size="30" name="voucheramount" id="voucheramount" onChange="updateVform();" />';
	n+='<input type="hidden" name="cmd" value="_xclick" />';
	n+='<input type="hidden" name="business" value="info@marknixon.com" />';
	n+='<input type="hidden" name="return" value="http://www.marknixon.com/thankyou.html" />';
	n+='<input type="hidden" name="currency_code" value="EUR" />';
	n+='<input type="hidden" name="undefined_quantity" value="1" />';
	n+='<input type="hidden" name="item_name" value="The Portrait Studio Voucher" />';
	n+='<input type="hidden" name="amount" value="'+num+'" />';
	n+='<input type="hidden" name="no_shipping" value="0" />';
	n+='<input type="hidden" name="shipping" value="0" />';
	n+='<input type="hidden" name="cancel_return" value="http://www.marknixon.com/cancel.html" />';
	n+='<input type="hidden" name="no_note" value="0" />';
	n+='<br />';
	n+='<input type="image" src="http://images.paypal.com/images/x-click-but01.gif" name="submit" alt="Buy voucher from pay pal" />';
	n+='</form>';
	n+='</div>';
	
	
	
	if(document.getElementById){
		p=document.getElementById("textblock");
		p.innerHTML=(n);
	}else if(document.all){
		document.all['textblock'].innerHTML=n;
	}else if(document.layers){
		document.layers["textblock"].document.open();
		document.layers["textblock"].document.write(n)
       		document.layers["textblock"].document.close();
	}

}

function updateVform(){
	var c=document.forms[0].elements["voucheramount"].value;
	if((c=="1")||(c=="2")||(c=="3")||(c=="4")||(c=="1.00")||(c=="2.00")||(c=="3.00")||(c=="4.00")){
		 var message="<strong>Please enter an amount higher than the minimum amount allowed. </strong>";
		 alert("Please enter a value higher than the minimum of 5")
	}else{
		
	}
	document.forms[0].elements["amount"].value=c;
}



