// write flash objects
function flash(file,height,width,vars){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+file+'">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+file+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="FlashVars" value="vars='+file+'&vars='+vars+'" />');
	document.write('<embed src="'+file+'" FlashVars="vars='+file+'&vars='+vars+'" quality="high" width="'+width+'" height="'+height+'" name="'+file+'" wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

// make us your homepage
function homepage() {
	if(window.showModalDialog){
		document.write('<a href="javascript:history.go(0);" onclick="this.style.behavior=\'url(#default#homepage)\';this.setHomePage(\'http://www.globegazette.com\');">');
		document.write('Make us your Homepage</a>');
	} else {
		document.write('<a href="http://www.globegazette.com">Make us your Homepage</a>');
	}
}

// pop up windows
function popUp(url,scrollbars,height,width){
	window.open(url.href, 'child', 'scrollbars='+scrollbars+',width='+width+',height='+height+'');
}

// array shuffle
Array.prototype.shuffle = function(times){
	var i,j,t,l = this.length;
	while(times--)	{
		with(Math)	{
			i = floor(random()*l);
			j = floor(random()*l);
		}
		t = this[i];
		this[i] = this[j];
		this[j] = t;
	}
	return this;
}

// simpleblog character limit
function char_count(textEl,countEl,limit){
	if(textEl.value.length > limit){
		textEl.value = textEl.value.substring(0, limit);
	} else {
		countEl.value = limit - textEl.value.length;
	}
}

// cookie functions
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


// set preffered font size
function fontSize(size){
	document.getElementById('fontSize').className = size;
	createCookie("style", size, 365);
	if(size=='large'){
		document.getElementById('default').className='';
		document.getElementById('large').className='selected_large';
	} else {
		document.getElementById('large').className='';
		document.getElementById('default').className='selected_default';
	}
}

function vMixPlayerThumbs(token,id,desc){
	var player = '<embed src="http://media.vmixcore.com/player/'+token+'/player.swf" width="320" height="256" FlashVars="auto_play=true&token='+token+'&dev_url=http://media.vmixcore.com/vmixcore"/>';
	var txt = desc;
	txt += ' <a href="http://videos.qctimes.com/p/video?id='+id+'" target="_blank">Full Video</a>';
	document.getElementById('vmp').innerHTML = player;
	document.getElementById('vmd').innerHTML = txt;
}

//window.onload = function(e){
//	if(document.getElementById('fontSize')){
//		var cookie = readCookie("style");
//		document.getElementById('fontSize').className = cookie;
//		if(cookie=='large'){
//			document.getElementById('large').className='selected_large';
//		} else {
//			document.getElementById('default').className='selected_default';
//		}
//	}
//}

/*
Copyright 2005, 4word systems
All rights reserved.
This software may not be reproduced or distributed in any form without the express 
written consent of 4word systems or it's designee.
Revision 1.1:  20050729 Added underscore to list of valid characters
*/
function validateEmail(email,required) {
	alert("1 '"+email+"'");
	var c=email.length;
	alert(c);
	if (required==undefined) {   // if not specified, assume it's required
		required=true;
	}
	if (email==null) {
		if (required) {
			return false;
		}
		return true;
	}
	alert("2 '"+email+"'");
	var c=email.length;
	alert(c);
	if (email.length<=6) {
		if (required) {
			return false;
		}
	}
	alert("got here c");
	if (! allValidChars(email)) {  // check to make sure all characters are valid
		return false;
	}
	alert("got here d");
	alert("length="+email.length);
	if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
		return false;
	} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
		return false;
	} else if (email.indexOf("@") == (email.length-1)) {  // @ must not be the last character
		return false;
	} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		return false;
	} else if (email.indexOf(".") == (email.length-1)) {  // . must not be the last character
		return false;
	} else if (email.indexOf(".") == (email.length-2)) {  // . must not be the 2nd to last character
		return false;
	}
	return true;
}

function allValidChars(email) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}
