﻿// This file should contain all the javascript common functions for all the pages
// please dont forget to add a description of the function right above the function.
// sabari. 

<!--
	//This function can be used to remove the decimals after a specified number.
	// eg: limitDecimalPlaces("34.5000000", 2) will give 34.50
	function limitDecimalPlaces(originalNumber, placesToLimitTo)
	{
		originalNumber = originalNumber.toString();
		var decimalIndex = originalNumber.search(/\./);

		//if there was a decimal point, then go from the start of the string
		//to one more after the decimal index (because we want the decimal) plus
		//the placesToLimitTo that was passed in
		
		if (decimalIndex >= -1) 
		{
   		var limitedToTwoDecimal = originalNumber.substring(0, decimalIndex + 1+ placesToLimitTo);
 		}
 		else
 		{
			var limitedToTwoDecimal = originalNumber;
		}

		return(limitedToTwoDecimal);
	}
	
	// this function extracts the query string parameter from the URL
	// eg: if http://pf2007/Catalog/PFProductDetails.aspx?Category=DressShirts&ProductId=110 is the URL, then
	// getQueryStringParam("Category") returns "DressShirts" and
	// getQueryStringParam("ProductId") returns "110"
	// sabari.
	
	function getQueryStringParam(name)
	{  
		name = name.toLowerCase()
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
		var regexS = "[\\?&]"+name+"=([^&#]*)";  
		var regex = new RegExp( regexS );  
		var results = regex.exec( window.location.href.toLowerCase() );  
		if( results == null )    
			return "";  
		else    
			return results[1];
	}

    // this function is used to show the popup for monogramming
    //marty
    function ShowPopup(href,lineindex,initial,style,location,color,category)
	{
		var str;
		str = href+'?index=' + lineindex + '&initial=' + initial + '&style=' + style + '&location=' + location + '&color=' + color +'&category='+category
		window.open(str,'_blank','height=540,width=280,scrollbars=no,resizeable=no,left=400,top=100')
	}
	
	 function ShowHemCuffPopup(href,lineindex,hcuff,iseam)
	{
		var str;
		str = href+'?index=' + lineindex + '&hemcuff=' + hcuff + '&inseam=' + iseam ;
		window.open(str,'_blank','height=540,width=260,scrollbars=no,resizeable=no,left=400,top=100')
	}

	function setVisible(obj)
	{
		obj = document.getElementById(obj);
		obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
	}

	function placeIt(obj)
	{
		obj = document.getElementById(obj);
		if (document.documentElement)
		{
			theLeft = document.documentElement.scrollLeft;
			theTop = document.documentElement.scrollTop;
		}
		else if (document.body)
		{
			theLeft = document.body.scrollLeft;
			theTop = document.body.scrollTop;
		}
		theLeft += 400;
		theTop += 600;
		obj.style.left = theLeft + 'px' ;
		obj.style.top = theTop + 'px' ;
		setTimeout("placeIt('layer1')",500);
	}
	
	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];}
    }
    
    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];}}
    }
    
    // this function was in the category and detail page but since it is being used in the keyword search button click,
    // i'm moving this function to this file. sabari.
    function setRelClickFlag()
	{
		relClicked = 1;
	}
// -->
