function navOver(imgTag){var theImage = imgTag;if(theImage.src.indexOf("_off.") != -1)theImage.src = theImage.src.replace("_off.","_over."); else theImage.src = theImage.src.replace("_over.","_off.");}
function addLoadEvent(func){var oldonload = window.onload;if (typeof window.onload != 'function'){window.onload = func;}else{window.onload = function(){if (oldonload){oldonload();}func();}}} 
document.getElementsByClassName = function(elClassName){var arrayList = new Array();var elements = document.getElementsByTagName("*");for(var i = 0;i < elements.length;i++){if(elements[i].className.indexOf(" ") >= 0){var classes = elements[i].className.split(" ");for(var j = 0;j < classes.length;j++){if(classes[j] == elClassName){arrayList.push(elements[i]);}}}else if(elements[i].className == elClassName){arrayList.push(elements[i]);}}return arrayList;}
			
addLoadEvent( function()
{
	EmailAFriend.Init();
});

function setCbs(el,image)
{													
	if(el.checked == true)							
		image.src = image.src.replace("_false.gif","_true.gif");							
	else
		image.src = image.src.replace("_true.gif","_false.gif");																											
}			

var printButton;
var checklistArray = new Array();

function definePrintButton()
{
	var printButton = document.getElementsByClassName("btnPrintCheckList")[0];
	printButton.id = "btnPrintCheckList";
	var clickEvent = printButton.href+"?";
	for(var i=0;i<checklistArray.length;i++)	
	{		
		clickEvent += "cb" + (i+1) + "=" + checklistArray[i].checked;
		if((i+1)<checklistArray.length) clickEvent += "&";
	}
	window.open(clickEvent, "", "width=650,height=800");	
}

function defineElements(cbEl, imgEl)
{			
	if(document.getElementById("btnPrintCheckList") == null) 
	{ 		
		printButton = document.getElementsByClassName("btnPrintCheckList")[0];
		printButton.id = "btnPrintCheckList";
		printButton.onclick = function()
		{
			definePrintButton();return false;
		};
	}
	
	cbEl.onclick = function()
	{																									
		setCbs(cbEl, imgEl);			
	};		
	
	checklistArray.push(cbEl);	
	cbEl.className = "hideCb";
	imgEl.className = "";
	
	if(cbEl.checked == true) {
		imgEl.src = imgEl.src.replace("_false.gif","_true.gif");
	}

	if(navigator.appName.indexOf("Internet Explorer") != -1)
	{
		imgEl.onclick = function()
		{
			changeCbs(cbEl, imgEl)
		};
	}	
}	

function changeCbs(el,image)
{
	if(image.src.indexOf('_false.gif') != -1)	{						
		image.src = image.src.replace("_false.gif","_true.gif");		
		el.checked = true;
	} else {
		image.src = image.src.replace("_true.gif","_false.gif");	
		el.checked = false;
	}
}	
					
var EmailAFriend = {
	Div: null,
	Btn: null,
	MaxHeight: null,
	Scrolling: null,	
	Init: function()
	{
		Scrolling = false;
		Div = document.getElementById('emailFields');
		Btn = document.getElementById('btnTellAFriend');
		Btn.onclick = EmailAFriend.Toggle;						
		Btn.removeAttribute('href');
		Btn.style.cursor = 'pointer';
		
		if(Div != null)
		{	
			MaxHeight = Div.offsetHeight;		
			Div.style.overflow = "hidden";			
			Div.style.height = 0 + "px";	
		}				
	},
	Toggle: function()
	{
		if(Scrolling == true) return;		
		if(parseInt(Div.style.height) == 0) EmailAFriend.Open();					
		else EmailAFriend.Close();		
	},
	Open: function()
	{
		Div.style.height = parseInt(Div.style.height) + 10 + "px";			
		if(parseInt(Div.style.height) < MaxHeight){						
			Scrolling = true;			
			setTimeout('EmailAFriend.Open()',50);
		} else {
			Scrolling = false;
		}
	},
	Close: function()
	{
		var speed;
		
		if(parseInt(Div.style.height) <= 10) speed = parseInt(Div.style.height);			
		else speed = 10;
			
		Div.style.height = parseInt(Div.style.height) - speed + "px";		
		if(parseInt(Div.style.height) > 0){
			Scrolling = true;
			setTimeout('EmailAFriend.Close()', 50);			
		} else {
			Scrolling = false;	
		}
	}
	
};

function addSwf(tagName, parentName)
{
	var ParentName = "";
	var TagName = "";
	
	var containerDiv = document.getElementsByClassName('pageContent')[0];
	
	for(var i=0;i<containerDiv.childNodes.length;i++)
	{
		var itemDiv = containerDiv.childNodes[i];							
		if(itemDiv.nodeName == "H3") itemDiv.className = "subTitle";						
	}		
}

var _debug;
function createSwftype(swftypeTag, swftypeSrc, cssSrc, swftypeWidth, swftypeHeight, txtSelect, resizeType, debug)
{
	_debug = debug;
	
	var elClassName = "";
	var hasDot = false;
	if(swftypeTag.indexOf(".") != -1)
	{	
		hasDot = true;
		elClassName = swftypeTag.substring(swftypeTag.indexOf(".")+1, swftypeTag.length);
		swftypeTag = swftypeTag.substring(0, swftypeTag.indexOf("."));
		if(swftypeTag.length==0)
		{
			swftypeTag=elClassName;
		}
	}		
	
	if((document.getElementsByTagName(swftypeTag) != "") || (document.getElementsByClassName(swftypeTag) != ""))
	{	
		if(document.getElementsByTagName(swftypeTag).length > 0)											
			var theSwftypeTag = document.getElementsByTagName(swftypeTag);												
		else if(document.getElementsByClassName(swftypeTag).length > 0 )
			var theSwftypeTag = document.getElementsByClassName(swftypeTag);			
	
		if(theSwftypeTag != null)
		{
			for(var i=0; i<theSwftypeTag.length; i++)
			{			
				var obj = theSwftypeTag[i];
				var tagName = obj.tagName;	
				var className= obj.className;	
				
				if(obj.className.indexOf(elClassName) != -1)
				{
					className = obj.className;
					obj.setAttribute('id', 'Swftype'+swftypeTag+i);			
					if(obj.innerHTML != null)
					{
						/* Swftype Content */
						var pageTxt = obj.innerHTML;			
						// search and add ' in classNames 
						if(pageTxt.indexOf('class=') != -1){			
							var firstQuote = (pageTxt.indexOf('class=') + 6);
							var spanCloseTag = pageTxt.indexOf('>');
							var className = pageTxt.substr(firstQuote, (spanCloseTag - firstQuote));				
							if(pageTxt.charAt(firstQuote) != '"'){
								pageTxt = pageTxt.replace(className,'"'+className+'"');
							}
						}									
						
						var printAlt = document.createElement("span");				
						// printAlt.setAttribute("class", "printSwfType");   
						printAlt.className = "printSwfType";				
						printAlt.innerHTML = pageTxt;   						
						obj.parentNode.insertBefore(printAlt, obj);
						
						
						// Escape all quotes with single quotes
						//pageTxt = pageTxt.replace(/"/g, "'");			
						
						// Convert apostrophes to ascii
						var ahrefStr = pageTxt.substring(pageTxt.indexOf("href=\"")+6, pageTxt.indexOf("\">"));
						pageTxt = pageTxt.replace(ahrefStr, ahrefStr.replace(/"/g, "'"));
						
						// Convert a href quotes to single quotes
						pageTxt = pageTxt.replace("<a href=\"", "<a href='");
						pageTxt = pageTxt.replace("<A href=\"", "<A href='"); // Because IE sucks!
						pageTxt = pageTxt.replace("\">", "'>");
						
						pageTxt = pageTxt.replace(/\+/g, "&#43;");		// Plus
						pageTxt = pageTxt.replace(/%/g, "&#37;");		// Percentage						
						pageTxt = pageTxt.replace(/&/g, "{and}");		// Ampersand
													
						if(_debug)
						{
							alert("Swftype Debug: " + pageTxt);
						}
					}
					else
					{
						var pageTxt = "DEFAULT";
					}
				}
				/* swfobject2 */
				var flashvars = {};
				flashvars.swftypeID		= "Swftype" + swftypeTag + i;
				flashvars.pageText		= pageTxt;
				flashvars.cssURL		= cssSrc;
				flashvars.tagName		= tagName;
				flashvars.hasDot		= hasDot;
				flashvars.className		= className;
				flashvars.txtWidth		= swftypeWidth;
				flashvars.txtHeight		= swftypeHeight;
				flashvars.txtSelect		= txtSelect;
				flashvars.resizeMethod	= resizeType;
				flashvars.debug 		= debug;
				flashvars.version		= 1.6;
				flashvars.swftypeURL	= "http://swftype.zeroseven.com.au/";
				var params = {};
				params.allowScriptAccess = "always";
				params.menu = "false";
				params.wmode = "transparent";
				var attributes = {};
				swfobject.embedSWF(swftypeSrc, "Swftype" + swftypeTag + i, swftypeWidth, swftypeHeight, "10", "false", flashvars, params, attributes);			
							
			}
		}
	}

}

/* Swftype Resize */
function resizeSwftype(SwftypeId, textWidth, textHeight)
{		
	//alert(textHeight);
	document.getElementById(SwftypeId).style.width = textWidth + "px";	
	document.getElementById(SwftypeId).style.height = textHeight + "px";
}

function resizeSwfTypeObject(SwftypeId,newWidth,newHeight)
{
	var flashvars = {};
	var params = {};
	params.allowScriptAccess = "always";
	params.menu = "false";
	params.wmode = "transparent";
	var attributes = {};	
	
	var objectID = document.getElementById(SwftypeId);
	if(navigator.appName.indexOf('Microsoft') != -1){
		var newUrl = objectID.movie;
	}else{
		var newUrl = objectID.data;
	}

	newUrl = newUrl.replace(/&txtWidth=.*&txtHeight/g,"&txtWidth="+newWidth+"&txtHeight");
	swfobject.embedSWF(newUrl, SwftypeId, newWidth, newHeight, "8", "false", flashvars, params, attributes);	
}

function showWarning(msg)
{
	if(_debug)
		alert("Swftype Warning: " + msg);
}

function AjaxForm() 
{	
	this.TargetId = document.getElementById(arguments[0].TargetId);
	this.TriggerId = arguments[0].TriggerId;	
	this.TriggerResendId = arguments[0].TriggerResendId;
	this.RequestUrl = arguments[0].RequestUrl;
	this.RequestType = arguments[0].RequestType;	
	this.InputFields = arguments[0].Fields;		
	this.LoadingHTML = arguments[0].LoadingHTML;
	this.ResetFields = arguments[0].ResetFields;
	this.isValid = true;
	this.RequestString = "";
	this.From = arguments[0].From;
}

AjaxForm.prototype.Call = function(type)	
{						
	xmlHttp = GetXmlHttpObject();		
	this.RequestString = "&call=" + type + "&from=" + this.From;
	
	if(type == "submit")
		this.Validate();
	
	if(this.isValid)
	{		
		xmlHttp.open(this.RequestType,this.RequestUrl,true);						
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", this.RequestString.length);
		xmlHttp.setRequestHeader("Connection", "close");		
		var self = this;

		xmlHttp.onreadystatechange = function()
		{				
			if (xmlHttp.readyState == 4)
			{			
				self.TargetId.innerHTML = xmlHttp.responseText;								
				if((type == "new") && (document.getElementById(self.TriggerId) != null)) document.getElementById(self.TriggerId).onclick = function(){self.Call('submit');return false};											
				if((type == "submit") && (document.getElementById(self.TriggerResendId) != null)) document.getElementById(self.TriggerResendId).onclick = function(){self.Call('new');return false};															
				
				var scripts = self.TargetId.getElementsByTagName('script');
				for (var i=0;i<scripts.length;i++) {
					eval(scripts[i].innerHTML);
				}
			}
			else 		
			{		
				self.TargetId.innerHTML = self.LoadingHTML;									
			}
		};		
		xmlHttp.send(this.RequestString);	
		if(this.ResetFields == "true") this.Reset();			
	}
};

AjaxForm.prototype.Reset = function()
{
	for (var i in this.InputFields)
	{		
		document.getElementById(this.InputFields[i].id).value = "";
	}
};

AjaxForm.prototype.Set = function()
{
	var self = this;
	document.getElementById(self.TriggerId).onclick = function()
	{
		self.Call('submit');return false
	};	
}
			
AjaxForm.prototype.Validate = function()
{		
	for (var i in this.InputFields)
	{
		var fieldHolder = document.getElementById(this.InputFields[i].id);
		
		if(this.InputFields[i].validate)
		{		
			if(fieldHolder.value == "")
			{
				this.isValid = false;
				addClass(fieldHolder, this.InputFields[i].errorCss);															
				
			}			
			else if(this.InputFields[i].isEmail)
			{		
				var supEmail = fieldHolder.value;
				var emLen = supEmail.length;
				var posAt = supEmail.indexOf('@')
				var posDot = supEmail.lastIndexOf('.')
				if((emLen < 7) || (posAt < 1) || (posDot <= (posAt + 1)) || (posDot >= (emLen - 1)))
				{
					this.isValid = false;
					fieldHolder.setAttribute("class", fieldHolder.getAttribute("class") + " " + this.InputFields[i].errorCss);		
				}	
				else 
				{
					this.isValid = true;
					this.RequestString += "&"+this.InputFields[i].name+"=" + fieldHolder.value;
					removeClass(fieldHolder, this.InputFields[i].errorCss);
				}
			}			
			else
			{			
				this.isValid = true;
				this.RequestString += "&"+this.InputFields[i].name+"=" + fieldHolder.value;
				removeClass(fieldHolder, this.InputFields[i].errorCss);
			}
		}
		else
		{	
			this.RequestString += "&"+this.InputFields[i].name+"=" + fieldHolder.value;
		}
	}			
}

function hasClass(ele,cls) 
{
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) 
{
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) 
{
	if (hasClass(ele,cls)) 
	{
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function fadeOut(el)
{
	var _theId = document.getElementById(el);
	var newOpacity = parseFloat(_theId.style.opacity) - 0.1;

	_theId.style.opacity = newOpacity;	
	_theId.style.filter = 'alpha(opacity=' + _theId * 100 + ')';	

	if(newOpacity > 0)
	{
		setTimeout('fadeOut("' + el + '")',80);
	}
	else
	{
		_theId.innerHTML = "";
		_theId.style.opacity = 1;	
		_theId.style.filter = 'alpha(opacity=' + 1 * 100 + ')';	
	}
}

function GetXmlHttpObject()
{
	var xmlHttp = null;	
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
