var userAgent = navigator.userAgent.toLowerCase();
var isIE = ((userAgent.indexOf("msie") != -1) && (userAgent.indexOf("opera") == -1) && (userAgent.indexOf("webtv") == -1));

var tid = new Array();
var lastMenu = new Array();
var hiddenObjects = new Array();

function show(menuName, menuType) 
{
	var actMenu = new Array();
	var subName = "";
	var subMenus = menuName.split("_");
	var addWidth = false; var addHeight = true;
	for (var m = 0; m < subMenus.length; m++) {
		if (m == 0) {
			subName = subMenus[m];
		} else {
			subName += "_" + subMenus[m];
			addWidth = true; var addHeight = false;
		}
		var parentMenuName = "m_" + subName;
		var subMenuName = "sm_" + subName;
		if (menuType == "2" || menuType == "secondary") {
			parentMenuName = "secondary_" + subName;
			subMenuName = "secondary_ddm_" + subName;
		}
		var parentMenu = document.getElementById(parentMenuName);
		var subMenu = document.getElementById(subMenuName);

		if (subMenu) {
			actMenu[subMenuName] = 1;
			subMenu.style.top = findPosY(parentMenu, addHeight) + "px";
			subMenu.style.left = findPosX(parentMenu, addWidth) + "px";
			subMenu.style.display='block';
			hideSelectBoxes(subMenuName);
			if (tid[subName]) {
				clearTimeout(tid[subName]);
				tid[subName] = "";
			}
		}
	}

	for (menuName in lastMenu) {
		if (!actMenu[menuName]) {
			var menuObj = document.getElementById(menuName);
			menuObj.style.display = "none";
			showSelectBoxes(menuName);
		}
	}
	lastMenu = actMenu;

}

function hide(menuName, menuType)
{
	var subMenus = menuName.split("_");
	for (var m = 0; m < subMenus.length; m++) {
		if (m == 0) {
			subName = subMenus[m];
		} else {
			subName += "_" + subMenus[m];
		}
		var blockName = "sm_" + subName;
		var blockMenu = document.getElementById(blockName);
		if (blockMenu) {
			tid[subName] = setTimeout("hideMenu('" + subName + "', '" + menuType + "')", 1500);
		}
	}
}

function hideMenu(menuName, menuType)
{
	var subMenuName = "sm_" + menuName;
	if (menuType == "2" || menuType == "secondary") {
		subMenuName = "secondary_ddm_" + menuName;
	}
	var subMenu = document.getElementById(subMenuName);
	if (subMenu) {
		subMenu.style.display='none';
		showSelectBoxes(subMenuName);
	}

}

function findPosX(obj, addWidth)
{
	var curleft = 0;
	if (addWidth) {
		curleft += obj.offsetWidth;
	}
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj, addHeight)
{
	var curtop = 0;
	if (addHeight) {
		curtop += obj.offsetHeight;
	}
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function getPageSizeWithScroll()
{
	var xWithScroll = 0; var yWithScroll = 0; 
	if (window.innerHeight && window.scrollMaxY) { // Firefox         
		yWithScroll = window.innerHeight + window.scrollMaxY;         
		xWithScroll = window.innerWidth + window.scrollMaxX;     
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac         
		yWithScroll = document.body.scrollHeight;         
		xWithScroll = document.body.scrollWidth;     
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
		yWithScroll = document.body.offsetHeight;         
		xWithScroll = document.body.offsetWidth;       
	}     
	var arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);    
	return arrayPageSizeWithScroll; 
} 

function getScroll()
{
	var w = window.pageXOffset ||
		document.body.scrollLeft ||
		document.documentElement.scrollLeft;
	var h = window.pageYOffset ||
		document.body.scrollTop ||
		document.documentElement.scrollTop;
	var arrayScroll = new Array(w, h);    
	return arrayScroll;
}

function showSelectBoxes(objId) {
	// delete hidden objects for this menu
	delete hiddenObjects[objId];
	var obj = document.getElementById(objId);
	var menuObjects = obj.overlapObjects;
	if (menuObjects && menuObjects.length > 0) {
		for (var i = 0; i < menuObjects.length; i++) {
			var objControl = menuObjects[i];
			// check if object control not present in hidden objects for new popup menus
			var objExists = false;
			for (id in hiddenObjects) {
				var checkObjects = hiddenObjects[id];
				for (var ob = 0; ob < checkObjects.length; ob++) {
					if (objControl == checkObjects[ob]) {
						objExists = true;
						break;
					}
				}
			}
			if (!objExists) {
				objControl.style.visibility = "visible";
			}
		}
	}
	obj.overlapObjects = null;
}

function hideSelectBoxes(objId, objExclude) {

	var obj = document.getElementById(objId);

	var x = findPosX(obj, false);
	var y = findPosY(obj, false);
	var w = obj.offsetWidth;
	var h = obj.offsetHeight;

	// create a new Array for overlapping Objects we will hide
	var overlapObjects = new Array();

	var objectsNames = new Array("object", "iframe");
	if (isIE) {
		// hide select controls for IE 
		objectsNames[2] = "select";
	}

	for (n = 0; n < objectsNames.length; n++) {
		var objectName = objectsNames[n];
		var objects = document.getElementsByTagName(objectName);

		for (i = 0; i < objects.length; i++) {
			var objectControl = objects[i];
	
			var objName = objectControl.name;
			var isExclude = false;
			if (objExclude && objExclude.length) {
				for (var ex = 0; ex < objExclude.length; ex++) {
					if (objName == objExclude[ex]) {
						isExclude = true;
					}
				}
			}
			// check if object was hidden before
			var objExists = false;
			if (objectControl.style.visibility == "hidden") {
				for (id in hiddenObjects) {
					var checkObjects = hiddenObjects[id];
					for (var ob = 0; ob < checkObjects.length; ob++) {
						if (objectControl == checkObjects[ob]) {
							objExists = true;
							break;
						}
					}
				}
			}
			if (isExclude == true || (objectControl.style.visibility == "hidden" && !objExists)) {
				// don't hide object hidden by user
				continue;
			}
	
			var ox = findPosX(objectControl, false);
			var oy = findPosY(objectControl, false);
			var ow = objectControl.offsetWidth;
			var oh = objectControl.offsetHeight;
	
			if (ox > (x + w) || (ox + ow) < x) {
				continue;
			}
			if (oy > (y + h) || (oy + oh) < y) {
				continue;
			}

			overlapObjects[overlapObjects.length] = objectControl;
			objectControl.style.visibility = "hidden";
		}
	}

	// save overlapObjects array in global variables
	obj.overlapObjects = overlapObjects;
	hiddenObjects[objId] = overlapObjects;
}
function creatediv(){

var screenheight=document.getElementById("wholePage").scrollHeight;

var newdiv = document.createElement('div');

   newdiv.setAttribute('id', "mydiv");
       newdiv.style.width = "300px";
       newdiv.style.height = "35px";
       newdiv.style.position = "absolute";
       newdiv.style.left = "50%";
       newdiv.style.top = screenheight;
   newdiv.style.background ="black";
   
      newdiv.style.marginLeft= "-150px";

   newdiv.style.zindex="750";

   
   document.body.appendChild(newdiv);

}
function popupBlock(linkName, blockName, imageName)
{                              	
	var linkObj = document.getElementById(linkName);
	var blockObj = document.getElementById(blockName);
	var imageObj = document.getElementById(imageName);

	if (blockObj.style.display == "none" || blockObj.style.display == "") {
		//blockObj.style.left = findPosX(linkObj, 0) + "px";
		//blockObj.style.top = findPosY(linkObj, 1) + "px";
		blockObj.style.display = "block";
		hideSelectBoxes(blockName, "");
		if (imageObj) {
			imageObj.src = "images/icons/minus_small.gif";
		}
	} else {
		blockObj.style.display = "none";
		showSelectBoxes(blockName);
		if (imageObj) {
			imageObj.src = "images/icons/plus_small.gif";
		}
	}
}

function contactopen() {
newwin = window.open("contactform/form.php","Mens","top=75,left=25,height=470,width=480,scrollbars=yes,resizable=no,toolbar=no")
}
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_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_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];}
}
function readyopen() {
newwin = window.open("popup-mensready.htm","Mens","top=75,left=25,height=300,width=625,scrollbars=yes,resizable=no,toolbar=no")
}
function whereopen() {
newwin = window.open("popup-menswhere.htm","Mens","top=75,left=25,height=275,width=625,scrollbars=yes,resizable=no,toolbar=no")
}
function howtoopen() {
newwin = window.open("popup-menshowto.htm","Mens","top=75,left=25,height=500,width=625,scrollbars=yes,resizable=no,toolbar=no")
}
function contactopen() {
newwin = window.open("contactform/form.php","Mens","top=75,left=25,height=470,width=480,scrollbars=yes,resizable=no,toolbar=no")
}
function currencyopen() {
newwin = window.open("currency.htm","Mens","top=75,left=25,height=470,width=750,scrollbars=yes,resizable=no,toolbar=no")
}
function sasha() {
newwin = window.open("images/sasha.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function sashb() {
newwin = window.open("images/sashb.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function sashc() {
newwin = window.open("images/sashc.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function sashd() {
newwin = window.open("images/sashd.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function ruana1() {
newwin = window.open("images/ruana1.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function ruana2() {
newwin = window.open("images/ruana2.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function rose1() {
newwin = window.open("images/rosette1.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function rose2() {
newwin = window.open("images/rosette2.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function skirt1() {
newwin = window.open("images/skirt1.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function skirt1() {
newwin = window.open("images/skirt1.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function skirt2() {
newwin = window.open("images/skirt2.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function biasskirt() {
newwin = window.open("images/biascut.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function longskirt() {
newwin = window.open("images/longskirt.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function var1() {
newwin = window.open("images/var1.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function var2() {
newwin = window.open("images/var2.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function var3() {
newwin = window.open("images/var3.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function var4() {
newwin = window.open("images/var4.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function vest1() {
newwin = window.open("images/vest1.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function vest2() {
newwin = window.open("images/vest2.jpg","sash","top=75,left=25,height=525,width=350,scrollbars=yes,resizable=no,toolbar=no")
}
function celticopen() {
newwin = window.open("popup-celticcustoms.htm","Mens","top=75,left=25,height=400,width=625,scrollbars=yes,resizable=no,toolbar=no")
}
function scottishopen() {
newwin = window.open("popup-scott_traditions.htm","Mens","top=75,left=25,height=400,width=625,scrollbars=yes,resizable=no,toolbar=no")
}
function currencyopen() {
newwin = window.open("currency.htm","Mens","top=75,left=25,height=470,width=750,scrollbars=yes,resizable=no,toolbar=no")
}
function submitopenm() {
newwin = window.open("measure-mens/form.php","Mens","top=75,left=25,height=475,width=510,scrollbars=yes,resizable=no,toolbar=no")
}
function submitopen() {
newwin = window.open("measure-highland/form.php","Mens","top=75,left=25,height=470,width=490,scrollbars=yes,resizable=no,toolbar=no")
}
function functionopen() {
newwin = window.open("popup-function.htm","Mens","top=75,left=25,height=300,width=625,scrollbars=yes,resizable=no,toolbar=no")
}
function howlongopen() {
newwin = window.open("popup-howlong.htm","Mens","top=75,left=25,height=275,width=625,scrollbars=yes,resizable=no,toolbar=no")
}
function resaleopen() {
newwin = window.open("popup-resale.htm","Mens","top=75,left=25,height=500,width=625,scrollbars=yes,resizable=no,toolbar=no")
}
function contactopen() {
newwin = window.open("contactform/form.php","Mens","top=75,left=25,height=470,width=480,scrollbars=yes,resizable=no,toolbar=no")
}
function currencyopen() {
newwin = window.open("currency.htm","Mens","top=75,left=25,height=470,width=750,scrollbars=yes,resizable=no,toolbar=no")
}
 
var fnames = new Array();var ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';var err_style = '';
try{
    err_style = mc_custom_error_style;
} catch(e){
    err_style = 'margin: 1em 0 0 0; padding: 1em 0.5em 0.5em 0.5em; background: rgb(255, 238, 238) none repeat scroll 0% 0%; font-weight: bold; float: left; z-index: 1; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(255, 0, 0);';
}
var mce_jQuery = jQuery.noConflict();
mce_jQuery(document).ready( function($) {
  var options = { errorClass: 'mce_inline_error', errorElement: 'div', errorStyle: err_style, onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
  var mce_validator = mce_jQuery("#mc-embedded-subscribe-form").validate(options);
  options = { url: 'http://mackilts.us1.list-manage.com/subscribe/post-json?u=ebfbfb528643772b3bc3f1652&id=546e32e42d&c=?', type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",
                beforeSubmit: function(){
                    mce_jQuery('#mce_tmp_error_msg').remove();
                    mce_jQuery('.datefield','#mc_embed_signup').each(
                        function(){
                            var txt = 'filled';
                            var fields = new Array();
                            var i = 0;
                            mce_jQuery(':text', this).each(
                                function(){
                                    fields[i] = this;
                                    i++;
                                });
                            mce_jQuery(':hidden', this).each(
                                function(){
                                	if ( fields[0].value=='MM' && fields[1].value=='DD' && fields[2].value=='YYYY' ){
                                		this.value = '';
									} else if ( fields[0].value=='' && fields[1].value=='' && fields[2].value=='' ){
                                		this.value = '';
									} else {
	                                    this.value = fields[0].value+'/'+fields[1].value+'/'+fields[2].value;
	                                }
                                });
                        });
                    return mce_validator.form();
                }, 
                success: mce_success_cb
            };
  mce_jQuery('#mc-embedded-subscribe-form').ajaxForm(options);

});
function mce_success_cb(resp){
    mce_jQuery('#mce-success-response').hide();
    mce_jQuery('#mce-error-response').hide();
    if (resp.result=="success"){
        mce_jQuery('#mce-'+resp.result+'-response').show();
        mce_jQuery('#mce-'+resp.result+'-response').html(resp.msg);
        mce_jQuery('#mc-embedded-subscribe-form').each(function(){
            this.reset();
    	});
    } else {
        var index = -1;
        var msg;
        try {
            var parts = resp.msg.split(' - ',2);
            if (parts[1]==undefined){
                msg = resp.msg;
            } else {
                i = parseInt(parts[0]);
                if (i.toString() == parts[0]){
                    index = parts[0];
                    msg = parts[1];
                } else {
                    index = -1;
                    msg = resp.msg;
                }
            }
        } catch(e){
            index = -1;
            msg = resp.msg;
        }
        try{
            if (index== -1){
                mce_jQuery('#mce-'+resp.result+'-response').show();
                mce_jQuery('#mce-'+resp.result+'-response').html(msg);            
            } else {
                err_id = 'mce_tmp_error_msg';
                html = '<div id="'+err_id+'" style="'+err_style+'"> '+msg+'</div>';
                
                var input_id = '#mc_embed_signup';
                var f = mce_jQuery(input_id);
                if (ftypes[index]=='address'){
                    input_id = '#mce-'+fnames[index]+'-addr1';
                    f = mce_jQuery(input_id).parent().parent().get(0);
                } else if (ftypes[index]=='date'){
                    input_id = '#mce-'+fnames[index]+'-month';
                    f = mce_jQuery(input_id).parent().parent().get(0);
                } else {
                    input_id = '#mce-'+fnames[index];
                    f = mce_jQuery().parent(input_id).get(0);
                }
                if (f){
                    mce_jQuery(f).append(html);
                    mce_jQuery(input_id).focus();
                } else {
                    mce_jQuery('#mce-'+resp.result+'-response').show();
                    mce_jQuery('#mce-'+resp.result+'-response').html(msg);
                }
            }
        } catch(e){
            mce_jQuery('#mce-'+resp.result+'-response').show();
            mce_jQuery('#mce-'+resp.result+'-response').html(msg);
        }
    }
}
 
