/*
* This is the common js function used by Vignette links.
* It is also inlcuded in portal
* It is also included in RightNow.
*/

function openWin(href, windowStyle, overrideParams, windowName) {

	// default the windowName to the windowStyle name if not set
	if (windowName == "" || windowName == null) {
		windowName = windowStyle;
	}

	// override params as required - for the moment only expect width and height
    
    var width = "";
    var height = "";        
	var op = new Array();
    
    if (overrideParams != null) {
    	op = overrideParams.split("_");
    	if (overrideParams.length > 0) {
    		width = op[0];
    		height = op[1];
    	}
    }

	// get params related to the windowStyle
	switch (windowStyle) {
		// these are from v6 au sites
		case "internet_Calculator"      : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_CaseStudy"       : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_Content"         : { params = "width=" + getNumericVal(770, width) + ",height=" + getNumericVal(550, height) + ",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_Form"            : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=yes,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_Glossary"        : { params = "width=" + getNumericVal(300, width) + ",height=" + getNumericVal(300, height) + ",toolbar=yes,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_PDF"             : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=yes,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_Print"           : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_Help"            : { params = "width=" + getNumericVal(676, width) + ",height=" + getNumericVal(550, height) + ",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_SecureLogin"     : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
		case "internet_FullSize"        : { params = "width=" + screen.availWidth + ",height=" + screen.availHeight + ",toolbar=no,location=no,directories=no,status=yes,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top=0,left=0"; break;}
		case "internet_FullSizeToolbar" : { params = "width=" + screen.availWidth + ",height=" + screen.availHeight + ",toolbar=yes,location=yes,directories=yes,status=yes,titlebar=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,addressbar=yes,top=0,left=0"; break;}
		
        // these are from the v6 portal sites
        case "pp_Standard"          : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=yes,location=yes,directories=no,status=yes,titlebar=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
        case "pp_Education"         : { params = "width=" + getNumericVal(603, width) + ",height=" + getNumericVal(467, height) + ",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
        case "pp_Flash"             : { params = "width=" + getNumericVal(1020, width) + ",height=" + getNumericVal(590, height) + ",fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no"; break;}
        case "pp_NULL"              : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=no,location=no,directories=no,status=yes,titlebar=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no"; break;}
        
        // global default
        default                     : { params = "width=" + getNumericVal(800, width) + ",height=" + getNumericVal(600, height) + ",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no"; }
	}

	// now open the window
	window.open(href, windowName, params);
}

function getNumericVal(defaultVal, suppliedVal) {
	var result = suppliedVal;
	if (result==""||result==null||isNaN(result)){
		result = defaultVal;
	}	
	return result;
}

//parse the body for any internal promotion links
function getIIDs() {

	try {
		var re = /iid\=([^\s\"\&]*)/gim;
		var re2 = /iid\=([^\s\"\&]*)/im;
		var html = document.body.innerHTML;
		var matches = html.match(re);
	
		var iids = "";
	
		if (matches != null) {
			for (i=0;i<matches.length;i++) {
				iids += re2.exec(matches[i])[1] + ",";
			}
		
			if (iids.length > 0) {
				iids = iids.substring(0,iids.length-1);
			}
		}
	} catch (e) {}
	
	return iids;
}

// track file download
function trackFile(atag, downloadName) {
	try {
		s.events='event1';
		s.eVar27=downloadName;
		s.linkTrackVars='eVar27,events';
        s.linkTrackEvents='event1';
		s.tl(atag,'d',downloadName);	
	} catch (e) {}
}

