//*********************************
// common functions for carbon news
//*********************************

function SaveAdClick(recordID) {
	var img = new Image()
	img.src = "savehit.asp?adid="+recordID
}

//*********************************
// standard common functions
//*********************************

var lastWin

function PopupScreenCentre(url,name,width,height,scrollbars) 
{
	var titleBarHeight, windowBorderWidth
	titleBarHeight = 24
	windowBorderWidth = 4

	var screenWidth, screenHeight
	screenWidth = 800
	screenHeight = 600

	if (window.screen) 
	{
		if (window.screen.availWidth) 
		{
			// ok browser has the appropriate properties we need to centre it
			screenWidth = window.screen.availWidth
			screenHeight = window.screen.availHeight
		}
	}

	var windowWidth = windowBorderWidth + width + windowBorderWidth
	var windowHeight = titleBarHeight + height + windowBorderWidth

	var left = (screenWidth - windowWidth) / 2
	var top = (screenHeight - windowHeight) / 2

	if(lastWin&&!lastWin.closed)
	{
		lastWin.close()
	}
	lastWin = window.open(url,name,'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+height+',scrollbars=1,resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0')
}

function makeRequest(url,returnFunction) 
// example usage: makeRequest(url + "&ajax=true", function(http_request) { PickerSetResultCallback(formName, fieldName, suffix, url, searchKeyword, http_request.responseText) })
{
	url += "&cachernd=" + Math.random()
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance. You may need to adjust your ActiveX controls settings. Please call David Lewis at Pengellys on 09 256 4901 if you would like more information.');
		return false;
	}
	if (typeof(returnFunction)=="string") {
		//returnFunction = returnFunction + '(http_request)';
		returnFunc = function(http_request) { eval(returnFunction + "(http_request)") }
	} else {
		returnFunc = returnFunction
	}
	http_request.onreadystatechange = function() { 
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				//eval(returnFunction) 
				returnFunc(http_request)
			} else if (http_request.status == 500) {
  	    alert('There was a problem with the request. http_request.status['+http_request.status+']');
  	    alert(http_request.responseText);
			} else {
  	    alert('There was a problem with the request. http_request.status['+http_request.status+']');
			}
    }
	};
	if(true || url==prompt('call:',url)) 
	{
		http_request.open('GET', url, true);
		http_request.send(null);
	}
}

function IsEmail(str) {
	// trim the value
	str = str.replace(/^\s+|\s+$/g, '') ;
	// check if the string is a valid email address
	var tAtPos;
	var tDotPos;
	var tLastDotPos;
	//
	tAtPos = str.indexOf("@");
	tDotPos = str.indexOf(".");
	tLastDotPos = str.lastIndexOf(".");
	//  Must be an @ symbol and a period somewhere there
	if (tAtPos == -1) return false
	if (tDotPos == -1)  return false
	//  No double @@ or ..
	if (str.indexOf("..") != -1 )  return false
	if (str.indexOf("@@") != -1 )  return false
	if (str.indexOf("@.") != -1 )  return false
	if (str.indexOf(".@") != -1 )  return false
	// No #'"?!&*
	if (str.indexOf("'") != -1 )  return false
	if (str.indexOf('"') != -1 )  return false
	if (str.indexOf("#") != -1 )  return false
	if (str.indexOf("?") != -1 )  return false
	if (str.indexOf("!") != -1 )  return false
	if (str.indexOf("&") != -1 )  return false
	if (str.indexOf("*") != -1 )  return false
	//  Only one @ allowed
	if (str.indexOf("@", tAtPos+1) != -1 )  return false
	//  No spaces allowed
	if (str.indexOf(" ") != -1 )  return false
	//  No leading @ or . allowed
	if (tAtPos == 0 || tDotPos == 0)  return false
	//  The last . must be after the @
	//  And must be text between the last . and the @
	if (tLastDotPos < tAtPos+2)  return false
	//  Must be 2 or 3 or 4 or 6 (for travel) letters behind the last .
	if ((str.charAt(str.length-3) != ".") && (str.charAt(str.length-4) != ".") && (str.charAt(str.length-5) != ".") && (str.charAt(str.length-7) != "."))  return false
	//  All good.
	return true;
}

function SaveBannerEvent(recordID) {
	var img = new Image()
	img.src = "savehit.asp?bannerid="+recordID
}