var _d = document;
function showTab(tab) {
 var tb=lt.id.substring(1); // pull out previous number
 ta=tab.id.substring(1); // pull out the current number
 lt.className='tabtextover'; // change previous to class o
 tab.className='tabtextover';
 lt=tab;

 // display table
 _d.getElementById('s'+tb).style.display="none";
 _d.getElementById('s'+ta).style.display="block";
 _d.getElementById('m'+ta).className='tabtextover';
  _d.getElementById('m'+tb).className='tabtext';
}

function viewimage(URL,productid) {
	var newwinwidth = 790;
	var newwinheight = 590;
	window.open(URL+'pop_viewimage.cfm?productid=' + productid, "ViewPhoto", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=" +newwinwidth+",height=" +newwinheight+",top=0,left=0");
	}	

var browserName = navigator.appName;
		var browserVer = parseInt(navigator.appVersion);
		var version = "";
		var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
		if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror" || browserName=="Opera") {version = "n3";} else {version = "n2";}
			// Blurring links:
		function blurLink(theObject)	{	//
			if (msie4)	{theObject.blur();}
		}

// clear search form

function clearFRMSearch() {
	if (document.FrmSearch.keyword.value=='Search') {
		document.FrmSearch.keyword.value='';
	}
}
// toggle visibility code

function toggle(obj) {
 var el = document.getElementById(obj);
 el.style.display = (el.style.display != 'none' ? 'none' : '');
}
// Contact Us Form Validation
	function contactsubmit()
	
	{
		if (FRMSubmit.contact_name.value == '')
		{
			alert("Please enter your name");
			FRMSubmit.contact_name.focus();
			return false;
		}
		if (FRMSubmit.contact_Email.value == '')
		{
			alert("Please enter your email address");
			FRMSubmit.contact_Email.focus();
			return false;
		}			
		if (FRMSubmit.contact_subject.value == '')
		{
			alert("Please enter a subject for the email");
			FRMSubmit.contact_subject.focus();
			return false;
		}
		if (FRMSubmit.contact_comments.value == '')
		{
			alert("Please enter the message.");
			FRMSubmit.contact_comments.focus();
			return false;
		}
		
	return true;
	}

// search form validation
function searchsubmit() {
	if (FRMsearch.keyword.value == '')
		{
			alert("Please enter a keyword to search for");
			FRMsearch.keyword.focus();
			return false;
		}
}

// Extranet Login Form Validation
	function extranetloginsubmit()
	
	{
		if (FRMLogin.user_email.value == '')
		{
			alert("Please enter your username");
			FRMLogin.user_email.focus();
			return false;
		}
		if (FRMLogin.user_password.value == '')
		{
			alert("Please enter your password");
			FRMLogin.user_password.focus();
			return false;
		}
		
	return true;
	}

	function leftloginsubmit()
	
	{
		if (FRMLeftLogin.user_email.value == '')
		{
			alert("Please enter your username");
			FRMLeftLogin.user_email.focus();
			return false;
		}
		if (FRMLeftLogin.user_password.value == '')
		{
			alert("Please enter your password");
			FRMLeftLogin.user_password.focus();
			return false;
		}
		
	return true;
	}

// Email Password Form Validation
	
	function passreqsubmit()
	
	{
		if (FRMPasswordReq.email.value == '')
		{
			alert("Please enter your email address");
			FRMPasswordReq.email.focus();
			return false;
		}
		
	return true;
	}	
	
// Extranet Registration Form Validation
	function extranetregistrationsubmit()
	{	
			
		if (FRMRegister.Fname.value == '')
		{
			alert("Please enter your first name");
			FRMRegister.Fname.focus();
			return false;
		}
		if (FRMRegister.Sname.value == '')
		{
			alert("Please enter your surname");
			FRMRegister.Sname.focus();
			return false;
		}
/*		if (FRMRegister.nzmn.value == '')
		{
			alert("Please enter your NZ Medical Number");
			FRMRegister.nzmn.focus();
			return false;
		}		
*/		
		//basic email address syntax validation
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(FRMRegister.email.value) == false) {
			alert("Invalid E-mail Address! Please re-enter.");
			return false;
		}
		
/*		if (FRMRegister.companyname.value == '')
		{
			alert("Please enter your Practice name");
			FRMRegister.companyname.focus();
			return false;

		}
*/	
		if (FRMRegister.address1.value == '')
		{
			alert("Please enter your address");
			FRMRegister.address1.focus();
			return false;
		}			
		if (FRMRegister.city.value == '')
		{
			alert("Please enter your city");
			FRMRegister.city.focus();
			return false;
		}	
		
/*				if (FRMRegister.postcode.value == '')
		{
			alert("Please enter your postcode/ZIP");
			FRMRegister.postcode.focus();
			return false;
		}	*/
			
		
		var telnr = /^\+?[0-9 ()-]+[0-9]$/;
		if (!telnr.test(FRMRegister.phone.value) || (FRMRegister.phone.value == '')) {
    		alert("Please enter a valid phone number with no letters");
			FRMRegister.phone.focus();
			return false;
		}	
		
		
				
		if (FRMRegister.user_password.value == '')
		{
			alert("Please enter your password")
			FRMRegister.user_password.focus();
			return false;
		}
		
		if (FRMRegister.user_password.value.length < 4) {
			alert("Please enter a password that is 4 or more characters long.")
			FRMRegister.user_password.focus();
			return false;
		}
		if (FRMRegister.user_password_confirm.value == '')
		{
			alert("Please enter your password confirmation");
			FRMRegister.user_password_confirm.focus();
			return false;
		}
		if (FRMRegister.user_password.value != FRMRegister.user_password_confirm.value  ) {
			alert("Your password and password confirmation do not match.\nPlease make sure your password and password confirmation are the same");
			FRMRegister.user_password_confirm.focus();
			return false;
		}
/*		if (FRMRegister.disclaimer.checked == false) {
			alert("You must accept the site Terms & Conditions to proceed.");
			FRMRegister.disclaimer.focus();
			return false;
		}	*/	
		
	return true;
	}

// Extranet Registration Form Validation
	function extranetregistrationupdate()
	{	
			
		if (FRMRegister.Fname.value == '')
		{
			alert("Please enter your first name");
			FRMRegister.Fname.focus();
			return false;
		}
		if (FRMRegister.Sname.value == '')
		{
			alert("Please enter your surname");
			FRMRegister.Sname.focus();
			return false;
		}
/*		if (FRMRegister.nzmn.value == '')
		{
			alert("Please enter your NZ Medical Number");
			FRMRegister.nzmn.focus();
			return false;
		}		
*/		
		//basic email address syntax validation
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(FRMRegister.email.value) == false) {
			alert("Invalid E-mail Address! Please re-enter.");
			return false;
		}
		
/*		if (FRMRegister.companyname.value == '')
		{
			alert("Please enter your Practice name");
			FRMRegister.companyname.focus();
			return false;
		}	
*/		
		if (FRMRegister.address1.value == '')
		{
			alert("Please enter your address");
			FRMRegister.address1.focus();
			return false;
		}			
		if (FRMRegister.city.value == '')
		{
			alert("Please enter your city");
			FRMRegister.city.focus();
			return false;
		}	
			
/*		if (FRMRegister.postcode.value == '')
		{
			alert("Please enter your postcode/ZIP");
			FRMRegister.postcode.focus();
			return false;
		}	*/
			
		
		var telnr = /^\+?[0-9 ()-]+[0-9]$/;
		if (!telnr.test(FRMRegister.phone.value) || (FRMRegister.phone.value == '')) {
    		alert("Please enter a valid phone number with no letters");
			FRMRegister.phone.focus();
			return false;
		}	
		
		
		//alert(FRMRegister.user_password.value.length);		
		if (FRMRegister.user_password.value.length > 0){
					
			if (FRMRegister.user_password.value.length < 4) {
				alert("Please enter a password that is 4 or more characters long.");
				FRMRegister.user_password.focus();
				return false;
			}
			if (FRMRegister.user_password.value != FRMRegister.user_password_confirm.value  ) {
			alert("Your password and password confirmation do not match.\nPlease make sure your password and password confirmation are the same");
			FRMRegister.user_password_confirm.focus();
			return false;
			}
			
			//return confirm("Are sure you want change your password?");

		}
			
						
/*		if (FRMRegister.disclaimer.checked == false) {
			alert("You must accpet the site Terms & Conditions to proceed.");
			FRMRegister.disclaimer.focus();
			return false;
		}		
*/		
	return true;
	}	
	
//Standard Functions
function open_new(url) {
	new_win = window.open(url,"new_win",'toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1');
	}
	
function open_new_resize(url, h, v) {
//	var mynew_win;
	if(top.mynew_win){
		if (top.mynew_win.open){
			if (top.mynew_win.closed){
				mynew_win = window.open(url,"new_win","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=1,width=" +h+",height=" +v+",top=50,left=50");
			}
			else{
				top.mynew_win.close();
				top.mynew_win = window.open(url,"new_win","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=1,width=" +h+",height=" +v+",top=50,left=50");
				
			}
		}
	}
	else {
					top.mynew_win = window.open(url,"new_win","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=1,width=" +h+",height=" +v+",top=50,left=50");
	}

top.mynew_win.focus();

}	
	
function open_email(url) {
	new_email = window.open(url,"new_email",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0, width=450, height=500');
	}
function open_print(url) {
	new_print = window.open(url,"new_print",'toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0, width=630, height=600');
	}	
function open_subscription(url) {
	new_sub = window.open(url,"new_sub",'toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=0,width=450,height=500');
	}	
	
// navigation
function sendToPage(toLocation) {
	if (toLocation != "")
		top.location.href=toLocation;
	}


	// this tests that file must be of certain type
function testForFileExtensions(myForm,extensions)
	{
	var objReg;
	var extension;
	var strErrorMsg = "."+extensions[extensions.length-1];
	var ok = false;
	(extensions.length>1)?strErrorMsg=" or "+strErrorMsg:strErrorMsg+=" ";
	
	for (i=0;i<extensions.length;i++)
	 {
	 extension = extensions[i];
	 objReg = "/\."+extension+"$/i.test(myForm.TopImage.value)";
	 if ((eval(objReg))) ok = true;
	 if (i<extensions.length-1) strErrorMsg = "."+extension+", "+strErrorMsg;
	 }
	
	if (!ok)
	 {
	 alert("Please select a file with extension "+strErrorMsg);
		myForm.TopImage.focus();
		return false;
	 } return true;
}

// open view photo window

function viewphoto (photoid,winwidth,winheight,viewthumb) {
	var TheUrl = siteurl;
	var newwinwidth = winwidth + 30;
	var newwinheight = winheight + 30;
	//alert (viewthumb);
	if (viewthumb == 1) {
		window.open(TheUrl + 'pop_viewphoto.cfm?photoid=' + photoid+'&viewthumb=yes', "ViewPhoto", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=" +newwinwidth+",height=" +newwinheight+",top=0,left=0");
	}
	else {
		window.open(TheUrl + 'pop_viewphoto.cfm?photoid=' + photoid, "ViewPhoto", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=" +newwinwidth+",height=" +newwinheight+",top=0,left=0");
	}
}

// open view photo window

function viewslideshow (photoid,winwidth,winheight,categoryid,viewthumb) {
	
	var TheUrl = siteurl;
	var newwinwidth = winwidth + 50;
	var newwinheight = winheight + 50;
	//alert (TheUrl);
	if (viewthumb == 1) {
		window.open(TheUrl + 'pop_viewslideshow.cfm?photoid=' + photoid+'&categoryid='+categoryid+'&viewthumb=yes', "ViewPhoto", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=" +newwinwidth+",height=" +newwinheight+",top=0,left=0");
	}
	else {
		window.open(TheUrl + 'pop_viewslideshow.cfm?photoid=' + photoid+'&categoryid='+categoryid, "ViewPhoto", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=" +newwinwidth+",height=" +newwinheight+",top=0,left=0");
	}
}

//existing site functions
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 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_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];}
}



/*******************************
***** CHECK EMAIL VIA AJAX *****
*******************************/
/*
$(function()
{
	var checkemailtimer;
	$(".checkemail").keyup(function(e)
	{
		$theemail = $(this).val();
		$thisparent = $(this).parent();
		
		$("div#prompt",$($thisparent)).remove();
		
		if(checkemailtimer)
		{
			clearTimeout(checkemailtimer);
		}
		checkemailtimer = setTimeout(function()
		{
			if($.trim($theemail) != "")
			{
				if($("#customeremail").size() > 0)
				{
					if($.trim($theemail) != $.trim($("#customeremail").val()))
					{
						$.post(
							"/_checkemail.cfm",
							{
								emailaddress:$theemail,
								returnpath:$("#returnpath").val()
							},
							function(data)
							{
								$thisparent.append(data);
							}
						);
					}
				}
				else
				{
					$.post(
						"/_checkemail.cfm",
						{
							emailaddress:$theemail,
							returnpath:$("#returnpath").val()
						},
						function(data)
						{
							$thisparent.append(data);
						}
					);
				}
				
			}
		},500);
	});
	
	$(".autopasswordrequest").livequery("click",function(e)
	{
		e.preventDefault();
		$.post(
			"/_autopasswordrequest.cfm",
			{
				autopasswordrequest:$(this).attr("id"),
				returnpath:$("#returnpath").val()
			},
			function(data)
			{
				$("div#prompt").removeClass("notice").addClass("success").html(data);
			}
		);
	});
	
	$(".closeprompt").livequery("click",function(e)
	{
		e.preventDefault();
		$("div#prompt").remove();
	});
});
*/

