/* *********************************************************** 
 *	FUNCTION:	insertQTMovie
 *	PURPOSE: 	allows us to insert a QT movie in IE
 * ********************************************************* */
function insertQTMovie(QTfilename) {
	
	document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0">\n');
	document.write('<param name="src" value="http://www.orum.com/funstuff/' + QTfilename + '" />\n');
	document.write('<param name="autoplay" value="true" />\n');
	document.write('<embed src="http://www.orum.com/funstuff/' + QTfilename + '" pluginspage="http://www.apple.com/quicktime/download/" align="middle" autoplay="true" bgcolor="white" ></embed>\n');
	document.write('</object>\n');
	
}

function alertgoob(){
alert('goober1');
}

/* *********************************************************** 
 *	FUNCTION:  valildateForm
 *	PURPOSE: validateForm input
 * ********************************************************* */
var bad_char_errors = new Array();
var errors = new Array();

function validateForm(form) {
	var f = form;
	
	var errdiv = document.getElementById("errmsg");
	
	var form_elements = new Array();

	form_elements = [['author','Name'],
					 					 ['email','Email'],
					 					 ['url','URL'],
					 					 ['comment','Comment']];
	
	for ( i = 0; i < form_elements.length; i++ ) {
		if ( document.getElementById(form_elements[i][0]) ) {
			var e = eval('f.' + form_elements[i][0] + '.value');
			
			if (!e) {
				errors.push('<p>&middot; '+form_elements[i][1]+' is required</p>');
				document.getElementById(form_elements[i][0]).className= "highlight";
			} else {
				if (form_elements[i][1] == "Email") { //verify email address
					if (! chk_email(e)) {
						document.getElementById(form_elements[i][0]).className= "highlight";
					} else {
						document.getElementById(form_elements[i][0]).className= "";
					}
				
				} else {
					document.getElementById(form_elements[i][0]).className= ""; //clear class="HIGHLIGHT" retained from non reload
				}
			}
		}
	}

	if (errors[0] || bad_char_errors[0]) {
		errdiv.style.display = "block";
		errdiv.innerHTML = '<h3>Ack! Errors!</h3>';
		if (errors[0]) {
			for( j = 0; j < errors.length; j++ ) {
				errdiv.innerHTML += errors[j]
			}
		}
		
		if (bad_char_errors[0]) {
			for( x = 0; x < bad_char_errors.length; x++ ) {
				errdiv.innerHTML += bad_char_errors[x]
			}
		}
		errors.length = 0;
		bad_char_errors.length = 0;
		return false;
		
	} else if (!errors[0] && !bad_char_errors[0]){
		errdiv.style.display = "none";
		//f.submit();
		return true;
		
	}

}
/* *********************************************************** 
 *	FUNCTION:  chk_email, chk_badchar
 *	PURPOSE: legacy functions for form validation
 * ********************************************************* */
function chk_email(obj) {
	var bad_email_chars = "`/ (){}[]|<>/,&+=*'%?!~#^:;";
 
 	// check for spl characters that are invalid
 	if (!chk_badchar(obj, bad_email_chars)) {
		bad_char_errors.push('<p>&middot; Email address contains illegal characters</p>');
 		return false;
 	}
	
	// Check for an @ sign
 	var at_sign = obj.indexOf("@");
 	if (at_sign < 0) {
		bad_char_errors.push('<p>&middot; Email address is missing the \'@\' sign</p>');
 		return false;
 	}
    return true;
}


function chk_badchar(word, badchars) {
	var found = -1; // bad char not found
   
 	for (var i = 0; i < badchars.length; i++) {
  		found = word.indexOf(badchars.charAt(i));
  		if (found > -1) {
   			break;  // exit from for loop
  		}
 	}

 	if (found > -1)	return false;
 	else return true;
}
/* *********************************************************** 
 *	FUNCTION:	externalLinks
 *	PURPOSE: 	make external links open in new windows
 * **********************************************************/

function getDomain(url) {
	
	if (!url.match(/^.*:\/\//)) return '';
	url = url.replace('www.','');
	return url.replace(/^.*\/\/(.*@)?|\?.*$|:.*$|\/.*$/g, '');
}
function isExternal(url) {
	
	if (url == null) return false; // Any scope
	if (getDomain(url) == '') return false;
	return getDomain(location.href) != getDomain(url);
}

function externalLinks() {
	if (document.getElementsByTagName){
	
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if(isExternal(anchor.getAttribute("href"))){
				anchor.target = "_blank";
				var nestedImages = anchor.getElementsByTagName("img");
				if (nestedImages[0]) {
					anchor.className = "imageLink"; 
				}
				else { 
					anchor.className = "external";
				}
				
			}
			
		}
	}
}

window.onload = externalLinks;