var ns4 = document.layers;
var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1)||(navigator.userAgent.indexOf("Opera/5")!=-1);
var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1);
var agt=navigator.userAgent.toLowerCase();
var mac = (agt.indexOf("mac")!=-1);
var ie = (agt.indexOf("msie") != -1); 
var mac_ie = mac && ie;

var imageWin = null;




function getRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while(tempEl != null){
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

function setGenderGirl(){
document.gender_tracking.gender_label.value='girl';
}
function setGenderBoy(){
document.gender_tracking.gender_label.value='boy';
}
function setGenderUnisex(){
document.gender_tracking.gender_label.value='unisex';
}
function setGenderAll(){
document.gender_tracking.gender_label.value='all';
}

function showHideMenuNode(node_id, image_id){
	n = document.getElementById(node_id);
	i = document.getElementById(image_id);
	if(n){
		n.style.display = n.style.display == "none" ? "block" : "none";
		if(i){
			i.src = n.style.display == "none" ? skin_images + "/menu_tree_plus.gif" : skin_images + "/menu_tree_minus.gif";
		}
	}
}

function Checkvalue_monogram(){
	var multi = document.product_page.oa_quantity.value;
	var count = 0;
	var tagName = "option";
	var optid = "";
	var optval = "";
	var newElement = "";
	selct = document.getElementById('mult_field');
	
	if(document.getElementById('select_code')) {
		if(document.getElementById('select_code').value.search(/Set\+of\+2/) != -1) {
			var setmultiplier = 2;
		} else if(document.getElementById('select_code').value.search(/Set\+of\+3/) != -1) {
			var setmultiplier = 3;
		} else {
			var setmultiplier = 1;
		}
	} else {
		var setmultiplier = 1;
	}

	multi = multi * setmultiplier;

	if(document.product_page.oa_add_monogram.checked) {
		document.product_page.oa_monogram_text.disabled = false;
		document.getElementById('oa_monogram').style.display = 'block';
		
		while(count < multi) {
			count++;	
			//document.getElementById('mult_field').innerHTML += "<option value='"+count+"'>"+count+"</option>";
			optid = "opt" + count;
			optval = count;
			var newElement = document.createElement("option");
			newElement.setAttribute('id', optid);
			newElement.setAttribute('value', optval);
			var newText = document.createTextNode(count);
			newElement.appendChild(newText);
			selct.appendChild(newElement);
		}

		document.getElementById('item_count').value = document.product_page.oa_quantity.value * setmultiplier;     
		document.getElementById('mult_field').value = 1; // document.getElementById('item_count').value;
	} else {
		document.getElementById('mult_field').innerHTML = "";
		document.product_page.oa_monogram_text.disabled = true;
		document.getElementById('oa_monogram').style.display = 'none';
		document.product_page.oa_monogram_text.value = "";
		document.getElementById('monogram_item').value = "";
		document.getElementById('item_count').value = "0";
		document.getElementById('monogram_style').value = "";
	}
}


function updateMonogramCount(){
document.getElementById('item_count').value=document.getElementById('mult_field').value;
}

function openSubContent(){
if (document.getElementById('traditional_opt').checked){
document.getElementById('firstname_monogram').style.display="none";
document.getElementById('traditional_monogram').style.display="block";
document.getElementById('monogram_item').value="";
document.getElementById('monogram_style').value="Traditional Monogram";
}
else{if(document.getElementById('firstname_opt').checked){
document.getElementById('firstname_monogram').style.display="block";
document.getElementById('traditional_monogram').style.display="none";
document.getElementById('monogram_item').value="";
document.getElementById('monogram_style').value="Baby's First Name";
}}
}

function updateMonogramItem() {
	if(document.product_page.oa_add_monogram.checked) {
		var multi = document.product_page.oa_quantity.value;
		var count = 0;
		var tagName = "option";
		var optid = "";
		var optval = "";
		var newElement = "";
		selct = document.getElementById('mult_field');
		
		
		if(document.getElementById('select_code')) {
			if(document.getElementById('select_code').value.search(/Set\+of\+2/) != -1) {
				var setmultiplier = 2;
			} else if(document.getElementById('select_code').value.search(/Set\+of\+3/) != -1) {
				var setmultiplier = 3;
			} else {
				var setmultiplier = 1;
			}
		} else var setmultiplier = 1;
	
		multi = multi * setmultiplier;
	
		document.getElementById('mult_field').innerHTML = "";
	
		while(count < multi) {
			count++;	
			//document.getElementById('mult_field').innerHTML += "<option value='"+count+"'>"+count+"</option>";
			optid = "opt" + count;
			optval = count;
			var newElement = document.createElement("option");
			newElement.setAttribute('id', optid);
			newElement.setAttribute('value', optval);
			var newText = document.createTextNode(count);
			newElement.appendChild(newText);
			selct.appendChild(newElement);
		}
	
		document.getElementById('item_count').value = document.product_page.oa_quantity.value * setmultiplier;     
		document.getElementById('mult_field').value = 1; //document.getElementById('item_count').value;
		if(document.product_page.oa_quantity.value == 0) {
			document.getElementById('item_count').value = 0;     
			document.getElementById('mult_field').innerHTML = document.getElementById('mult_field').innerHTML + "<option value='0'>0</option>";
		}
    }
}

var cnt;
function wordcount(count) {
var words = count.split(";");
cnt= words.length;
var ele = cnt;
if(document.product_page.oa_quantity.value < ele){
alert("Monogram exceeded");
}
}

function writeMonogram(){
if (document.getElementById('traditional_opt').checked){
document.getElementById('monogram_item').value=document.getElementById('first_monogram').value+" "+document.getElementById('last_monogram').value+" "+document.getElementById('middle_monogram').value;
}
else{if(document.getElementById('firstname_opt').checked){
document.getElementById('monogram_item').value=document.getElementById('text_add_monogram').value;
}}
}


function getElementHeight(Elem) {
	if(ns4){
		var elem = document.getElementById(Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = document.getElementById(Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}


if(document.layers){
	_browser = "nn";
}
if(document.all){
	_browser = "ie";
}
if(navigator.userAgent.toLowerCase().match("gecko")){
	_browser= "gecko";
}
function isEmail(entry){
	var rex= /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/	
	return rex.test(entry);
}

function delay(gap){ /* gap is in millisecs */
	var then, now; 
	then = new Date().getTime();
	now = then;
	while((now-then) < gap){
		now=new Date().getTime();
	}
}

function showImage(image_url, image_width, image_height){
	image_width = image_width == "" ? 400 : image_width;
	image_height = image_height == "" ? 380 : image_height;

	var w = screen.width;
	var h = screen.height;
	var ww = image_width * 1 + 30;
	var wh = image_height * 1 + 45;
	var wx = (w - ww)/2;
	var wy = (h - wh)/2;
	
	if(imageWin != null){
		imageWin.close();
	}
	imageWin = null;
	imageWin = window.open(
		"", 
		"ProductImageWindow", 
		"titlebar=yes, toolbar=no, menubar=no, status=no, directories=no, resizable=yes, scrollbars=yes, top=" + wy.toString() + ", left=" + wx.toString() + ", width=" + ww.toString() + ", height=" + wh.toString() + ""
	);
	while(imageWin==null);
	imageWin.focus();
	
	imageWin.document.body.innerHTML = "";
	imageWin.document.write('<body style="padding:5px;margin:0px">');
	imageWin.document.write('<div align="center"><img hspace="0" vspace="0" src="' + image_url + '"></div><br/>');
	imageWin.document.write('<div align="center" style="font-family:arial;font-color:black;font-size:11px;"><a href="javascript:window.close();" style="color:#0000AA;">Close Window</a></div>');
	imageWin.document.write('</body>');
	imageWin.width = ww;
	imageWin.height = wh;
}

function showPrinterPage(url){
	var prWin = null;
	prWin = window.open(
		url,
		"PrintVer", 
		"titlebar=yes, toolbar=no, menubar=yes, status=yes, directories=no, resizable=yes, scrollbars=yes, top=20, left=20, width=810, height=600"
	);
	while(prWin==null);
	prWin.focus();
}

function OnButton(bt){
	document.images[bt].src = skin_images + bt + "_on.gif";
	
}
function OffButton(bt){
	document.images[bt].src = skin_images + bt + "_off.gif";
}

function OnMenu(cid){
	document.images["menul_" + cid].src = skin_images + "catl_bg_on.gif";
	document.all["menur_" + cid].background = skin_images + "catr_bg_on.gif";
}
function OffMenu(cid){
	document.images["menul_" + cid].src = skin_images + "catl_bg_off.gif";
	document.all["menur_" + cid].background = skin_images + "catr_bg_off.gif";
}
var RecentTimeOut, CartTimeOut;

function ShowCart(){
	window.clearTimeout(CartTimeOut);
	if(_browser == "ie"){
		cartDiv.style.visibility = 
			cartDiv.style.visibility == "hidden"?"visible":"hidden";
			document.images["cartImage"].src =
				cartDiv.style.visibility == "hidden"?
				(skin_images + "ic_expand.gif"):
				(skin_images + "ic_collapse.gif");
	}
	else if(_browser == "gecko"){
		document.getElementById('cartDiv').style.visibility = 
			document.getElementById('cartDiv').style.visibility == "hidden"?"visible":"hidden";
		document.images["cartImage"].src =
			document.getElementById('cartDiv').style.visibility == "hidden"?
			(skin_images + "ic_expand.gif"):
			(skin_images + "ic_collapse.gif");
	}
	else{
		document.cartDiv.visibility = document.cartDiv.visibility  == "hidden"?"visible":"hidden";
	}
}


function ShowRecent(){
	window.clearTimeout(RecentTimeOut);
	if(_browser == "ie"){
		recentDiv.style.visibility = 
			recentDiv.style.visibility == "hidden"?"visible":"hidden";
		document.images["recentImage"].src =
			recentDiv.style.visibility == "hidden"?
			(skin_images + "ic_expand.gif"):
			(skin_images + "ic_collapse.gif");
	}
	else if(_browser == "gecko"){
		document.getElementById('recentDiv').style.visibility = 
			document.getElementById('recentDiv').style.visibility == "hidden"?"visible":"hidden";
		document.images["recentImage"].src =
			document.getElementById('recentDiv').style.visibility == "hidden"?
			(skin_images + "ic_expand.gif"):
			(skin_images + "ic_collapse.gif");
	}
	else{
		document.recentDiv.visibility = document.recentDiv.visibility  == "hidden"?"visible":"hidden";
	}
}

function PopUpCart(){
	CartTimeOut = window.setTimeout('ShowCart();', 1000);
}

function PopUpRecent(){
	RecentTimeOut = window.setTimeout('ShowRecent();', 1000);
}

function OnMenu(img){
	document.images[img].src = skin_images + "menu_arrow_on.gif";
}
function OffMenu(img){
	document.images[img].src = skin_images + "menu_arrow.gif";
}

function ShowPopup(src){
	var bWin = null;
	bWin = window.open(
		src, 
		"PopupWind", 
		"titlebar=no, toolbar=no, menubar=no, status=no, directories=no, resizable=no, scrollbars=no, top=20, left=20, width=320, height=240"
	);
	while(bWin==null);
	bWin.focus();
}

function PopUpImage(image_source, image_width, image_height){
	var bWin = null;
	bWin = window.open(
		image_source, 
		"ImageWind", 
		"titlebar=no, toolbar=no, menubar=no, status=no, directories=no, resizable=no, scrollbars=no, top=20, left=20, width=" + (image_width + 20) + ", height=" + (image_height + 20)
	);
	while(bWin==null);
	bWin.focus();
}

function ConfirmLogout(){
	if(orderItemsCount > 0){
		if(confirm("You have items in your cart. Logging out will empty your cart\nAre you sure want to continue?")){
			document.location = urlLogout;
		}
	}
	else{
		if(confirm("Do you really want to logout?")){
			document.location = urlLogout;
		}
	}
}

function CartConfirmDeleteItem(ocid){
	if(confirm(msg_confirm_delete_item)){
		document.location = CartDeleteItemUrl + '&ocid=' + ocid;
	}
}
function CartConfirmEmpty(){
	if(confirm(msg_confirm_empty_cart)){
		document.location = CartEmptyUrl;
	}
}



<!-- swapimage//-->


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

<!-- swapimage//-->

function ClearInput(value, id){
var input = document.getElementById(id); 

if(value == input.value){ 
input.value = ''; 
}else{ 
input.value = input.value; 
} 
}

	function newsletterSignup() {
		var fNameVal = document.getElementById('mcFName').value;
		var lNameVal = document.getElementById('mcLName').value;
		var emailVal = document.getElementById('mcEmail').value;

		$('#mcResponse').fadeOut('fast', function() {
			$('#mcProcessor').slideDown('fast', function() {
				$('#mcLoader').fadeIn('fast', function() {
					var hostName = location.hostname;
					$.post('http://'+hostName+'/ajax-mailchimp.php', { fname:fNameVal, lname:lNameVal, email:emailVal }, function(data) {
						$('#mcLoader').fadeOut('fast', function() {
							$('#mcResponse').html(data);
							$('#mcResponse').fadeIn('fast');
						});
					});
				});
			});
		});
		
		return false;
	}
