/**
 * SUBMODAL v1.6
 * Used for displaying DHTML only popups instead of using buggy modal windows.
 *
 * By Subimage LLC
 * http://www.subimage.com
 *
 * Contributions by:
 * 	Eric Angel - tab index code
 * 	Scott - hiding/showing selects for IE users
 *	Todd Huss - inserting modal dynamically and anchor classes
 *
 * Up to date code can be found at http://submodal.googlecode.com
 */

var speed = 1; // Delay between increments.
var inc = 3; // Increment amount -- also changes speed
var bool = new Boolean(false); 
var tt = "";


// Popup code
var gPopupMask = null;
var gPopupContainer = null;
var gPopFrame = null;
var gReturnFunc;
var gPopupIsShown = false;
var gDefaultPage = "images/modalDialog/loading.html";
var gHideSelects = false;
var gReturnVal = null;

var gTabIndexes = new Array();
// Pre-defined list of tags we want to disable/enable tabbing into
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	

// If using Mozilla or Firefox, use Tab-key trap.
if (!document.all) {
	document.onkeypress = keyDownHandler;
}

/**
 * Initializes popup code on load.	
 */
function initPopUp() {

	// Add the HTML to the body
	theBody = document.getElementsByTagName('BODY')[0];
	popmask = document.createElement('div');
	popmask.id = 'popupMask';
	popcont = document.createElement('div');
	popcont.id = 'popupContainer';
	popcont.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle" style="font-weight: bold; font-size: 13px;text-align: left;color:black;padding-left: 3px;padding-top: 6px;"></div>' +
				'<div id="popupControls" >' +
					'<input type="button" align="top" value="" style="color:#FFF;cursor: pointer;background: url(../images/transparent.gif);border: 0px;" onclick="hidePopWin(false);" id="popCloseLink"  /> '+
					'<input type="button" align="top"  value="X"  onclick="hidePopWin(false);" id="popCloseLink2"  /> '+
					//'<img src="../images/modalDialog/close.gif" onclick="hidePopWin(false);" id="popCloseBox" />' +
				'</div>' +
			'</div>' +
			'<iframe src="'+ gDefaultPage +'" style="width:100%;height:100%;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="100%" height="100%"></iframe>' +
		'</div>';
	theBody.appendChild(popmask);
	theBody.appendChild(popcont);
	
	gPopupMask = document.getElementById("popupMask");
	gPopupContainer = document.getElementById("popupContainer");
	gPopFrame = document.getElementById("popupFrame");	
	
	// check to see if this is IE version 6 or lower. hide select boxes if so
	// maybe they'll fix this in version 7?
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
		gHideSelects = true;
	}
	
	// Add onclick handlers to 'a' elements of class submodal or submodal-width-height
	var elms = document.getElementsByTagName('a');
	for (i = 0; i < elms.length; i++) {
		if (elms[i].className.indexOf("submodal") == 0) { 
			// var onclick = 'function (){showPopWin(\''+elms[i].href+'\','+width+', '+height+', null);return false;};';
			// elms[i].onclick = eval(onclick);
			elms[i].onclick = function(){
				// default width and height
				var width = 400;
				var height = 200;
				// Parse out optional width and height from className
				params = this.className.split('-');
				if (params.length == 3) {
					width = parseInt(params[1]);
					height = parseInt(params[2]);
				}
				showPopWin(this.href,width,height,null); return false;
			}
		}
	}
}
addEvent(window, "load", initPopUp);




 /**
	* @argument width - int in pixels
	* @argument height - int in pixels
	* @argument url - url to display
	* @argument returnFunc - function to call when returning true from the window.
	* @argument showCloseBox - show the close box - default true
	*/
function showPopWin(url, width, height, returnFunc, showCloseBox,title) {
document.getElementById('popupTitle').innerHTML=title;

	if(width>screen.width){
	width=screen.width-150;
	}
	if(width>screen.height){
	height=screen.height-150;
	}



	// show or hide the window close widget
	
	document.getElementById("popCloseLink").value = showCloseBox
	/*if (showCloseBox == null || showCloseBox == true) {
		document.getElementById("popCloseBox").style.display = "block";
	} else {
		document.getElementById("popCloseBox").style.display = "none";
	}*/
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	loadIFrameHeight();
	// set the url
	gPopFrame.src = url;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	//window.setTimeout("setPopTitle();", 600);
}

//
var gi = 0;
function centerPopWin(width, height) {
	if (gPopupIsShown == true) {
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		//var theBody = document.documentElement;
		var theBody = document.getElementsByTagName("BODY")[0];
		//theBody.style.overflow = "hidden";
		var scTop = parseInt(getScrollTop(),10);
		var scLeft = parseInt(theBody.scrollLeft,10);
	
		setMaskSize();
		
		//window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++;
		
		//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
		var titleBarHeight = 0;
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		
		gPopupContainer.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		gPopupContainer.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
		//alert(fullWidth + " " + width + " " + gPopupContainer.style.left);
	}
}


function showPopWin6(url,returnFunc, showCloseBox,image,close,print,title ) {
	document.getElementById('popupTitle').innerHTML=title;
	//if (url.trim()==''){
	//	return;
	//}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	
	width=750;
    height=420;	
		if(width>=screen.width){
	width=screen.width-150;
	}
	if(height>=screen.height){
	height=screen.height-420;
	}
	
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	loadIFrameHeight();
	// set the url
	gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	return;
	//window.setTimeout("setPopTitle();", 600);
	
}





function showPopWin5(url,returnFunc, showCloseBox,image,close,print,title ) {
	document.getElementById('popupTitle').innerHTML=title;
	//if (url.trim()==''){
	//	return;
	//}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	
	width=450;
    height=520;	
		if(width>=screen.width){
	width=screen.width-150;
	}
	if(height>=screen.height){
	height=screen.height-420;
	}
	
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	loadIFrameHeight();
	// set the url
	gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	return;
	//window.setTimeout("setPopTitle();", 600);
	
}


function showPopWin3(url,returnFunc, showCloseBox,image,close,print,title ) {
gPopFrame.src='about:blank';
	document.getElementById('popupTitle').innerHTML=title;
	//if (url.trim()==''){
	//	return;
	//}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	
	width=800;
    height=520;	
		if(width>=screen.width){
	width=screen.width-150;
	}
	if(height>=screen.height){
	height=screen.height-420;
	}
	
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	loadIFrameHeight();
	// set the url
	gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	return;
	//window.setTimeout("setPopTitle();", 600);
	
}


function showPopWin4(url,returnFunc, showCloseBox,image,close,print,title,proId,widthImg,heightImg) {
//alert(widthImg);
//alert(heightImg);
var width=parseInt(widthImg)+350;
var height=parseInt(heightImg+200)
	document.getElementById('popupTitle').innerHTML=title;
	if (url==''){
		return;
	}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	
	//width=1150;
   // height=600;	
 //  width=500;
  //  height=500;	
   
		if(width>=screen.width){
	width=screen.width-150;
	}
	if(height>=screen.height){
	height=screen.height-420;
	}
	
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	// set the url
	
/* browser det */


    var detect = navigator.userAgent.toLowerCase();
    var OS,browser,version,total,thestring;

    if (checkIt('konqueror'))
    {
          browser = "Konqueror";
          OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari"
    else if (checkIt('omniweb')) browser = "OmniWeb"
    else if (checkIt('opera')) browser = "Opera"
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab"
    else if (checkIt('msie')) browser = "Internet Explorer"
    else if (!checkIt('compatible'))
    {
          browser = "Netscape Navigator"
          version = detect.charAt(8);
    }
    else browser = "An unknown browser";
   
    if (!version) version = detect.charAt(place + thestring.length);
    if (browser != "Internet Explorer")
    {
     //   alert("it is not iE");
    }
    else
    {
        if(version = 7)
        {
      //      alert("IE version is 7");
        }
         else  if(version = 6)
        {
      //      alert("IE version is 6");
        }
         else  if(version = 8)
        {
       //     alert("IE version is 8");
        }
    }  
    if (!OS)
    {
          if (checkIt('linux')) OS = "Linux";
          else if (checkIt('x11')) OS = "Unix";
          else if (checkIt('mac')) OS = "Mac"
          else if (checkIt('win')) OS = "Windows"
          else OS = "an unknown operating system";
    }

    function checkIt(string)
    {
          place = detect.indexOf(string) + 1;
          thestring = string;
          return place;
    }


 /* borwser det end */
 
 
 loadIFrameHeight();
	 gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print+"&proId="+proId;
	
	
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	return;
	//window.setTimeout("setPopTitle();", 600);
	
	
	
	
}


function showPopWin2(url,returnFunc, showCloseBox,image,close,print ) {
	
	if (url.trim()==''){
		return;
	}	
	
	try {
	
		document.getElementById("popCloseLink").value = '';//close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	width=800;
    height=600;	
		if(width>=screen.width){
	width=screen.width-150;
	}
	if(width>=screen.height){
	height=screen.height-150;
	}
	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	loadIFrameHeight();
	// set the url
	gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	return;
	//window.setTimeout("setPopTitle();", 600);
	
}


function showPopCart(url,close,itemId,itemName){
	if (url.trim()==''){
		return;
	}	
	
	try {
		document.getElementById("popCloseLink").value = close;
	} catch (ex){}
	
	width=400;
	height=400;
	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	loadIFrameHeight();
	// set the url
	gPopFrame.src = url+"?itemId="+itemId+"&itemName="+itemName;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	//alert('bbb');
	setPopTitle();
	return;
	//window.setTimeout("setPopTitle();", 600);
}



addEvent(window, "resize", centerPopWin);
addEvent(window, "scroll", centerPopWin);
window.onscroll = centerPopWin;


/**
 * Sets the size of the popup mask.
 *
 */
function setMaskSize() {
	var theBody = document.getElementsByTagName("BODY")[0];
			
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	
	// Determine what's bigger, scrollHeight or fullHeight / width
	if (fullHeight > theBody.scrollHeight) {
		popHeight = fullHeight;
	} else {
		popHeight = theBody.scrollHeight;
	}
	
	if (fullWidth > theBody.scrollWidth) {
		popWidth = fullWidth;
	} else {
		popWidth = theBody.scrollWidth;
	}
	
	gPopupMask.style.height = popHeight + "px";
	gPopupMask.style.width = popWidth + "px";
	// added this line to increase overlay in new template
	gPopupMask.style.height = "2000" + "px";
}

/**
 * @argument callReturnFunc - bool - determines if we call the return function specified
 * @argument returnVal - anything - return value 
 */
function hidePopWin(callReturnFunc) {
clearTimeout(tt);
	gPopupIsShown = false;
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "";
	restoreTabIndexes();
	if (gPopupMask == null) {
		return;
	}

	gPopupMask.style.display = "none";
	gPopupContainer.style.display = "none";
	
	if (callReturnFunc == true && gReturnFunc != null) {
		// Set the return code to run in a timeout.
		// Was having issues using with an Ajax.Request();
		gReturnVal = window.frames["popupFrame"].returnVal;
		window.setTimeout('gReturnFunc(gReturnVal);', 1);
	}
	gPopFrame.src = gDefaultPage;
	// display all select boxes
	if (gHideSelects == true) {
		displaySelectBoxes();
	}
}

/**
 * Sets the popup title based on the title of the html document it contains.
 * Uses a timeout to keep checking until the title is valid.
 */
function setPopTitle() {
	return;
	if (window.frames["popupFrame"].document.title == null) {
		window.setTimeout("setPopTitle();", 10);
	} else {
		document.getElementById("popupTitle").innerHTML = window.frames["popupFrame"].document.title;
	}
}

// Tab key trap. iff popup is shown and key was [TAB], suppress it.
// @argument e - event - keyboard event that caused this function to be called.
function keyDownHandler(e) {
    if (gPopupIsShown && e.keyCode == 9)  return false;
}

// For IE.  Go through predefined tags and disable tabbing into them.
function disableTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				gTabIndexes[i] = tagElements[k].tabIndex;
				tagElements[k].tabIndex="-1";
				i++;
			}
		}
	}
}

// For IE. Restore tab-indexes.
function restoreTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				tagElements[k].tabIndex = gTabIndexes[i];
				tagElements[k].tabEnabled = true;
				i++;
			}
		}
	}
}


/**
 * Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
 * IE has a problem with wanted select form tags to always be the topmost z-index or layer
 *
 * Thanks for the code Scott!
 */
function hideSelectBoxes() {
  var x = document.getElementsByTagName("SELECT");

  for (i=0;x && i < x.length; i++) {
    x[i].style.visibility = "hidden";
  }
}

/**
 * Makes all drop down form select boxes on the screen visible so they do not 
 * reappear after the dialog is closed.
 * 
 * IE has a problem with wanting select form tags to always be the 
 * topmost z-index or layer.
 */
function displaySelectBoxes() {
  var x = document.getElementsByTagName("SELECT");

  for (i=0;x && i < x.length; i++){
    x[i].style.visibility = "visible";
  }
  }




function showPopArticleSpecialist(url,returnFunc, showCloseBox,header,size,colour,quantity,close,image ) {

	document.getElementById('popupTitle').innerHTML="";	
var combo1 = document.getElementById(size);
var val1 = combo1.options[combo1.selectedIndex].value
var val1TextSize = combo1.options[combo1.selectedIndex].text


var combo2 = document.getElementById(colour);
var val2 = combo2.options[combo2.selectedIndex].value;
var val2TextColour = combo2.options[combo2.selectedIndex].text;


var combo3 = document.getElementById(quantity);
var val3 = combo3.options[combo3.selectedIndex].value;
var val3TextQuantity = combo3.options[combo3.selectedIndex].text;
//	alert((val1=="0")&&(val2=="0"));
	
	if((val1=="0")||(val2=="0")){
//dont alow open popup
}else{
	
	
	
	
//show popup
if (url.trim()==''){
		return;
	}	
	var col=val2TextColour;
	var siz=val1TextSize;
	var qun=val3TextQuantity;
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
			document.getElementById("popCloseLink2").style.display = "none";
		//	document.getElementById("popCloseLink2").style.display = "none";
		//	document.getElementById("popupTitleBar").style.display= "popupInner";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	width=630;
	height=330;
	
	if(width>screen.width){
	width=screen.width-100;
	}
	if(width>screen.height){
	height=screen.height-100;
	}
	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	// set the url			
	loadIFrameHeight();																		
	gPopFrame.src = url+"?size="+siz+"&header="+header+"&colour="+col+"&quantity="+qun+"&image="+image;
	//alert(gPopFrame.src);
	//gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
//	document.getElementById("popupTitleBar").height=6;

	window.setTimeout("setPopTitle();", 600);
//	popcont.innerHTML = '' +
//		'<div id="popupInner">' +
//			'<iframe src="'+ gDefaultPage +'" style="width:100%;height:100%;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="100%" height="100%"></iframe>' +
//		'</div>';
	document.getElementById("popupTitleBar").style.display= "none";
}

	
}




		function loadIFrameHeight() {		
	 try{
	// var fullWidth = window.frames['popupFrame'].scrollWidth;
	//  alert(fullWidth);
	//document.frames("popupFrame").document.forms("Members").elements("testDive").style.height = fullWidth+"px";
	var dvWidtd=document.getElementById('popupContainer').scrollHeight;
	//alert(dvWidtd);
	//window.frames['popupFrame'].getElementById['testDive'].style.height = dvWidtd+"px";
	//alert(document.frames("popupFrame").document.forms("Members").elements("testDive"));
	//window.frames['popupFrame'].document.getElementId('testDive').style.height = dvWidtd+"px";
	//document.getElementById('Members:testDive').style.height = dvWidtd+"px";	
	//var mmsiobj=window.frames['popupFrame'].document.getElementsByTagName('DIV')[0];	
	//alert(dvWidtd);
	var calcHeight=dvWidtd-70;
	//alert(calcHeight);
	//window.frames['popupFrame'].document.getElementsByTagName('td')[0].style.height  = ""+calcHeight+"px";
	//window.frames['popupFrame'].document.getElementsByTagName('td')[0].style.verticalAlign  = 'middle';
	//alert(mmsiobj.scrollWidth);
	//mmsiobj.getElementsByTagName('DIV').style.height = dvWidtd+"px";
	// alert('done');
				   }catch(err){
				//alert('err');
				   }	
				   
				   
				   
				   
				   
				   
				   
				   
				  
    var detect = navigator.userAgent.toLowerCase();
    var OS,browser,version,total,thestring;

    if (checkIt('konqueror'))
    {
          browser = "Konqueror";
          OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari"
    else if (checkIt('omniweb')) browser = "OmniWeb"
    else if (checkIt('opera')) browser = "Opera"
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab"
    else if (checkIt('msie')) browser = "Internet Explorer"
    else if (!checkIt('compatible'))
    {
          browser = "Netscape Navigator"
          version = detect.charAt(8);
    }
    else browser = "An unknown browser";
   
    if (!version) version = detect.charAt(place + thestring.length);
    if (browser != "Internet Explorer")
    {
     //   alert("it is not iE");
     try{
     window.frames['popupFrame'].document.getElementsByTagName('td')[0].style.height  = ""+calcHeight+"px";
     }
catch(err)
  { 
  }
    }
    else
    {
   // alert(version);
      if(version == 8)
        {
           // alert("IE version is 8");
           try{
       window.frames['popupFrame'].document.getElementsByTagName('td')[0].style.height  = dvWidtd+"px";
       }
catch(err)
  { 
  }
        }
        else if(version == 7)
        {
           // alert("IE version is 7");
           try{
      window.frames['popupFrame'].document.getElementsByTagName('td')[0].style.height  = ""+calcHeight+"px";
      }
catch(err)
  { 
  }
        }
         else  if(version == 6)
        {
      //      alert("IE version is 6");
      try{
      window.frames['popupFrame'].document.getElementsByTagName('td')[0].style.height  = ""+calcHeight+"px";
      }
catch(err)
  { 
  }
        }
         
    }  
    if (!OS)
    {
          if (checkIt('linux')) OS = "Linux";
          else if (checkIt('x11')) OS = "Unix";
          else if (checkIt('mac')) OS = "Mac"
          else if (checkIt('win')) OS = "Windows"
          else OS = "an unknown operating system";
    }

    function checkIt(string)
    {
          place = detect.indexOf(string) + 1;
          thestring = string;
          return place;
    } 
				   
				   
				   
				   
				   
				   
				   
				   
				   
				   
	}



//print pop-up
function showPopWinZoomImg(url,returnFunc, showCloseBox,image,close,print,title,proId,widthImage,heightImage ) {
//alert('test not come');
//var width=parseInt(widthImage)+350;
//var height=parseInt(heightImage+440);
width=650;
height=650;

	document.getElementById('popupTitle').innerHTML=title;
	//if (url==''){
	//	return;
	//}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	
		//width=650;
   // height=585;	
  // alert('585'+height);
  if(width>150){
		if(width>=screen.width){
	width=screen.width-150;
	//alert('t');
	}
	}else{
	
	}
	if(height>420){
	if(height>=screen.height){
	height=screen.height-420;
	//alert('tt');
	}
	}else{
	
	}
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	
	
	
	
	
		
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();
	

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	// set the url
	 loadIFrameHeight();
	 
	gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print+"&proId="+proId;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	//window.setTimeout("setPopTitle();", 600);
	
}


function showPopWinSizeImg(url,returnFunc, showCloseBox,image,close,print,title,widthImage,heightImage) {
var widthImg=parseInt(widthImage);
var heightImg=parseInt(heightImage);
//alert(widthImg);
//alert(heightImg);
	document.getElementById('popupTitle').innerHTML=title;
	if (url==''){
		return;
	}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	

	width=920;
    height=600;	
    //width=500;
    //height=500;	
    

	if(width>=screen.width){
		width=screen.width-150;
	}
	if(height>=screen.height){
		height=screen.height-420;
	}
	
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	// set the url
	loadIFrameHeight();
	
	gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print+"&width="+widthImg+"&height="+heightImg;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	//window.setTimeout("setPopTitle();", 600);
	//width,height
	var bool = new Boolean(false); 
	
	 tt = window.setTimeout("scaleToFit('popupContainer',"+widthImg+","+heightImg+","+bool+");", 1000);
	
	//clearTimeout(t);
	
	
}





function showPopWin7(url,returnFunc, showCloseBox,image,close,print,title,proId ) {
clearTimeout(tt);
	document.getElementById('popupTitle').innerHTML=title;
	if (url==''){
		return;
	}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	
	width=600;
    height=380;	
		if(width>=screen.width){
	width=screen.width-150;
	}
	if(height>=screen.height){
	height=screen.height-420;
	}
	
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	// set the url
	
/* browser det */


    var detect = navigator.userAgent.toLowerCase();
    var OS,browser,version,total,thestring;

    if (checkIt('konqueror'))
    {
          browser = "Konqueror";
          OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari"
    else if (checkIt('omniweb')) browser = "OmniWeb"
    else if (checkIt('opera')) browser = "Opera"
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab"
    else if (checkIt('msie')) browser = "Internet Explorer"
    else if (!checkIt('compatible'))
    {
          browser = "Netscape Navigator"
          version = detect.charAt(8);
    }
    else browser = "An unknown browser";
   
    if (!version) version = detect.charAt(place + thestring.length);
    if (browser != "Internet Explorer")
    {
     //   alert("it is not iE");
    }
    else
    {
        if(version = 7)
        {
      //      alert("IE version is 7");
        }
         else  if(version = 6)
        {
      //      alert("IE version is 6");
        }
         else  if(version = 8)
        {
       //     alert("IE version is 8");
        }
    }  
    if (!OS)
    {
          if (checkIt('linux')) OS = "Linux";
          else if (checkIt('x11')) OS = "Unix";
          else if (checkIt('mac')) OS = "Mac"
          else if (checkIt('win')) OS = "Windows"
          else OS = "an unknown operating system";
    }

    function checkIt(string)
    {
          place = detect.indexOf(string) + 1;
          thestring = string;
          return place;
    }


 /* borwser det end */
 
 
 loadIFrameHeight();
	 gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print+"&proId="+proId;
	
	
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	setPopTitle();
	//window.setTimeout("setPopTitle();",1);
	return;
	
}







function showPopWinZoomImg2(url,returnFunc, showCloseBox,image,close,print,title,proId,widthImage,heightImage,imagePdf) {
//alert(imagePdf);
//var width=parseInt(widthImage)+50;
//var height=parseInt(heightImage)
width=470;
height=575;	
	document.getElementById('popupTitle').innerHTML=title;
	if (url==''){
		return;
	}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	
		//width=470;
    //height=575;	
   //alert('575'+height);
		if(width>=screen.width){
	width=screen.width-150;
	}
	if(height>=screen.height){
	height=screen.height-420;
	}
	
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	// added this line to increase overlay in new template
	gPopupMask.style.height = "2000" + "px";
	
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	
	
	
	
	
		
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();
	

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	// set the url
	 loadIFrameHeight();
	 
	gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print+"&proId="+proId+"&imagePdf="+imagePdf;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	//window.setTimeout("setPopTitle();", 1);
return;
	
}


function showPopWinSizeImg3(url,returnFunc, showCloseBox,image,close,print,title) {
var widthImg=parseInt(950);
var heightImg=parseInt(470);
//alert(widthImg);
//alert(heightImg);
	document.getElementById('popupTitle').innerHTML=title;
	if (url==''){
		return;
	}	
	
	try {
	
		document.getElementById("popCloseLink").value = close;
		//if (showCloseBox == null || showCloseBox == true) {
			//document.getElementById("popCloseBox").style.display = "block";
		//} else {
		//	document.getElementById("popCloseBox").style.display = "none";
		//}
		
		//popCloseLink
		
		
	} catch (ex){
		//alert(ex); 
	}
	

	width=1100;
    height=600;	
    //width=500;
    //height=500;	
    

	if(width>=screen.width){
		width=screen.width-150;
	}
	if(height>=screen.height){
		height=screen.height-420;
	}
	
	

	
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	//var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	var titleBarHeight = 0;

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	// set the url
	loadIFrameHeight();
	
	gPopFrame.src = url+"?itempic="+image+"&itemPrint="+print+"&width="+widthImg+"&height="+heightImg;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	setPopTitle();
	//window.setTimeout("setPopTitle();", 600);
	//width,height
	var bool = new Boolean(false); 
	
	 tt = window.setTimeout("scaleToFit('popupContainer',"+widthImg+","+heightImg+","+bool+");", 1000);
	
	//clearTimeout(t);
	
	
}




function scaleToFit(id,width,height,enable) {

if(enable){
var obj= document.getElementById(id);
resize(width+50,height+50, 0, id);
//resize2(1159, 600, 0, id);
//alert(width);
//alert(height);
}
}

function resize(width,height,current,id) {

//alert('call');

var obj = document.getElementById(id);
if (obj.scrollWidth <= width && obj.scrollWidth<=(screen.width-150)) {
i = obj.scrollWidth + inc;
obj.style.width = i;
gPopupContainer.style.width = (i) + "px";

}



if (obj.scrollHeight <= height && obj.scrollHeight <=(screen.height-420)) {
i = obj.scrollHeight + inc;
obj.style.height = i;
gPopupContainer.style.height = (i) + "px";
gPopFrame.style.height = (i) + "px";
}

gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
centerPopWin(obj.scrollWidth, obj.scrollHeight);
//gPopupContainer.style.display = "block";
if (obj.scrollWidth <= width || obj.scrollHeight <= height) {
 tt = window.setTimeout("resize("+width+","+height+","+i+",'"+id+"');", speed);
} else { obj.style.height = height; obj.style.width = width;
//alert('call');
 }


if(width>=screen.width){
		width=screen.width-150;
	}
	if(height>=screen.height){
		height=screen.height-420;
	}


}












