/*
 *
 *	Generic library
 *
 */

/* Open external links in new window BEGIN */
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
	var anchor = anchors[i];
	if (anchor.getAttribute("href") &&
	anchor.getAttribute("rel") == "external")
	anchor.target = "_blank";
	}
}
window.onload = externalLinks;
/* Open external links in new window END */




/* addto bookmarks BEGIN */
var addtoLayout=0;						// 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical, 3=Vertical text only
var addtoMethod=1;						// 0=direct link, 1=popup window
var AddURL = encodeURIComponent(document.location.href);	// this is the page's URL
var AddTitle = escape(document.title);	// this is the page title
/* addto bookmarks END */



function popUpImageGallery(pic) {

	/* open a new centred window and (re)focus it */

	var width = 980;
	var height = 700;
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,scrollbars=yes,location=no,left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;

	myWindow = window.open("../popUpGallery.php?productID=" + pic, "imageGallery", windowFeatures);

	// re-focus the window if it`s already open
	myWindow.focus();

}


/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 */
 
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}
 
addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}