// Open Pop-Up Window
function openWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}


// Open Pop-Up Send to friend
    function popitup(url) {
	newwindow=window.open(url,'name','resizable=1,scrollbars=1,height=450,width=550');
	if (window.focus) {newwindow.focus()}
	return false;
}

function size_guide(sPicURL) {
    window.open(sPicURL, "",
    "resizable=1,scrollbars=1,height=650,width=800");
}

function form(sPicURL) {
    return window.open(sPicURL, "", "resizable=1,scrollbars=1,height=500,width=500");
}

// Navigation for IE
navHover = function() {
	var navLi = document.getElementById("navigation").getElementsByTagName("LI");
	for (var i=0; i<navLi.length; i++) {
		navLi[i].onmouseover=function() {
			this.className+=" over";
		}
		navLi[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);


function showPic(whichpic,whichurl) {
  if (!document.getElementById("placeholder")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("placeholder");
  var placeholderlink = document.getElementById("placeholderlink");
  placeholder.setAttribute("src",source);
  placeholderlink.setAttribute("href",whichurl);
  if (!document.getElementById("description")) return false;
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  var description = document.getElementById("description");
//  if (description.firstChild.nodeType == 3) {
//    description.firstChild.nodeValue = text;
//  }
//  return false;
}


// Bookmarking
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  	window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

// Read Cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

	
function bookmarkPage(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "");
}




 window.addEvent('domready', function() {  
       
       
     //store titles and text  
     $$('.Tips2').each(function(element,index) {  
         var content = element.get('title').split('::');  
         element.store('tip:title', content[0]);  
         element.store('tip:text', content[1]);  
     });  

     //create the tooltips
     var tipz = new Tips('.Tips2',{
         className: '.Tips2',
         fixed: true,
         hideDelay: 50,
         showDelay: 50
     });

 });



// Helper for the Quote tool, creates new or duplicate rows in the given table
// @param   string      source      The ID of the containing table
// @param   boolean     as_new      Flag to indicate if the row should be cloned, or with new values.
function duplicateRow(source, as_new) {
    if (! $(source)) {
        return;
    }
    try {
        // Locate the target table and clone the last row.
        var rows = $(source).getChildren('tr');
        if (rows.length < 1) {
            // No rows found!
            return false;
        }
        var row = rows[rows.length - 1];
        var row2 = row.cloneNode(true);
        
        // Append to the DOM
        $(source).appendChild(row2);
        if (as_new == false) {
            // A cloned row, and this is an IE hack!
            var rowOpts = row.getElements('select');
            var row2Opts = row2.getElements('select');
            for(i = 0; i < rowOpts.length; i++){
                row2Opts[i].selectedIndex = rowOpts[i].selectedIndex;
                if (row2Opts[i].get('onchange')) {
                    //Need to add the correct class name
                    var opts = PPExclusion.getSelectProperties($(row2Opts[i]));
                    if (opts) {
                        row2Opts[i].removeClass(opts.orig);
                        row2Opts[i].addClass(opts.nextRow);
                    }
                }
            }
        }
        else {
            // A new row, so remove all selections copied from the old row.
            var ipts = row2.getElements('input');
            var opts = row2.getElements('select');
            for (var i = 0, l = ipts.length; i < l; i++) {
                ipts[i].set('value', '');
            }
            for (i = 0, l = opts.length; i < l; i++) {
                opts[i].selectedIndex = 0;
                //Need to add the correct class name
                var o = PPExclusion.getSelectProperties($(opts[i]));
                if (o) {
                    opts[i].removeClass(o.orig);
                    opts[i].addClass(o.nextRow);
                }
            }
        }
    } catch (e) {
        alert("Failed to find last row: " + e.message);
        return false;
    }
}

function checkWeHaveQuantity() {
    if($('frm_quantity')) {
        var proceed = false;
        var qty_boxes = $$("#frm_quantity .sizes");
        var qty_message = $('qty_message');
        qty_boxes.each(function(item) {
            var val = item.value;
            if(val !=='0' && val !=="") {
                proceed = true;
				item.removeClass('qty_message');
            } else { 
                item.addClass('qty_message');
            }	
        });
        if(proceed) {
            qty_message.setHTML('&nbsp;');
            return true;
        } else {
            qty_message.set('html',"Choose Size & Quantity before adding to your basket.");
			qty_message.setStyle('display', 'block');
			
            return false;
        }
    }
}



