function openAvail (search,c,s) {
    var x = window.open (search+'?Style='+s+'&ColorAvl='+c,'availability','width=525,height=450,dependent=1,resizable=1,scrollbars=1,screenX=125,screenY=165,left=125,top=165');
}

function mailPop(search,s) {
	var myLink = location.href;
	var t = window.open (search+'?Notify=friend&Style='+s,'mail_popup', 'width=490,height=340,dependent=1,resizable=1,screenX=125,screenY=165,left=125,top=165');
}


function productPop (search,s) {
	window.open (search+'?Notify=product&Style='+s,'prd_notification_popup','width=525,height=480,dependent=1,resizable=1,screenX=125,screenY=165,left=125,top=165');
}

function productSpecificPop (search,s,p) {
	window.open (search+'?Notify=product&Style='+s+'&CWS_pulldown='+p,'prd_notification_popup','width=525,height=480,dependent=1,resizable=1,screenX=125,screenY=165,left=125,top=165');
}


function brandPop (search,s) {
    var z = window.open (search+'?Notify=brand&Style='+s,'brd_notification_popup','width=480,height=450,dependent=1,resizable=1,screenX=125,screenY=165,left=125,top=165');
}


function addtowebsitePop (url) {
    var z = window.open (url,'addtowebsite_popup','width=480,height=275,dependent=1,resizable=1,screenX=125,screenY=165,left=125,top=165');
}

function sizeChartPop (s) {
    window.open (s,'availability','width=475,height=400,dependent=1,scrollbars=1,resizable=1,screenX=125,screenY=165,left=125,top=165');
}

function switchColorImage(cid) {
	colorId = cid;
    if (colorId == "") {                                                                                                   
         return;                                                                                                             
    } else {
		var multiCnt = multiCntMap[colorId];
		var label = '';
		if ((multiCnt & 1) > 0) label = 'View Larger Image & More Image Views';
		else if (multiCnt > 0) label = 'More Image Views';
		else if (zoomImageMaps[colorId] != null) label = 'View Larger Image';
		
		if (imageMaps[colorId] == null){
			document.viewImage.src = imgbase + imageMaps['DEFAULT'];   
		} else{                                                                                                             
			document.viewImage.src = imgbase + imageMaps[colorId];                          
		}

		var zoomlink = document.getElementById("zoomlink"); 
		if (zoomlink != null) {
			var thisobj = zoomlink.firstChild;                                                                                                             
			if (thisobj != null) zoomlink.firstChild.nodeValue = label;   
			else {
				var txt = document.createTextNode(label);
				zoomlink.appendChild(txt);
			}  
		}

		var imagecolorobj = document.viewColorImage.imageColors;
		var selectedindex = imagecolorobj.selectedIndex;
		var ctext = imagecolorobj.options[selectedindex].text;

		var viewedColor = document.getElementById("viewedColor"); 
		if (viewedColor != null) {
			var obj = viewedColor.firstChild;
			if (obj != null) viewedColor.firstChild.nodeValue = ctext;
			else {
				var ntxt = document.createTextNode(ctext);
				viewedColor.appendChild(ntxt);
			}  
		}

		var viewedColor2 = document.getElementById("viewedColor2"); 
		if (viewedColor2 != null) {
			var obj2 = viewedColor2.firstChild;                                                                                                             
			if (obj2 != null) viewedColor2.firstChild.nodeValue = ctext;   
			else {
				var ntxt2 = document.createTextNode(ctext);
				viewedColor.appendChild(ntxt2);
			}  
		}
    }
}

//multiple image project
function openJB() {
	var multiCnt = multiCntMap[colorId];
	//var selected = 1;
	//if (zoomImageMaps[colorId] == null) selected = 1;
	var mywin = open('','availability','width=475,height=582,resizable=yes'); 
	mywin.document.writeln('<HTML>');
	mywin.document.writeln('<HEAD>');
	mywin.document.writeln('<TITLE>' + name + '</TITLE>');
	//mywin.document.writeln('<script language="javascript"  src="/jscript/detail.js" type="text/javascript" ></script>'); 
	mywin.document.writeln('<script>');
	mywin.document.writeln('function showLayer(o, p) {');
	mywin.document.writeln('	var layer = document.getElementById(o);');
	mywin.document.writeln('	var one = null;');
	mywin.document.writeln('	if (layer != null) one = layer.style;');
	mywin.document.writeln('	if (one != null) {');
	mywin.document.writeln('		one.visibility = "visible";');
	mywin.document.writeln('		one.display = "block";');
	mywin.document.writeln('		one.left = p + "px";');	
	mywin.document.writeln('	}');
	mywin.document.writeln('}');
	mywin.document.writeln('function hideLayer(o, p) {');
	mywin.document.writeln('	var layer = document.getElementById(o);');
	mywin.document.writeln('	var one = null;');
	mywin.document.writeln('	if (layer != null) one = layer.style;');
	mywin.document.writeln('	if (one != null) {');
	mywin.document.writeln('		one.visibility = "hidden";');
	mywin.document.writeln('		one.display = "none";');
	mywin.document.writeln('		one.left = p + "px";');
	mywin.document.writeln('	}');
	mywin.document.writeln('}');
	mywin.document.writeln('function switchColorImage(cid) {');
	mywin.document.writeln('	colorId = cid; ');
	mywin.document.writeln('	var multiCnt = multiCntMap[colorId];');
	mywin.document.writeln('	if (multiCnt != null && multiCnt > 0) {');
	mywin.document.writeln('		var newselected = 0;');
	mywin.document.writeln('		showLayer("multi", "0");');
	mywin.document.writeln('		var p = 15;');
	mywin.document.writeln('		var inc = 35;');
	mywin.document.writeln('		for (var i = 1; i <= maxImg; i++) {');
	mywin.document.writeln('			if ((multiCnt & Math.pow(2, i - 1)) > 0) {');
	mywin.document.writeln('				if (newselected == 0) newselected = i;');
	//mywin.document.writeln('				eval("document.thumb" + i + ".src=\'" + fileroot + colorId + "_dt" + i + ".jpg\';");');
	mywin.document.writeln('				eval("document.thumb" + i + ".src=\'" + mcfileroot + colorId + "_dt" + i + ".jpg\';");');
	mywin.document.writeln('				eval("document.thumb" + i + ".width=\'30\';");');
	mywin.document.writeln('				eval("document.thumb" + i + ".height=\'30\';");');
	mywin.document.writeln('				showLayer("thumb" + i, "" + p);');
	mywin.document.writeln('				p += inc;');
	mywin.document.writeln('			}');
	mywin.document.writeln('			else {');
	mywin.document.writeln('				eval("document.thumb" + i + ".src=\'\';");');
	mywin.document.writeln('				eval("document.thumb" + i + ".width=\'0\';");');
	mywin.document.writeln('				eval("document.thumb" + i + ".height=\'0\';");');
	mywin.document.writeln('				eval("document.thumb" + i + ".border=\'0\';");');
	mywin.document.writeln('				hideLayer("thumb" + i, "300");');
	mywin.document.writeln('			}');
	mywin.document.writeln('		}');
	mywin.document.writeln('		switchThumb(newselected);');
	mywin.document.writeln('		loadImage(colorId);');
	mywin.document.writeln('	}');
	mywin.document.writeln('	else {');
	mywin.document.writeln('		hideLayer("multi", "0");');	
	mywin.document.writeln('		for (var i = 1; i <= maxImg; i++) {');
	mywin.document.writeln('			eval("document.thumb" + i + ".src=\'\';");');
	mywin.document.writeln('			eval("document.thumb" + i + ".width=\'0\';");');
	mywin.document.writeln('			eval("document.thumb" + i + ".height=\'0\';");');
	mywin.document.writeln('			eval("document.thumb" + i + ".border=\'0\';");');
	mywin.document.writeln('		}'); 
	mywin.document.writeln('		if (imageMaps[colorId] == null)');
	mywin.document.writeln('			document.viewImage.src = imgbase + imageMaps["DEFAULT"];');
	mywin.document.writeln('		else');	
	mywin.document.writeln('			document.viewImage.src = imgbase + imageMaps[colorId];');                       
	mywin.document.writeln('	}');
	mywin.document.writeln('} ');

	mywin.document.writeln('function switchThumb(o) {');
	mywin.document.writeln('	 eval("document.thumb" + selected + ".border=0;");');
	mywin.document.writeln('	 selected = o;');
	mywin.document.writeln('	 eval("document.thumb" + selected + ".border=1;");');
	//mywin.document.writeln('	 document.viewImage.src = fileroot + colorId + "_jb" + selected + ".jpg";');
	mywin.document.writeln('	 document.viewImage.src = mcfileroot + colorId + "_jb" + selected + ".jpg";');
	mywin.document.writeln('}');

	mywin.document.writeln('function loadImage(cid) {');
	mywin.document.writeln('	if (myimages[cid] != null) return;');
	mywin.document.writeln('	var cnt = multiCntMap[cid];');
	mywin.document.writeln('	if (cnt > 0) {');
	mywin.document.writeln('		myimages[cid] = new Array();');
	mywin.document.writeln('		for (var j = 1; j <= maxImg; j++) {');
	mywin.document.writeln('			if ((cnt & Math.pow(2, j - 1)) > 0) {');
	mywin.document.writeln('				myimages[cid][j] = new Image();');
	mywin.document.writeln('				myimages[cid][j].src =  mcfileroot + cid + "_jb" + j + ".jpg";');
	//mywin.document.writeln('				myimages[cid][j].src =  fileroot + cid + "_jb" + j + ".jpg";');
	mywin.document.writeln('			}');
	mywin.document.writeln('		}');
	mywin.document.writeln('	}');
	mywin.document.writeln('	else {');
	mywin.document.writeln('		myimages[cid] = new Image();');
	mywin.document.writeln('		myimages[cid].src = imgbase + imageMaps[cid];');
	mywin.document.writeln('	}');
	mywin.document.writeln('}');

	//mywin.document.writeln('<script>');
	mywin.document.writeln('var multiCntMap = new Array();');
	for (var i in multiCntMap) {
		mywin.document.writeln('multiCntMap["' + i + '"] = ' + multiCntMap[i] + ';');
	}
	mywin.document.writeln('var imageMaps = new Array();');
	var cnt = 0;
	for (var i in imageMaps) {
		if (i == 'DEFAULT') continue;
		if (multiCntMap[i] > 0 || zoomImageMaps[i] != null) {
			mywin.document.writeln('imageMaps["' + i + '"] = "' + zoomImageMaps[i] + '";');
			cnt++;
		}
	}
	if (zoomImageMaps['DEFAULT'] != null) {
		mywin.document.writeln('imageMaps["DEFAULT"] = "' + zoomImageMaps['DEFAULT'] + '";');
	}
	mywin.document.writeln('var imgbase = "' + imgbase + '";');
	mywin.document.writeln('var colorId = "' + colorId + '";');
	mywin.document.writeln('var selected = 1;');
	mywin.document.writeln('var maxImg = ' + maxImg + ';');
	mywin.document.writeln('var fileroot = "' + fileroot + '";');
	mywin.document.writeln('var mcfileroot = "/pm' + fileroot.substring(3) + '";');
	//mywin.document.writeln('var imgType = "_jb";');
	//mywin.document.writeln('var showThumb = true;');
	mywin.document.writeln('var myimages = new Array();');
	mywin.document.writeln('<\/script>');
	mywin.document.writeln('</HEAD>');
	mywin.document.writeln('<BODY>');
	mywin.document.writeln('<center>');
	
	mywin.document.writeln('<table width="100%"><tr><td align="left" valign="top"><a style="text-decoration: none; font-size: 15px; font-family: verdana; color: #2D1459; font-weight: bold">' + name + '</a></td>');
	mywin.document.writeln('<td align="right" valign="top" nowrap><A HREF="javascript:close()" style="text-decoration: underline; font-size: 13px; font-family: verdana; color: blue; font-weight: bold">Close Window</A></td></tr><tr><td colspan=2 align=left>');
	if (cnt > 1 && document.viewColorImage.imageColors != undefined) {
		var imagecolorobj = document.viewColorImage.imageColors;
		var selectedindex = imagecolorobj.selectedIndex;
		var len = imagecolorobj.length;
		mywin.document.writeln('View another color:<br>');
		mywin.document.writeln('<select name="imageColors" onchange="switchColorImage(this.options[this.selectedIndex].value);">');
		for (var i = 0; i < len; i++) { 
			var thiscid = imagecolorobj.options[i].value;
			if (multiCntMap[thiscid] > 0 || zoomImageMaps[thiscid] != null) {
				var thistext = imagecolorobj.options[i].text;
				if (i == selectedindex) {
					mywin.document.writeln('<option value="' + thiscid + '" selected>' + thistext); 
				}
				else {
					mywin.document.writeln('<option value="' + thiscid + '">' + thistext); 
				}
			}
		}
		mywin.document.writeln('</select>');
	}
	else {
		var viewedColor = '';
		//if (colorMaps.length == 1) {
		if ((window['colorMaps'] != undefined) && colorMaps.length == 1) {
			if (imageMaps[colorId] != undefined) {
			   viewedColor = colorMaps['0'];
			}
		}
		else {
			var viewedColorelem = document.getElementById("viewedColor"); 
			if (viewedColorelem != null) {
				viewedColor = viewedColorelem.firstChild.nodeValue;
			}
			else {
				var obj = document.viewColorImage.imageColors;
				if (obj != null) {
					viewedColor = obj.options[obj.selectedIndex].text;
				}
			}
		}
		if (viewedColor != '') {
			mywin.document.writeln('<span style="font-family:verdana;font-size:12px;">You are viewing color:<br>');
			mywin.document.writeln(viewedColor + '</span>');
		}
	}

	mywin.document.writeln('</td></tr></table><p>');

	mywin.document.writeln('<table border="0" width="100%">');
	mywin.document.writeln('<tr><td colspan="3" align="center" valign="middle" width="450" height="400"><img name="viewImage" border="0" src=""></td></tr>');
	mywin.document.writeln('</table>');
	mywin.document.writeln('</center>');
	
	mywin.document.writeln('<table><tr valign="middle" align="left"><td><a style="text-decoration: none; font-size: 13px; font-family: verdana; color: #2D1459;"><span id="multi">View multiple angles:</span></a></td></tr><tr><td align="left">');

	for (var i = 1; i <= maxImg; i++) {
		mywin.document.writeln('<img style="position:absolute;" id="thumb' + i + '" name="thumb' + i + '" border="0" width="0" height="0" src="" onMouseOver="switchThumb(' + i + ')">');
	}
	mywin.document.writeln('</td></tr></table>');

	mywin.document.writeln('<SCRIPT LANGUAGE="JavaScript">');
	mywin.document.writeln('	switchColorImage(colorId);');
	mywin.document.writeln('	var n = multiCntMap[colorId];');
	mywin.document.writeln('	if (n > 0) loadImage(colorId);'); 
	mywin.document.writeln('	for (var i in multiCntMap) {');
	mywin.document.writeln('		if (multiCntMap[i] == 0) loadImage(i);');
	mywin.document.writeln('	}');
	mywin.document.writeln('<\/SCRIPT>');
	mywin.document.writeln('</BODY>');
	mywin.document.writeln('</HTML>');
	mywin.document.close();
	mywin.focus();
}

//moved from detail.jsp -01/05/09 by nl

var newwindow;
function poptastic(url)
{
   newwindow=window.open(url,'name','height=380,width=520,left=90,top=90,scrollbars=1');
   //newwindow=window.open("getCustomerImages.jsp",'name','height=220,width=260,left=90,top=90,scrollbars=1');
   if(window.focus){newwindow.focus()}
}

function popup(url, height) {

  if (!height) {
    height = 560;
  }
  var params = 'width=525,height=' + height + ',dependent=1,resizable=1,scrollbars=1';
  newwindow=window.open(url,'name',params);
  return false;
}

//--Shahzad--
function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
  var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
  var int_windowTop = (screen.height - a_int_windowHeight) / 2;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
//alert(a_str_windowURL);
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
    }
}

//used to sort color in buybox dropdown
function sortbytext(a,b){return a.text < b.text ? -1 : a.text > b.text ? 1 : 0;}
