// JavaScript Document
// Copies passed text to the clipboard
	function copyToClipboard(text) {
		var range = document.body.createTextRange();
		range.findText(text);
		range.select();
		document.execCommand("Copy");
		document.execCommand("Unselect");
	}
	
popUpWin = "nowin";
function popWin(name, file, width, height, status, resizable, scrollable) {
	var h=height;
	var w=width;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',status='+status+',resizable='+resizable+',scrollbars='+scrollable;
	popUpWin = window.open( file , name, winprops );
	popUpWin.focus();
}

function pressPop(name) {//800, 750
	popWin(name, 'pressPop.aspx?pid=' + name, 535, 650, 0, 0, 0); //'images/press_med/' + name + '_ar1_md.jpg'
}


function closePopUp() {
	if( popUpWin != "nowin" ) {
		if( !popUpWin.closed ) {
			popUpWin.close();
		}
	}
}
function checkState(THIS, stateField) {
	//alert(THIS.value + '\n' + document.getElementById(stateField).value);
	if (THIS.value != 'US' && THIS.value != 'CA') {
		document.getElementById(stateField).value = '  ';
		//document.getElementById(stateField).disabled = 'disabled';
	}
	else {
		//alert(THIS.value);
		document.getElementById(stateField).value = '';
		//document.getElementById(stateField).disabled = '';
	}
}


function formFocus(element) {
	document.forms[0][element].focus();	
}

function toggleMoreBody(linkDiv, contentDiv) {
	if (document.getElementById(linkDiv).style.display == "block") {
		document.getElementById(linkDiv).style.display = "none";
		document.getElementById(contentDiv).style.display = "block";
	} else {
		document.getElementById(linkDiv).style.display = "block";
		document.getElementById(contentDiv).style.display = "none";
	}
}

function bottomSwap() {
	if (document.getElementById('mainphoto').src.indexOf('_side.jpg') >=0 ) {
		document.getElementById('mainphoto').src = document.getElementById('mainphoto').src.substring(0, document.getElementById('mainphoto').src.indexOf('_side.jpg')) + '_btm.jpg';
		document.getElementById('switchLabel').innerHTML = 'VIEW SIDE';
	}
	else {
		document.getElementById('mainphoto').src = document.getElementById('mainphoto').src.substring(0, document.getElementById('mainphoto').src.indexOf('_btm.jpg')) + '_side.jpg';
		document.getElementById('switchLabel').innerHTML = 'VIEW BOTTOM';
	}
	return true;
}

function updateColor(shoe, selector) {
	var color = selector.options[selector.selectedIndex].value;
	selectColor(shoe, color);
	return true;
}

function colorSwap(source) {
	document.getElementById('mainphoto').src = source;
	document.getElementById('switchLabel').innerHTML = 'VIEW BOTTOM';
	return true;
}

function selectColor(shoe, color) {
	var source = '/collections/images/' + shoe + '_' + color + '_side.jpg';
	colorSwap(source);
	allOff('shoeThumb');
	chooseColor(color);
	document.getElementById('color_'+color).className = "shoeThumb_on";
	return true;
}

function allOff(classname) {
	if (document.getElementsByTagName) {
		var els = document.getElementsByTagName("a");
		var c = new RegExp('/b^|' + classname + '|$/b');
		for (var i = 0; i < els.length; i++)
			if (els[i].className)
				if(c.test(els[i].className))
					els[i].className = 'shoeThumb';
		return true;
	}
}

function chooseColor(color) {
	var colorSelector = document.getElementById('colorSelector');
	for (var i = 0; i < colorSelector.options.length; i++) {
		if (colorSelector.options[i].value == color) {
			colorSelector.selectedIndex = i;
			return true;
		}
	}
}


function preloadImages() {
	var d=document;
	if(d.images){
			if(!d.MM_p)
				d.MM_p=new Array();
		var i,j=d.MM_p.length,a=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];
		}
	}
}