//General Purpose image-rollover Function
function rollOver(image_name, image_location)
{
        if (document.images)
        {
                document [image_name].src = image_location;
        }
}



//General Purpose popUp Function
//usage - call from the onClick: return (#, #, 'name', 'url', 1/0, 1/0) where the last 2 parameters must be a 1 or 0.
function popUpWindow (window_width, window_height, window_name, window_url, _resizeable, _scrollbars )
{
	var options="resizable="+_resizeable+",scrollbars="+_scrollbars+",width="+window_width+",height="+window_height+"";
	popupWin=window.open(window_url, window_name, options);
	return false;
}



//Full Window (all the browser bells and whistles) popUp Function
//usage - call from the onClick: return (#, #, 'name', 'url', 1/0, 1/0) where the last 2 parameters must be a 1 or 0.
function popUpFullWindow (window_width, window_height, window_name, window_url)
{
	var options="resizable=1,scrollbars=1,toolbar=1,location=1,menubar=1,status=1,directories=1,width="+window_width+",height="+window_height+"";
	popupWin=window.open(window_url, window_name, options);
	return false;
}


//Handy email validation function
function checkEmail(checkString)
{  
    var newstr = ""; 
    var at = false;
    var dot = false;

    if (checkString.indexOf("@") != -1)
    {
      at = true;
    } 
    else if (checkString.indexOf(".") != -1)
    {
      dot = true;
    }
    for (var i = 0; i < checkString.length; i++)
    {
        ch = checkString.substring(i, i + 1)
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == "@") || (ch == ".") || (ch == "_") || (ch == "-") || (ch >= "0" && ch <= "9"))
        {
            newstr += ch;
                if (ch == "@")
                {
                    at=true;
                }
                if (ch == ".")
                {
                    dot=true;
                }
        }
    }
    if ((at == true) && (dot == true))
    {
        return true;
    }
    else
    {
        //alert ("Sorry, the email address you\nentered is not in the correct\nformat.");
        return false;
    }
}


//Function to update any class on any stylesheet
function modifyCSSClass(class_name, css_element, css_value)
{
	var rule_descriptor;
	//Insert cheap ie detector here :()
	if(document.all)
	{
		rule_descriptor = "rules";
	}
	else
	{
		rule_descriptor = "cssRules";
	}
	
	for(var n=0; n<document.styleSheets.length; n++)
	{
		for(var p=0; p<document.styleSheets[n][rule_descriptor].length; p++)
		{
			if(document.styleSheets[n][rule_descriptor][p].selectorText.toLowerCase() == class_name.toLowerCase())
			{
				document.styleSheets[n][rule_descriptor][p].style[css_element] = css_value;
			}
		}
	}
}



//To help hide email addresses from scavengers
function writeEmailAddress(user_id, domain_name)
{
	document.write("<a href=\"mailto:"+user_id+"@"+domain_name+"\">"+user_id+"@"+domain_name+"</a>")
}


//Just an alert with a specific message..must resturn false though
function friendsOnlyNote()
{
	alert("Private posts are normally hidden.\n\nYou are seeing this post because you previously\nentered my last name on a private post and have\nbeen marked as a friend.");
	return false;
}


//Just an alert with a specific message..must resturn false though
function draftNote()
{
	alert("Drafts are normally hidden.\n\nYou are seeing this post because you are logged in to the admin section right now.");
	return false;
}


//Function to popup the little scriptable calendar
function popUpCalendar(form_name, field_name)
{
	var calendar_url = "/popup_calendar.php?form_name=" + form_name + "&field_name=" + field_name;
	var random_variable = popUpWindow(220, 200, "calendar_popup", calendar_url, 0, 0);
	return false;
}



//AJAX function that turns a string into an xml parseable document
function getXMLDoc(xml_data)
{
	if(window.ActiveXObject)
	{
		//for ie
		var xml_doc=new ActiveXObject("Microsoft.XMLDOM");
		xml_doc.async="false";
		xml_doc.loadXML(xml_data);
	}
	else
	{
		//for Mozilla, Firefox, Opera, etc.
		var parser=new DOMParser();
		var xml_doc=parser.parseFromString(xml_data,"text/xml");
	}
	
	//documentElement always represents the root node so just return the root object
	var return_object = xml_doc.documentElement;
	
	return return_object;
}



//AJAX function that actually retrieves the xml from a specified url
function getXMLHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch(e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				return null;
			}
		}
	}
	return xmlHttp;
}
