
//A simple debug function
//Throws an error to the js console
function debug(aMsg) {
	setTimeout(function() { throw new Error(aMsg); }, 0);
}

//Image swap code
//Set the following attributes on the image tag
//	onload = "MS(this);"
//	oversrc = "<over state of image>"
function MS_swap(Mitem,Mtype){
  Mitem.src=Mitem.getAttribute(Mtype || "origsrc");
}

function MS(img_swap){
	img_swap.setAttribute("origsrc",img_swap.src);
	img_swap.setAttribute("onload", "");
   	img_swap.oversrc_img = new Image();
  	img_swap.oversrc_img.src=img_swap.getAttribute("oversrc");
    img_swap.onmouseover = new Function("MS_swap(this,'oversrc');");
    img_swap.onmouseout = new Function("MS_swap(this);");
	img_swap.style.cursor = 'pointer';
}

function M_object(obj){
	if (document.getElementById)
		return document.getElementById(obj)
	else if (document.all)
		return document.all[obj]
}
//End image swap

//swap add remove and check to see if a css class is added to an object
//fe_css('swap',objectname,'class1','class2')
//Parameters:
//	a 			- 'swap', 'add', 'remove', 'check'
//	objectname 	- can be the object name in string form or this
//	class1		- css class name
//	class2		- css class name
function fe_css(a,m,c1,c2) {
	var o =  new fe_getobj(m);

	//Added By Wes 9/7
	if(!o.className){ o = m; }
	
	switch (a){
		case 'swap':
			o.className=!fe_css('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
		case 'add':
			if(!fe_css('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
			break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;
	}
}

//Get Object
//Should be used for all object fetching
function fe_getobj(obj) {
	if (document.getElementById)
		return document.getElementById(obj)
	else if (document.all)
		return document.all[obj]
}

//Decodes the addresses coded by ASP function EncodeEmail and open a mailto link
function sendEmail(address, linkto) {
   	var aryAddress = new Array
   	var mailTo = new String;
   	address = address.replace(/x/g, ',64');address = address.replace(/y/g, ',46');address = address.replace(/z/g, ',');
   	aryAddress = address.split(',') 
   	for (q=1; q<aryAddress.length;q++) {  
		mailTo = mailTo + String.fromCharCode(aryAddress[q]);   
	}
	linkto.href = 'mailto:'+mailTo;
} 


//Podium MML OPEN
function openMML(consoleid, galleryid, mediaid, mediatype) {
	var pGallery = (galleryid > 0)?'&gallery_id=' + galleryid:'';
	var pMedia = (mediaid > 0)?'&mediatype=' + mediatype +'&mediaid=' + mediaid:'';
	window.open('/podium/MediaLibrary/player/default.aspx?console_id=' + consoleid + pGallery + pMedia + '&browse=yes&recent=yes', '_blank', 'location=no, menubar=no, scrollbar=no, status=no, resizable=no, height=497, width=700');
}

//Submit Form from Select statment		
function jump(f) {
	f.submit();
}

//Check for added variable to podium url
function CheckForID(VarType) {
	var beginValue,mylocation,MyID,FoundAnd
	mylocation = new String(parent.window.location);
	beginValue = mylocation.search(VarType);
	if(beginValue > 0){
		MyID = mylocation.substring(beginValue+VarType.length+1,mylocation.length);
		FoundAnd = MyID.search("&");
		if(FoundAnd > 0){
			MyID = MyID.substring(0,FoundAnd);
		}
	}
	if(MyID == null){
		return 0;
	}
	else{
		return MyID;
	}
}

// Mimics podium page loading
function __pdL(taskid, taskname, tasktypeid, taskargs, path, clearhistory, subtaskid, subtaskname) {
	parent.window.location = "/podium/default.aspx?t=" + taskid;
}

//
function ReSizeIFRAME() {
	var aIF = window.parent.document.getElementsByTagName('IFRAME')
	var objIF
	for (x=0; x<aIF.length;x++) {
		if(aIF[x].id.substring(0,2) == 'if') objIF = aIF[x]
	}
	var objBody = document.getElementById('__pdIFRAMEarea') 
	objIF.style.height = objBody.offsetHeight;
}

//finds the Y screen position of the given object
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}