function hide(n) {
	n.style.visibility = 'hidden'; 
	n.style.display = 'none';
	n.style.height = '0'; 
}

function show(n) {
	n.style.visibility = 'visible'; 
	n.style.display = 'block';
	n.style.height = 'auto'; 
}

function showPersOptBox(n) {
	var b = document.getElementById('product_personalization');
	for(var i=0; i<b.childNodes.length; i++) {
		hide(b.childNodes[i]);
	}
	show(document.getElementById(n));
}

function getHTTPObject(){
	if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); }
	else if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); }
	else {
		alert("Your browser does not support AJAX.");
	return null;
	}
}

function switchToVid(n,v) { /*console.log(n+"\n"+v);*/
	if(document.getElementById("clvid_embed_tag") != null) {
		document.getElementById("clvid_embed_tag").src = n;
	}
	document.getElementById("clvid_param_movie").value = n;
	document.getElementById("cl-vid").movie = n;
	
	hide(document.getElementById("product_photo_container")); 
	show(document.getElementById("product_video_container")); 

	httpObj = getHTTPObject();
	httpObj.open("GET","video_counter.php?vid="+v,true);
	httpObj.send(null);
	/*httpObj.onreadystatechange = function() {
		if(httpObj.readyState == 4) { 
			console.log(httpObj.responseText);
		}
	}*/
}

function switchToPhoto(n) {
	document.getElementById("clvid_param_movie").value = '';
	document.getElementById("cl-vid").movie = '';

	document.getElementById("product_image").src = n;
	hide(document.getElementById("product_video_container"));
	show(document.getElementById("product_photo_container"));
}

function checkProductOption(n) {
	pf = document.getElementById('product_form');
	var selopt = -1;
	for(i=pf.opt.length-1; i>-1; i--) {
		if(pf.opt[i].checked) { selopt = i; i = -1; }
	}
	if(selopt == -1) {
		alert('Please select a size');
		return false;
	}
	else {
		e = document.createElement('input');
		e.setAttribute('type','hidden');
		e.setAttribute('name',n.name+'_x');
		e.setAttribute('value','true');
		pf.appendChild(e);
		pf.submit();
	}
}

