/*

GZIP CONTENT DELIVERY
Copyright 2010 Fat Publisher

All rights reserved. Republication, redistribution,
replication or use of Fat Publisher content / scripting
is strictly prohibited without the prior written consent of Fat Publisher.

www.fatpublisher.com.au

Content generated : 12:39:01 pm 09 September 2010

*/

var onload_events = new Array();

function dom_id(elmnt)
{
	return document.getElementById(elmnt);
}

function dom_by_tag(tag)
{
	return document.getElementsByTagName(tag);
}

// jump to next box 
function auto_focus_next(obj, formname)
{
	if (obj.value.length ==4) {
		var f = document.forms[formname];
		var match = obj.name.match(/([a-z_]*)\[([0-9]*)\]/i);
		var next = f.elements[match[1] + "[" + (parseInt(match[2]) + 1) + "]"];
		if (next) {
			next.onkeyup = new Function("auto_focus_next(this, '" + formname + "')");
			next.focus();
		}
	}
}

function add_to_onload(event)
{
	onload_events.push(event);
	window.onload = function() { 
		for (var x = 0; x < onload_events.length; x ++) {
			eval(onload_events[x]);
		}
	}
}

// returns the elements position on the document
function get_position(obj, type)
{
	var retval = 0;

	if (type == "Left" && obj.x) {
		return obj.x;
	}
	else if (obj.y) {
		return obj.y;
	}
	else {
		while (obj.offsetParent) {
			if (obj && obj.style && obj.style.position) obj.style.position = "relative";
			retval += eval("obj.offset" + type);
			obj = obj.offsetParent;
		}
		return retval;
	}
}

function setup_displayed_elements(item)
{
	switch (item) {

		// step through links and remove the href if we can use js to display stuff
		case "login" :
			var as = dom_by_tag("a");
			for (var m = 0; m < as.length; m ++) {
				if (as[m].onclick && String(as[m].onclick).search(/toggle_element_displays/i) != -1) {
					// remove href from this item as we want to use js to display it
					as[m].href = "#";
				}
			}
		break;
	}
}

function toggle_element_displays(show, hide, obj)
{
	var args = arguments;
	for (var i = 0; i < args.length; i ++) {
		if (args[i] && typeof(args[i]) == "object" && args[i].length) {
			for (var x = 0; x < args[i].length; x ++) {
				dom_id(args[i][x]).style.display = (i == 0) ? "" : "none";
			}
		}
	}
	if (obj) {
		obj.blur();
	}
}

function add_button_overs()
{
	var inps = document.getElementsByTagName("INPUT");
	for (var c = 0; c < inps.length; c ++) {
		var match = inps[c].className.match(/button/);
		if (match) {
			switch (inps[c].getAttribute("type")) {
				case "submit" : case "button" :
					inps[c].onmouseover = function() {
						var cn = this.className;
						cn = cn.replace(/button/, "");
						var parts = cn.split(" ");
						for (var w = 0; w < parts.length; w ++) {
							parts[w] = parts[w] + "_over";
						}
						this.className = "button " + parts.join(" ");
					}
					inps[c].onmouseout = function() {
						this.className = this.className.replace(/_over/g, "");
					}
				break;

				case "image" :

				break;

			}
			
		}
	}

	var others = new Array("vc_continue_submit", "do_purchase", "customer_information_submit", "vc_checkout_submit", "vc_continue_to_payment_submit", "vc_alter_submit", "payment_form_submit");
	for (var q = 0; q < others.length; q ++) {
		if (inps[others[q]]) {
			inps[others[q]].onmouseover = function() {
				this.src = this.src.replace(/(\.[a-z]{3})$/, "_over$1");
			}
			inps[others[q]].onmouseout = function() {
				this.src = this.src.replace(/_over/, "");
			}
		}
	}
}

function add_popups()
{
	var lnks = document.getElementsByTagName("A");
	for (var x = 0; x < lnks.length; x ++) {
		var rel = lnks[x].getAttribute("rel");
		if (rel && rel.search(/^popup/) != -1) {
			lnks[x].onclick = function() {
				var pstr = this.getAttribute("rel").replace(/^popup_?/, "");
				window.open(this.href, "", pstr);
				return false;
			}
		}
	}
}

add_to_onload("add_popups()");
add_to_onload("add_button_overs()");