// Utility functions

function formHandler(form){ 
	var URL = document.form.MonthCheck.options[document.form.MonthCheck.selectedIndex].value; 
	document.getElementById("Calendar").src = URL; 
} 

function toggleit() {
	var doc=document.getElementById("Menu");
	doc.style.display=(doc.style.display=='inline')?'none':'inline';
	return false;
}

function getObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getObject

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility


function changeObjectDisplay(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.display = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectDisplay


function submit() {
	document.form.submit()
}


// Popup window
var popupwin = null;
function popup(url,props) {
	if (!props) props = "width=300,height=100,scrollbars=no,resizable=no,menubar=no,statusbar=no";
	popupwin = window.open(url,"popupwin",props);
	return false;
}

var popupwinA = null;
function popupA(url,props) {
	if (!props) props = "width=730,height=600,scrollbars=yes,resizable=yes,menubar=yes,statusbar=yes";
	popupwinA = window.open(url,"popupwinA",props);
	return false;
	
	
	
}


// Declarations
var Link_Account;
var Link_Checkout;

function parseGetVars() {
	//alert(document.referrer)
	var getVars = new Array();
	var qString = unescape(top.location.search.substring((document.referrer)));
	var pairs = qString.split(/\&/);
	for (var i in pairs) {
		var nameVal = pairs[i].split(/\=/);
		if (nameVal[1] == "LOGN") {
			//Link Screen=acnt
		//location.href = 'http://www.powertale.com/Merchant2/merchant.mv?Screen=ACNT&Order=1&Store_Code=PDI';
		}
	}	
}


// Declarations
var btnAccount;
var srcMivaAccount = "btn_InsideAccount.gif"; 

function copyMivaLinks() {
	// Get reference to our links
	btnAccount = document.getElementById("hrefAccount");

	// Get starting cell and move down to navigation cell
	var tdStart = document.getElementById("tdMiva");
	tdStart = moveToTag(tdStart,'TABLE');
	tdStart = moveToTag(tdStart,'TBODY');
	tdStart = moveToTag(tdStart,'TR');
	tdStart = moveToTag(tdStart,'TD');
	tdStart = moveToTag(tdStart,'TABLE');
	tdStart = moveToTag(tdStart,'TBODY');
	tdStart = moveToTag(tdStart,'TR');
	recurseThroughCell(tdStart);

	// Hide parent
	tdStart.style.display = 'none';
}

function moveToTag(obj,tag) {
	for (i=0;i<obj.childNodes.length;i++) if (obj.childNodes[i].tagName==tag) return obj.childNodes[i];
}

function recurseThroughCell(obj) {
	// If this has children, recurse
	for (var i=0;i<obj.childNodes.length;i++) recurseThroughCell(obj.childNodes[i]);
	// Check this item
	if (obj.tagName=='IMG' && obj.src.indexOf(srcMivaAccount)>-1)
		btnAccount.href = obj.parentNode.href;
}

