// ---------- mygallery.js ----------
//   Used for the add to my gallery feature on Canvas Etc product pages

var addG ="<img src=\"images/addmy.jpg\" title=\"add to my gallery\" onMouseover=\"icontxt('addg')\" onMouseout=\"icontxt('out')\">"
var removeG="<img src=\"images/removemy.jpg\"  title=\"remove from my gallery\" onMouseover=\"icontxt('removeg')\" onMouseout=\"icontxt('out')\">"
var addG2 ="<img src=\"images/addmy.jpg\" title=\"add to my gallery\">"

function getCookie(NameOfCookie)
{ if (document.cookie.length > 0) 
{ begin = document.cookie.indexOf(NameOfCookie+"="); 
if (begin != -1) 
{ begin += NameOfCookie.length+1; 
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); } 
}
return null; 
}

function setCookie(NameOfCookie, value, expiredays) { 
if (checkCookie(value)) {
var ExpireDate = new Date ();
currCookie = getCookie(NameOfCookie)
if (currCookie==null) {currCookie=""}
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + currCookie + escape(value) + 
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
location.reload();
}
}

function resetCookie(NameOfCookie, value, expiredays) { 
var ExpireDate = new Date ();
currCookie = getCookie(NameOfCookie)
if (currCookie==null) {currCookie=""}
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) + 
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
location.reload();
}

function delCookie (NameOfCookie) 
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
location.reload();
}} 

function showCookie() {
alert(getCookie("mg"))
}


function removefromCookie(removeStr) {
cookieStr = getCookie('mg');
if (cookieStr !== null && cookieStr!=="") { 
x = cookieStr.replace(removeStr , "");
resetCookie('mg', x , 365);
location.reload();
}
}

function checkCookie(value) {
cookieStr = getCookie('mg');
if (cookieStr !== null && cookieStr!=="") { 
var pos = cookieStr.indexOf(value)
if (pos>=0) {return false} else {return true}
} else {return true}
}


function dispMyGallery() {
cookieStr = getCookie('mg');
if (cookieStr !== null && cookieStr!=="") { 
var gallery_array=cookieStr.split("#");
var prodcode="";
var z=0;
while (z < gallery_array.length)
 {
  prodcode=(gallery_array[z]);
if (prodcode.length >0) {
document.write ('<a href="canvas-art-' + prodcode + '.html"><img src="images/canvas-art/' + prodcode + 'g.jpg" title="' + prodname + '"></a> ')
}
  z+=1;
  }
} else {
document.write ("<div id=emptygallery>your favourites gallery is currently empty.<br><br>click on the " + addG2 + " icon underneath the canvas art to add it to your gallery...</div> ")
}

}

function writeGalleryButton(value) {

cookieStr = getCookie('mg');
if (cookieStr !== null && cookieStr!=="") { 
if (checkCookie(value)) {
document.write ("<a href= \"javascript:setCookie( 'mg' ,prodcode + '#', 365 )\" >" + addG + "</a>")
} else {
document.write ("<a href= \"javascript:removefromCookie(prodcode + '#')\" >" + removeG + "</a>")
}
} else {
document.write ("<a href= \"javascript:setCookie( 'mg' ,prodcode + '#', 365 )\" >" + addG + "</a>")
}
}


function printMyGallery() {
cookieStr = getCookie('mg');
if (cookieStr !== null && cookieStr!=="") { 
var gallery_array=cookieStr.split("#");
var prodcode="";
var z=0;
while (z < gallery_array.length)
 {
  prodcode=(gallery_array[z]);
if (prodcode.length >0) {
document.write ('<div class="pcanvas"><img src="images/canvas-art/' +  prodcode +'t.jpg" border=0><br>' + pcode[eval(prodcode)] + '</div>')
}
  z+=1;
  }
} else {
document.write ("<div id=emptygallery>your favourites gallery is currently empty.<br><br>click on the " + addG2 + " icon underneath the canvas art to add it to your gallery...</div> ")
}
}

function zoomMyGallery() {
sizeGuideWin = window.open("print-my-gallery.html", "MyGalleryZoom" , 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=660,height=660')
} 


function icontxt(txt) {
var spaces="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
switch (txt) {
case "out":
dtxt=""
break
case "zoom":
dtxt="view a larger version of this canvas art (zoom)"
break
case "zoompic":
dtxt="click canvas art to view a larger version (zoom)"
break
case "book":
dtxt="add this canvas to your bookmarks/favourites"
break
case "close":
dtxt="see a close up section of part of this canvas art"
break
case "size":
dtxt="view the sizes available for this canvas art"
break
case "addg":
dtxt="add this canvas art to my gallery"
break
case "removeg":
dtxt="remove this canvas art from my gallery"
break
}
document.getElementById('actiontext').innerHTML= spaces + dtxt
}

