/* 
** Compiled by MYROCK LLC for Abrasive Store Only. **
This notice may not be removed. No portion of this page/script may be reproduced without permission.
For getScrollXY function code, please visit the URL specified below. All other functions were based upon other publically available code.
*/


/* SCROLL XY SCRIPT Based menu scripts provided for free by http://www.howtocreate.co.uk. Customers are not charged for use of this script function */
// For unmodified version, visit: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
/* 	Programming note: 'parent' had to be added to IF condition, otherwise 'additem' box would return 0,0 - and therefore IF would think it was false. 
	So, check parent's position. If scrollLeft/Top=0 (which is also 'false') final else condition is executed (values are 0).
	Alerts added. */
function getScrollXY() { 
	//MODIFIED to reference "parent" (so it works in add item win)
	var scrOfX = 0, scrOfY = 0;
	if( typeof( parent.window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		//alert("NS/FF");
		scrOfY = parent.window.pageYOffset;
		scrOfX = parent.window.pageXOffset;
	} else if( parent.document.body && ( parent.document.body.scrollLeft || parent.document.body.scrollTop ) ) {
		//DOM compliant
		//alert("DOM");
		scrOfY = parent.document.body.scrollTop;
		scrOfX = parent.document.body.scrollLeft;
	} else if( parent.document.documentElement && ( parent.document.documentElement.scrollLeft || parent.document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		//alert("IE6 Std. Compliant Mode");
		scrOfY = parent.document.documentElement.scrollTop;
		scrOfX = parent.document.documentElement.scrollLeft;
	} else {
		//alert("Scroll position is 0,0 or browser-type is undefined.");
		scrOfY=0;
		scrOfX=0;
	}
	return [ scrOfX, scrOfY ];
}
/* End SCROLL XY SCRIPT */


//
// Compiled from other sources. Please do a search for 'cookies' in your Web browser for unmodified cookie information!!
//
function setPagPos(cookieName,targetP) { // Remember Page Position (set for return links) by setting its information in a JavaScript Cookie:
	if(targetP!="clear") { // used specifically for clear PROD cookies - car (instead of introducing a new var, re-use targetP)
		var rememberPagePos=getScrollXY()[1];
		pagenm=parent.document.location.href;
		pageparampos = pagenm.indexOf('?'); if (pageparampos > -1) {  pagenm = pagenm.substring(0, pageparampos); /*Strip out ?params ... or it will mess up the return link.. If it's found that vars need to exist in URL, then strip out pos=x from URL string and use & for new pos.*/ }
	} else { /* if it is 'clear'*/ pagenm=""; rememberPagePos=""; }
	//alert(getScrollXY());
	document.cookie = cookieName+"pos="+rememberPagePos+ ";path=/;"; // cookie name is "indxpos" or "prodpos";
	document.cookie = cookieName+"url="+escape(pagenm)+ ";path=/;"; // cookie name is "produrl" (not really used for index pages, since those reference ./)
	if(targetP!="" && targetP!="clear") document.location.href=targetP;
}
function getPagPos(cookieName,targetP) { // pass targetP for Index pages only (all others, pass '')
	// Get Previous Page's position (read by return links)
	var cookieURLName = cookieName+"url="; var cookieName = cookieName+"pos=";
	var position=""; var previousurl="";
	var cookieAtt = document.cookie.split(';');
	for(var i=0;i < cookieAtt.length;i++) {
		var c = cookieAtt[i];
		while (c.charAt(0)==" ") c = c.substring(1,c.length);
		if(c.indexOf(cookieURLName)==0) {
			previousurl=unescape(c.substring(cookieURLName.length,c.length));
		}
		if(c.indexOf(cookieName)==0) {
			position=c.substring(cookieName.length,c.length);
		}
	}
	//alert("DEBUG: COOKIE:"+cookieName+" PREV:"+previousurl+" POS:"+position);
	if(cookieName=="indxpos=") { /*alert("index");*/ previousurl=targetP; } // ignore cookie var for index links (to be SURE "return to index" is actually doing that.
	if(position=="") position=0;
	if(previousurl=="") { /* If Previous URL is empty, then it wasn't set via JS Cookie (or was cleared b/c 'view cart' was clicked from a non-mfg-specific page). 
		Use $prevPage PHP variable instead (set before this page is called, in PHP) */
		document.location.href=prevPage; 
	} else { 
		document.location.href=previousurl+"?pos="+position; 
	}
	return false;
}
