function loadNZOS(which,what) {
	$.get("/nzonscreen.cfm", function(data){
		$.facebox(data);
		var flashVars;
		var flashObjectId = "flash_screentalk_videoid_"+what;
		flashVars="xmlURL=http://www.nzonscreen.com/related_material_data_output/video_single/"+what+"&amp;useSelector=false";
		generateFlash("nzonscreenvideo", "http://www.nzonscreen.com/resources/media/nza_vid_player_[890x400].swf", 432, 393, flashVars, "", "");
	});
}

function checkEmailExists(which) {
	$.get("/ajax-check_email_exists.cfm?e="+$("#em"+which).val(), function(xml){
		$(xml).find("user").each(function(){
			$("#fn"+which).val($(this).attr("fn"));
			$("#ln"+which).val($(this).attr("ln"));
			$("#pc"+which).val($(this).attr("pc"));
			$("#couid"+which).val($(this).attr("couid"));
			$("#occ"+which).val($(this).attr("occ"));
			$("#natid"+which).val($(this).attr("natid"));
			$("#uaid"+which).val($(this).attr("uaid"));
			$("#ulid"+which).val($(this).attr("ulid"));
			$("#ref"+which).val($(this).attr("ref"));
			$("#uid"+which).val($(this).attr("uid"));
			$("#sid"+which).val($(this).attr("sid"));
			if($(this).attr("cbs")=="1") {
				$("#cbs"+which).attr("checked", "checked");
			} else {
				$("#cbs"+which).removeAttr("checked");
			}
			if($(this).attr("nus")=="1") {
				$("#nus"+which).attr("checked", "checked");
			} else {
				$("#nus"+which).removeAttr("checked");
			}
		});
	});
}

function pollRedirect(which) {
	$.get("/__poll.cfm?pid="+which, function(data) {
		tmp=data.split("|");
		if(tmp[0]=="0") {
			$("#pollanswer").html(tmp[1]);
		} else if(tmp[0]=="1") {
			document.location.href=tmp[1];
		} else if(tmp[0]=="2") {
			window.open(tmp[1],"_blank","directories=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1");
		}
	});
}

function searchFocus(which) {
	if(which.value=="Search the site") {
		which.value="";
		which.className="input_focus";
	}
}
function searchBlur(which) {
	if(which.value=="") {
		which.value="Search the site";
		which.className="input_blur";
	}
}

function viewSpecifiedImage(which) {
	var x = window.open('','pictureViewer','width=800,height=800,resizable=1');
	if( !x ) { return true; }
	x.document.open();
	x.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>Picture Viewer<\/title>');
	x.document.write('<sc'+'ript type="text/javascript">');
	x.document.writeln('var isNN,isIE;');
	x.document.writeln('function reSizeToImage(){');
	if (navigator.appName.indexOf("Microsoft")==-1)
	{
		x.document.writeln('window.innerWidth=document.images["ex_popimage"].width;');
		x.document.writeln('window.innerHeight=document.images["ex_popimage"].height;');
		x.document.writeln('document.title="Picture Viewer";');
	}else if(window.opera){
		x.document.writeln('window.resizeTo(100,100);');
		x.document.writeln('width=130-(document.body.clientWidth-document.images[0].width);');
		x.document.writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		x.document.writeln('window.resizeTo(width,height);');
	}else{
		x.document.writeln('window.resizeTo(100,100);');
		x.document.writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		x.document.writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		x.document.writeln('window.resizeTo(width,height);');
	}
	x.document.writeln('}<\/sc'+'ript>');
	x.document.write('<\/head><body style="margin:0px;" id="ex_popbody" onload="reSizeToImage();self.focus();">');
	x.document.write('<img id="ex_popimage" name="ex_popimage" src="'+which+'" onclick="window.close();" alt="" \/><\/body><\/html>');
	x.document.close();
	if( x.focus ) { x.focus(); }
}

// Window opening
function winOpenCenter(url,name,statbar,scroll,locate,resize,xWidth,yWidth)	{
	var adjustedleft = 8//optional
	var adjustedheight = 30//adjust height because of windows taskbar
	var screenwidthremainder = screen.availWidth%2//really not needed, but won't hurt
	var screenheightremainder = screen.availHeight%2
	var screenwidth = screen.availWidth - screenwidthremainder
	var screenheight = screen.availHeight - screenheightremainder
	var winheight = yWidth //set new window height properties
	var winwidth = xWidth //set new window width properties
	var winleft = parseInt(screenwidth/2) - (winwidth/2) - adjustedleft//optional
	var wintop = parseInt(screenheight/2) - (winheight/2) - adjustedheight
	var win = window.open(url,name,'width=' +winwidth+ ',height=' +winheight+',status=' +statbar+',resizable='+resize+',scrollbars='+scroll+',location='+locate+',top='+wintop+',left='+winleft);
	return win;
}

// Email checker
function ValidateEmailAddress(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		var textObj =document.getElementById("Email"); 
		alert("Please enter a valid email address.")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		var textObj =document.getElementById("Email"); 
	    alert("Email address username is not valid.")
	    return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
				var textObj =document.getElementById("Email"); 
		        alert("Email address destination IP is invalid.")
			return false
		    }
	    }
	    return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		var textObj =document.getElementById("Email"); 
		alert("Email address domain name doesn't seem to be valid.")
	    return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) {
		var textObj =document.getElementById("Email"); 
		alert("Email address must end in a three or four-letter domain, or two letter country.")
		return false
	}
	if (len<2) {
		var textObj=document.getElementById("Email"); 
		var errStr="Email address is missing a hostname."
		alert(errStr)
		return false
	}
	return true;
}
