function switchDivs(name_1, name_2) {
	if(document.getElementById(name_1).style.display == 'none') {
		document.getElementById(name_1).style.display = '';
		document.getElementById(name_2).style.display = 'none';
	} else {
		document.getElementById(name_1).style.display = 'none';
		document.getElementById(name_2).style.display = '';
	}
}

var current_menu = 0;

function submenu(elementID) {
	
	if (elementID == -1) {
		if (current_menu == 0)
			elementID = 1;
		else
			elementID =0;
	}
	
	var count = 0;
	var target1 = null;
	while ((target1 = document.getElementById('submenu'+count)) != null) {
			if (target1.id == 'submenu'+elementID)
					target1.style.display = 'block';
			else
					target1.style.display = 'none';
			count++;
	}

	count = 1;
	target1 = null;
	while ((target1 = document.getElementById('menubutton'+count)) != null) {
			if (target1.id == 'menubutton'+elementID) {
				target1.className = 'main_page_header_active';
			}
			else {
				target1.className = 'main_page_header';
			}
			count++;
	}
	
	current_menu = elementID;
}

function location_search(link) {
	document.location.href = link;
}

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];}}
}

function loadXMLString(txt) 
{
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(txt);
  return(xmlDoc);  
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
	{
	parser=new DOMParser();
	xmlDoc=parser.parseFromString(txt,"text/xml");
	return(xmlDoc);
	}
  catch(e) {alert(e.message)}
  }
return(null);
}

function checkAllDomains(form){
	for (var i=0;i< form.elements.length;i++) {
		var e = form.elements[i];
		if (e.checked == false) { e.checked=true; }
	}
}
	  
function uncheckAllDomains(form){
	for (var i=0;i< form.elements.length;i++) {
		var e = form.elements[i];
		if (e.checked == true) { e.checked=false; }
	}
}



function checkCountry(value) {
	if(value == '001')
		document.getElementById('stateDIV').style.display = '';
	else
		document.getElementById('stateDIV').style.display = 'none';
		
	var prefix = '+' + value;
	document.getElementById('prefix_telephone').disabled = true;
	document.getElementById('prefix_fax').disabled = true;
	document.getElementById('prefix_telephone').value = prefix; 
	document.getElementById('prefix_fax').value = prefix;
}

function checkShippingCountry(value) {
	if(value == '001')
		document.getElementById('stateShippingDIV').style.display = '';
	else
		document.getElementById('stateShippingDIV').style.display = 'none';
		
	var prefix = '+' + value;
	document.getElementById('shipping_prefix_telephone').disabled = true;
	document.getElementById('shipping_prefix_telephone').value = prefix; 
}

function checkShippingCountry2(value) {
	if(value == '001')
		document.getElementById('stateDIV').style.display = '';
	else
		document.getElementById('stateDIV').style.display = 'none';
		
	var prefix = '+' + value;
	document.getElementById('prefix_telephone').disabled = true;
	document.getElementById('prefix_telephone').value = prefix; 
}

function checkShippingAddress(form, value) {
	if(value) {
		document.getElementById('new_shipping').style.display = 'none';
		document.getElementById('old_shipping').style.display = '';
	} else {
		document.getElementById('new_shipping').style.display = '';
		document.getElementById('old_shipping').style.display = 'none';
	}
		
}

function TwitThis(url, title) {
	window.open("http://twitter.com/home?status="+((title) ? encodeURIComponent(title.replace(/^\s*|\s*$/g,'')) : "")+" "+url, "TwitThisPop", "width=600, height=600, location, status, scrollbars, resizable");
}

function changeButton(value) {
	if(value == 'new') {
		document.getElementById('returningDIV').style.display = 'none';
		document.getElementById('newDIV').style.display = '';
		document.getElementById('lostDIV').style.display = 'none';
	} else if(value == 'lost') {
		document.getElementById('returningDIV').style.display = 'none';
		document.getElementById('newDIV').style.display = 'none';
		document.getElementById('lostDIV').style.display = '';
	} else if(value == 'returning') {
		document.getElementById('returningDIV').style.display = '';
		document.getElementById('newDIV').style.display = 'none';
		document.getElementById('lostDIV').style.display = 'none';
	}
}


function slideSwitch() {
	var $active = jQuery('#slideshow DIV.active');
	
	if ( $active.length == 0 ) $active = jQuery('#slideshow DIV:last');

	// use this to pull the divs in the order they appear in the markup
	var $next =  $active.next().length ? $active.next()
		: jQuery('#slideshow DIV:first');

	// uncomment below to pull the divs randomly
	// var $sibs  = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next  = $( $sibs[ rndNum ] );


	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

jQuery(function() {
	setInterval( "slideSwitch()", 5000 );
});

function Basket(action, id, value) {
	if(action == 'delete') {
		var conf = confirm("Are you sure you want to delete this item?");
		if(conf) {
			ManageBasket(action, id, value);
			TabsContent(5);
		}	
	} else if(action == 'price') {
		ManageBasket(action, id, value);
		TabsContent(5);
	}
}

function Lightbox(action, id, value) {
	if(action == 'delete') {
		var conf = confirm("Are you sure you want to delete this item?");
		if(conf) {
			ManageLightbox(action, id, value);
			TabsContent(4);
		}	
	} else if(action == 'price') {
		ManageLightbox(action, id, value);
		TabsContent(4);
	}
}

function Register_std(thickbox_id) {
	if(thickbox_id)
		tb1_show('Register a new 3d4Medical.com account', '/register-front.html?keepThis=true&TB1_iframe=true&height=400&width=940', '');
	else
		tb_show('Register a new 3d4Medical.com account', '/register-front.html?keepThis=true&TB_iframe=true&height=400&width=940', '');
}

function sleep(milliseconds) {
	var start = new Date().getTime();
	for (var i = 0; i < 1e7; i++) {
		if ((new Date().getTime() - start) > milliseconds){
			break;
		}
	}
}

function openpopup(popurl){ 
	winpops=window.open(popurl,"","scrollbars=0,toolbar=0,menubar=0,status=0,resizable=no,screenX=0,screenY=0,left=150,top=0"); 
	//winpops.body.clientWidth=480;
	//winpops.body.clientHeight=730;
	//winpops.moveTo(100,0);
	//winpops.resizeTo(480,730);
}

function appstore(link, message) {
	if(message != '')
		alert(message);
	if(link != '')
		window.open(link);
		//document.location.href = link;	
}

function flashlink(link_main,link, message, status) {
	if (status == 2) {
		if(message != '')
			alert(message);
		if(link != '')
			openpopup(link);
	}
	else if (status == 1) {
		alert("You are logged in - but in order to access the free online versions, you must first purchase at least one iPhone version from itunes. Once you have purchased one of our iPhone apps from iTunes, please write a review and email it to us at iPhoneReviews@3D4Medical.com as proof of purchase and we will register you for access to all online app versions! Please ensure you send us your 3D4Medical.com login user name as well as your itunes review!");
	}
	else
		alert("You must login to use the online app versions.");
}

function FilterSearch() {
	var filters = document.getElementById('results_filters').value;
	var query = document.getElementById('search_q').value;
	var category = document.getElementById('category_q').value;
	
	if(document.getElementById('sci').checked)
		var type = 'i';
	else
		var type = 'a';
	tb_show('Filter search', '/filter-search.html?f='+ filters +'&t='+ type +'&c='+ category +'&q='+ query +'&keepThis=true&TB_iframe=true&height=auto&width=640', '');
}

function AdvancedSearch() {
	tb_show('Filter search', '/advanced-search.html?keepThis=true&TB_iframe=true&height=auto&width=640', '');
}

function moreFields(counter) {
	counter++;
	document.getElementById('counter').value = counter;
	var newFields = document.getElementById('readroot').cloneNode(true);
	newFields.id = '';
	newFields.style.display = 'block';
	var newField = newFields.childNodes;
	var nam="";
	for (var i=0;i<newField.length;i++)
	{
		var theName = newField[i].name;
		nam += theName;
		if(theName == 'friend_name'){
			newField[i].name = theName + counter;
			newField[i].id = theName + counter;
		}
		if(theName == 'friend_email'){
			newField[i].name = theName + counter;
			newField[i].id = theName + counter;
			newField[i].className = theName + counter;
		}
	}
	var insertHere = document.getElementById('writeroot');
	insertHere.parentNode.insertBefore(newFields,insertHere);
}

function ModifyImage(img_id, style_id, img_horizontal) {
	if(img_horizontal)
		tb1_show('Modify Image', '/modify-image.html?id='+img_id+'&style='+style_id+'&keepThis=true&TB1_iframe=true&height=720&width=750', '');
	else
		tb1_show('Modify Image', '/modify-image.html?id='+img_id+'&style='+style_id+'&keepThis=true&TB1_iframe=true&height=720&width=750', '');
}

function HowItWorks() {
	tb_show_without_exit('3D4Medical Skeleton System App Review', '/how-it-works.html?keepThis=true&TB_iframe=true&height=420&width=480', '');
	//tb_show('Filter search', '/how-it-works.html?keepThis=true&TB_iframe=true&height=auto&width=auto', '');
}
