var wincounter = 0;

/* Generic Functions */

function addEvent(obj, evType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
	else {
		return false;
	}
}
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagname, strClassname){
	var arrElements = (strTagname == "*" && document.all)? document.all : 
	oElm.getElementsByTagName(strTagname);
	var arrReturnElements = new Array();
	strClassname = strClassname.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassname + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];      
		if(oRegExp.test(oElement.classname)){
			arrReturnElements.push(oElement);
		}   
	}
	return (arrReturnElements)
}

function returnObjById(id) { 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
} 
/* End Generic */


function printWindow(){
	//Create Popup Window
		
	var strOutput = document.getElementById("centreContent").innerHTML;
	var mywin = window.open("about:blank", "source" + wincounter++, "width=720,height=500,toolbar=no,location=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
		
	while (mywin == null) {
		mywin = window.open("about:blank", "source" + wincounter++, "width=720,height=500,toolbar=no,location=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
	}
		
	//reference popup's document object
	var myDoc = mywin.document;
		
	//write into popup
	myDoc.open("text/html");
	myDoc.write("<html><link rel='stylesheet' href='/_scripts.global.ampci/client/css/print.css'><body><table border='0' cellpadding='0' cellspacing='0'><tr><td>" + strOutput + "</td></tr></table></body></html>");
	myDoc.close();
	myDoc.title = document.title;
}
	
function mailToAFriend() {
    var sbj = 'Hello';
    var msgWebsite = 'I thought you might be interested in this page from AMP Capital Investors.';
    var msg = escape(msgWebsite + '\n\n' + window.location + '\n\n' + 'Regards,');
    var sbj = escape(sbj);    
    window.location = 'mailto:?subject=' + sbj + '&body=' + msg;
}

function popWin(location, name, width, height) {
	window.open (location, name, 'toolbar=no,menubar=no,scrollbars=yes,fullscreen=no,resizable=yes,width=' + width + ',height=' + height + '');
}


function openScoreborad(scName, location, pdf, name, width, height) {
	window.open (pdf, name, 'toolbar=no,menubar=no,scrollbars=yes,fullscreen=no,resizable=yes,width=' + width + ',height=' + height + '');
	location = location;
}

function openDir(form) { 
	var newIndex = form.fieldname.selectedIndex; 
	var newValue = form.fieldname.options[newIndex].value;
	switch(newValue)
	{
		case  "NSW" : alert( "please select one of the NSW stores below" ); return;
		case  "WA" : alert("please select one of the WA stores below" ); return;
		case  "NZ" : alert( "please select one of the NZ stores below" ); return;
		case  "VIC" : alert( "please select one of the VIC stores below" ); return;
		case  "QLD" : alert( "please select one of the QLD stores below" ); return;
	}
	if ( newIndex == 0 ) { 
		alert( "Please select a location!" ); 
	} else { 
		cururl = form.fieldname.options[ newIndex ].value; 
		window.open(cururl,"","" ); 
	} 
} 
