﻿var no_redir=false;
var gotoCatalogpage="../catalog/catalog.aspx"

function showCollectionGroupIcons(GID,CC) {
    gotoURL(getURLandView()+ "&curCat=" + CC + "&grpIcons=" + GID + getCat())
}

function showCollectionIcons(CID,CC) {
    gotoURL(getURLandView()+ "&curCat=" + CC + "&collIcons=" + CID + getCat())
}

function openCollection(CID,CC) {
    gotoURL(getURLandView()+ "&curCat=" + CC + "&showColl=" + CID + getCat())
}


function showProductClassImgs(CC,PCID) {
    gotoURL("product.aspx?view=prd&showPCIcons=" + PCID )
}

function showProducts(CC,PCID) {
    gotoURL("product.aspx?view=prd&showPCID=" + PCID)
}


function getURLandView() {	
	try {
       var curl=document.location.href;
       var sarr= new Array;
       sarr=curl.split("?view=")
       var cview=sarr[1]
       cview=cview.substring(0,3)
       //sarr=sarr[0].split("/")
       //sarr.reverse()
       //return sarr[0]+ "?view=" + cview 
	   return gotoCatalogpage + "?view=" + cview 
	} catch(ex) {
       return gotoCatalogpage + "?view=cat" 
	}
}

function getCat() {
	var ccs
    var cc=querySt("chgCat")
	if (cc!="") {
		ccs="&chgCat=" + cc
	} else { ccs="" }
	return ccs
}

function querySt(ji) {
   hu = window.location.search.substring(1);
   gy = hu.split("&");
   for (i=0;i<gy.length;i++) {
     ft = gy[i].split("=");
     if (ft[0] == ji) {
        return ft[1];
     }
   }
   return "" 
}


function changeCatalog(obj) {
    gotoURL(getURLandView()+ "&chgCat=" + obj.value)
}

function chgCatalog(catID) {
    gotoURL(getURLandView()+ "&chgCat=" + catID)
}


function changeTheme(obj) {
    gotoURL(getURLandView()+ "&shThemes=" + obj.value + getCat())
    
}

function onNewLineGoSearch(event) {
  var kc;
  try {kc=event.which;}
  catch(ex) { kc=window.event.keyCode;} 
  finally {
      try {kc=window.event.keyCode;} catch(ex) {;} finally{;}; 
  };
  if (kc=="13") { 
     goSearch();
  }
} 

function goSearch() {	
	if (document.getElementById("srchText").value.replace(/ /g,'')=="") {
		alert("Please enter a search text.")
		return;
	}
	var no=""
	//if (document.getElementById("onlyNew").checked) {
	//	no="&NewO=1"
	//}
    gotoURL(getURLandView()+ "&srchTxt=" + document.getElementById("srchText").value + getCat() + no )
}

function genPages(Pg,Pgs) {	
	if (Pg>1) {
		document.write("<a href='javascript:gotoPage("+(Pg-1)+")'>&lt;&lt;</a>")
	}
	var lPg=Pg-5;
	var rPg=Pg+5;
	if (lPg<1) {lPg=1};
	if (rPg>Pgs) {rPg=Pgs};
	for (i=lPg;i<=rPg;i++) { 
	  if (Pg==i) {		  
		  document.write (" <b>"+i+"</b>") 
	  } else {
		  document.write (" <a href='javascript:gotoPage("+i+")'>"+i+"</a> ") 
	  }
	};
	if (Pg<Pgs) {
		document.write("<a href='javascript:gotoPage("+(Pg+1)+")'>&gt;&gt;</a>")
	}
}

function gotoPage(Pg) {
    var curl=document.location.href;
    var sarr= new Array;
    sarr=curl.split("&Pg=")
    gotoURL(sarr[0] + "&Pg="+Pg)
}

function viewDetails(ID) {	
	if (no_redir==true) { no_redir=false; return }
    gotoURL(getURLandView()+ "&details=" + ID + getCat())
}

function ViewDetails(ID) {
    setTimeout("viewDetails("+ID+")",500)
}

function AddToList() {
	alert('add to list');
}

function emailToaFriend(){
    gotoURL("mailto:?subject=I'm sending you this link from Sandylion's Scrapbooking site&body=Visit this link to view the product "+ escape(document.location.href) + ".")
}

var lrgImgObj;

function enlargeImage(ID) {
   var pos=getElementPos(document.getElementById("CCThumbNail"))
   document.getElementById('ccLargeImage').src="image.aspx?ID="+ID
   dd.elements.ImgWin.moveTo(pos[0],pos[1]+70)
   document.getElementById('ImgWin').style.visibility="visible"
}

function getElementPos(el)
{
    if(typeof(el.offsetParent) == "undefined")
        return [70, 4000];
	var a = new Array(0, -70);
	while(el)
	{
		a[0] += el.offsetLeft || 0;
		a[1] += el.offsetTop || 0;
		el = el.offsetParent || null;
	}
	return a;
}


function hideLargeImage() {
   document.getElementById('ImgWin').style.visibility="hidden"
}
   var noCartMsg=false;

   function AddToCart(productId,qty) {
	  no_redir=true;
      var t= new Date();
      var d = new Date(t.getTime() + 1200000); //expires in 20 min 20*60*1000
      var myCart=GetCookie("imageBin");
      if (myCart.indexOf("#" + productId + "|")>-1) { alert ("Item is already in your cart.");return;}
      document.cookie = "imageBin=" + myCart + "#" + productId + "|"  + qty + ";expires="+d.toGMTString+";";
      if (noCartMsg==false) {alert ("Item added to your cart.");}	  
   }

   function RemoveFromCart(productId) {
      var t= new Date();
      var d = new Date(t.getTime() + 1200000); //expires in 20 min 20*60*1000

      var myCart=GetCookie("imageBin");
      if (myCart!="") {
         if (myCart.indexOf(productId + "|")>-1) { 
            var re = new RegExp("#" + productId + "\\|\\d+")
            var rs = myCart.replace(re,"");
            document.cookie = "imageBin=" + rs + ";expires="+d.toGMTString+";";
            if (noCartMsg==false) {if (rs=="") {alert("Your cart is empty.")} else {alert ("Item is removed from your cart.");}}
         } else {
            if (noCartMsg==false) {alert("Item not found in your cart.");}
         }
      } else {
        if (noCartMsg==false) {alert("Your cart is empty.");}
      }
      gotoURL(document.location.href)
   }

   function RemoveAllFromCart() {
      var t= new Date();
      var d = new Date(t.getTime() + 1200000); //expires in 20 min 20*60*1000
      document.cookie = "imageBin=;expires="+d.toGMTString+";";
      gotoURL(document.location.href)
   }

   
   function GetCookie(sName)
   {
      var aCookie = document.cookie.split("; ");
      for (var i=0; i < aCookie.length; i++)
      {
         var aCrumb = aCookie[i].split("=");
         if (sName == aCrumb[0]) 
         return unescape(aCrumb[1]);
      }
      return "";
   }
   
   function printCartList() {
      openInNew (600,400,"printCart.aspx")
   }

  function openInNew (wdth,hgh,url_add) {
       var msie;
       if(navigator.appName.indexOf("Internet Explorer")!=-1) { mie=true; } else { mie=false; };
       if (mie) {
	   var features = 'toolbar=no,location=no,directories=no,status=no,menubar=no,' +
   	                  'scrollbars=yes,titlebar=no,resizable=no,width='+ wdth +',height='+hgh; 
           var posleft = window.screenLeft + ((window.screen.width - wdth) / 2)
           var postop = window.screenTop + ((window.screen.height - hgh) / 2)-100
           features=features + ",left=" + posleft + ",top=" + postop;
           var xxx=window.open (url_add,"",features);
	   
	   return xxx;
	} else {
	   var features = 'toolbar=no,location=no,directories=no,status=no,menubar=no,' +
   	                  'scrollbars=yes,titlebar=no,resizable=no,innerWidth='+wdth+',innerHeight='+hgh
           var posleft = window.screenX + ((window.outerWidth - wdth) / 2)
           var postop = window.screenY + ((window.outerHeight - hgh) / 2)
           features=features + ",left=" + posleft + ",top=" + postop;
           return window.open (url_add,"",features);
	}
	
  } 

  function gotoURL(urln) {
    var mie;
    if(navigator.appName.indexOf("Internet Explorer")!=-1) { mie=true; } else { mie=false; };
    if (mie) {
      try {
        document.getElementById("simClick").href=urln;
        document.getElementById("simClick").click();
      } catch(ex) {
         simClick=document.createElement("A") ;
         simClick.href=urln;
         document.body.insertBefore(simClick,null)
         simClick.click();
      }

    } else {
      document.location.href=urln;
    }
  }
  
  function editProductName(id) {
      PopUpModalDialog("ccEditProp.aspx?ID="+id,600,360,"gotoURL(document.location.href)",100,-1,false,"Edit Product Properties")
  }
  

   function AddToOrder(productId,qty) {
	  no_redir=true;
      var t= new Date();
      var d = new Date(t.getTime() + 1200000); //expires in 20 min 20*60*1000
      var myCart=GetCookie("orderBin");
      if (myCart.indexOf( productId + ",")>-1) { alert ("Item is already placed in your online order cart.");return;}
      document.cookie = "orderBin=" + myCart +  productId + ",;expires="+d.toGMTString+";";
      if (noCartMsg==false) {alert ("Item added to your online order cart.");}	  
   }

   function BuyOnLine(url) {
	  no_redir=true;
	  window.open(url)
   }


function disableForm(oid) {
   try {
	var obj=document.getElementById(oid)
	while (obj.tagName!="FORM") {
		obj=obj.parentNode
	};
	obj.action="javascript:doNothing()"
   } catch(ex) { }
}

function doNothing() {
}