function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

//Display a named menu, at the position of another object
function display_menu(parent,named)
{
	//get the named menu
	var menu_element = document.getElementById(named);
	//override the 'display:none;' style attribute
	menu_element.style.display = "";
	//get the placement of the element that invoked the menu...
	var placement = findPos(parent);
	//...and put the menu there
	menu_element.style.left = placement[0] + "px";
	menu_element.style.top = placement[1] + "px";
}

//Hide a named menu
function hide_menu(named)
{
	//get the named menu
	var menu_element = document.getElementById(named);
	//hide it with a style attribute
	menu_element.style.display = "none";
}

function CheckContactUsForm(MyForm)
{
ErrorMessage='';
Code=MyForm.Code.value;
if(Code != '123keen')
	{
	//document.getElementById('Code').className = 'redTD';
	ErrorMessage+='Please Enter Correct Security Code\n';
	}	
if(ErrorMessage == '')
	{
	MyForm.submit();
	}
else
	{
	alert(ErrorMessage);
	}
}

function TrakIt(ThisSrc)
{
script = document.createElement( 'script' );
script.src = 'https://www.dynamicfootwear.com/phpscripts/pagetraker.php?Page='+ThisSrc;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function SizeSearch(Gender,Size)
{
document.getElementById('InvSizes').innerHTML = "Getting All available Sizes...";	
var url ='http://www.dynamicfootwear.com/phpscripts/AvailableSizeSearch.php?action=go&Gender='+Gender+'&Size='+Size;	
script = document.createElement( 'script' );
script.src = url;
document.getElementsByTagName( 'head' )[0].appendChild( script );	
}

function SwapColor(ColorCode,Style,ColorDesc,Gender)
{
document.getElementById('ColorName').innerHTML = ColorDesc;
ProdN=Gender+' '+Style+' '+ColorDesc;
document.getElementById('ProductName').innerHTML = ProdN;
//alert(Style);
document.getElementById('ImgSwap').innerHTML = "Getting New Image...";	
GetAvailableSizes(ColorCode,Style,Gender);
script = document.createElement( 'script' );
script.src = 'http://www.dynamicfootwear.com/phpscripts/ProductHandler.php?action=GetNewColorPic&ColorCode='+ColorCode+'&Style='+Style+'&Gender='+Gender;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function SwapView(ColorCode,Style,Gender,View)
{
document.getElementById('ImgSwap').innerHTML = "Getting New Image...";	
script = document.createElement( 'script' );
script.src = 'http://www.dynamicfootwear.com/phpscripts/ProductHandler.php?action=GetNewViewPic&ColorCode='+ColorCode+'&Style='+Style+'&Gender='+Gender+'&View='+View;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function GetSelectedColorName(ColorDesc)
{
document.getElementById('ColorName').innerHTML = ColorDesc;
}

function GetColorMini(ColorCode,Style,ColorDescription,Gender)
{
script = document.createElement( 'script' );
script.src = 'http://www.dynamicfootwear.com/phpscripts/ProductHandler.php?action=GetNewColorPicMini&ColorCode='+ColorCode+'&Style='+Style+'&Gender='+Gender+'&DivID='+Style;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}


function GetAvailableSizes(ColorCode,Style,Gender)
{
//alert(ColorCode);
document.getElementById('AvailableSizes').innerHTML = 'Please wait, loading available sizes...';
script = document.createElement( 'script' );
script.src = 'http://www.dynamicfootwear.com/phpscripts/ProductHandler.php?action=AvailableSizes&ColorCode='+ColorCode+'&Style='+Style+'&Gender='+Gender;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function LoadMiniCart()
{
script = document.createElement( 'script' );
script.src = 'https://www.dynamicfootwear.com/NewCart/CartHandler.php?action=LoadMiniCart';
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function SelectSize(SKU)
{
//alert(SKU);
if(SKU != '')
	{document.getElementById('SelectedSize').innerHTML = '<input type=hidden id=UPC12digit name=sku value='+SKU+'>';}

}

var whosChanged = null;
function ChangeColor(el)
{
el.style.backgroundColor = "#FE3000";
el.style.color = "#000000";
if (whosChanged != null)
{
whosChanged.style.backgroundColor = ""
whosChanged.style.color = ""
}
whosChanged = el;
}

function AddToCart(Action)
{		

	if(document.getElementById('UPC12digit'))
		{
		document.getElementById('superminicart').innerHTML = "<img src=\"https://www.dynamicfootwear.com/images/AddingBag.jpg\">";
	  document.getElementById('ImgSwap').innerHTML = "<h1><font color=\"#138816\">Adding to cart...</font></h1>";
		var UPC12digit = document.getElementById('UPC12digit').value;			
		var Qty = document.getElementById('Qty').value;	
		//alert(UPC12digit);
		script = document.createElement( 'script' );
		TheScriptCall='http://www.dynamicfootwear.com/NewCart/CartHandler.php?action='+Action+'&sku='+UPC12digit+'&Qty='+Qty;
		//alert(TheScriptCall);
		script.src = TheScriptCall;
		document.getElementsByTagName( 'head' )[0].appendChild( script );
		}
	else
		{
		alert('Please Choose a size.');
		}
}

var popWin = null    // use this when referring to pop-up window
var winCount = 0
var winName = "popWin"

function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var d_winLeft = 20  // default, pixels from screen left to window left
  var d_winTop = 20   // default, pixels from screen top to window top
  winName = "popWin" + winCount++ //unique name for each pop-up window
  closePopWin()           // close any previously opened pop-up window
  if (openPopWin.arguments.length >= 4)  // any additional features?
    winFeatures = "," + winFeatures+',';
  else
    winFeatures = ""
  //window.open('jex5.htm','mywindow','width=400,height=200,left=0,top=100,screenX=0,screenY=100')
  if (openPopWin.arguments.length == 6)  // location specified
    winFeatures += 'width='+winWidth+',height='+ winHeight+',left='+ winLeft+',top='+ winTop;
  else
    winFeatures += 'width='+winWidth+',height='+ winHeight+',left='+d_winLeft+',top='+ d_winTop
  //alert(winFeatures);
  popWin = window.open(winURL, winName, winFeatures)
  }
  
  
function closePopWin(){    // close pop-up window if it is open
  if (navigator.appName != "Microsoft Internet Explorer"
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popWin != null) if(!popWin.closed) popWin.close()
  }


function getLocation(winWidth, winHeight, winLeft, winTop){
  return ""
  }
  
ParseQuerystring();

function ParseQuerystring(qs) 
{ 
//alert('inside Parse');
// Using this function to grab query string and check for Commission Junction variable ref=cj
	this.params = {};
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) 
		{
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
		if(name == 'ref')
			if(value=='cj')
				{
				//Post Cookie
				//alert('posting cj cookie');
				var exdate=new Date();
				var c_name='ref';
				var expiredays=30;
				exdate.setDate(exdate.getDate()+expiredays);
				//Setting cookie for CJ to expire in 30 days
				document.cookie=c_name+ "=" +escape(value)+
				((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
				}
		}
}