// Add On Scripts for Tania King Photography Site Functionality

// 'Bookmark This Page' function.
function addBookmark(title,url) { 
 	if (window.sidebar) { 
 		window.sidebar.addPanel(title, url,""); 
 	} else if( document.all ) { 
 		window.external.AddFavorite( url, title); 
 	} else if( window.opera && window.print ) { 
 		return true; 
	} 
}

// Email This Page To A Friend
function eMailPage(thePage) {
	var url = "/_cfm/eMailTo.cfm?thePage="+thePage;
	var newWindow = window.open(url,"eMailTo","height=300,width=700,top=200,left=100");
}


/* Create the Cookie */
function addToCart(theImage, theCategory, theRef, stock, prMat, poster) {
	var nextMonth = new Date();
	nextMonth.setMonth(nextMonth.getMonth() +1);
/*    alert("next  month = " +nextMonth); 

alert(theImage + ":" + theCategory);*/
	var oldValue ="";
	var duplicate = -1;
	var newValue = theCategory + "/" + theImage + "&" + theRef + "&" + stock + "&" + prMat + "&" + poster +"?";
	var allCookies = document.cookie;
	var pos = allCookies.indexOf("TKPHOTOCART=");
	if (pos != -1) { 
		var start = pos + 12;
		var end = allCookies.indexOf(";", start);
/* alert("end = " + end); */
		if (end == -1) end = allCookies.length; {
			var oldValue = allCookies.substring(start, end);
			
/* alert("cookie found. \n oldValue = " + oldValue + "\n newValue = " + newValue); */

			var duplicate = oldValue.indexOf(newValue);

			if (duplicate == -1) {
				var newValue = oldValue + newValue;
				alert('This image has been added to your Cart.');
			} else {
				var newValue = oldValue;				
			}
/* alert("duplicate bool = "  + duplicate); */
		}
	 } else {
/* alert("no cookie found"); */
		alert('This image has been added to your Cart.');
	}
/* alert("new value to write =" + newValue); */
	document.cookie = "TKPHOTOCART=" + newValue + "; expires=" + nextMonth.toGMTString() + "; Path=" + "/";
} 

function removeImage(thisImage) {

	var nextMonth = new Date();
	nextMonth.setMonth(nextMonth.getMonth() +1);

	var removeValue = thisImage;
	var allCookies = document.cookie;
	var pos = allCookies.indexOf("TKPHOTOCART=");
	var start = pos + 12;
	var end = allCookies.indexOf(";", start);
	if (end == -1) end = allCookies.length; {
		var oldValue = allCookies.substring(start, end);
		var removeStart = oldValue.indexOf(removeValue);
		var removeEnd = removeValue.length + removeStart;
		var newValue = oldValue.substring(0,removeStart) + oldValue.substring(removeEnd,oldValue.length);
	}
	document.cookie = "TKPHOTOCART=" + newValue + "; expires=" + nextMonth.toGMTString() + "; Path=" + "/";
	document.location = "order.cfm";
}