// action to be taken when image is selected in admin console
function GetFileName(filename, dest) {

	var string = filename;
    var separator = '';
	
	if(filename.charAt(0) == "/") 
		separator = '/';
	else 
		separator = '\\';
    
    var stringArray = string.split(separator);
    dest.value = stringArray[stringArray.length-1];
}

function ToggleDisplay(objName) {
	if(!objName) return false;
	var oObj = document.getElementById(objName);
	
	if(oObj == null) return(false);
		
	oObj.style.display = (oObj.style.display == 'none') ? "block" : "none" ;
}

function ChangeObjectValue(strNone, strBlock, strSoure, oTarget) {
	var oSource = document.getElementById(strSoure);
	if(oSource == null) return(false);
		
	oTarget.value = (oSource.style.display == 'none') ?  strNone : strBlock;
}

/* ============================ /contact.php ============================ */

// Used to validate form in contact.php
function ValidateContactForm() {
	// init vars
	var err = "";
	
	var oName = document.frm.cname;
	var oEmail = document.frm.cemail;
	var oComments = document.frm.ccomments;
	

	if(oName.value == "") { err +="- Name can not be empty\n"; }
	if(oEmail.value=="") { err += "- Email can not be empty\n"; }
	if(oComments.value=="") { err += "- Comments can not be empty\n"; }
	
	if(err.length == 0) {
		// no errors found
		// ensure that email has proper formay
		result = IsValidEmail(oEmail.value);
		if(result) {
			return(true);
		}
		err += "-Email does not have a proper format";
	}
	err = "Errors found in form:\n"+err;
	alert(err);
	return(false);
}

function IsValidEmail(strEmail) {
   if (strEmail == "" || strEmail.indexOf ('@', 1) == -1 || strEmail.indexOf ('.', 3) == -1) 
      return (false);
   else
      return (true);
}

function OpenBio(id) {
	var wnCast = window.open('cast_bio.php?id='+id, 'castbio', 'height=350,width=450,resizable=yes,toolbar=no,scrollbars=yes');
	wnCast.focus();
}

function OpenWindow(strUrl) {
	var wnWnd = window.open(strUrl, 'wnd', 'height=350,width=450,resizable=yes,toolbar=no,scrollbars=yes');
	wnWnd.focus();
}

function OpenMedia(strUrl, strTitle) {
	window.open("media_player.php?url="+strUrl+"&title="+strTitle,"mediaplayer","width=350,height=335");
}

function OpenMediaPic(id, gallery) {
	var oWnd = window.open("media_viewer.php?id="+id+"&gallery="+gallery,"gallery_image","width=600,height=500,resizable=yes,scrollbars=yes");
	oWnd.focus();
}

// preload images when document loads
function PreloadImages() {
	var arrImages = new Array(
					   "images/redhours_01.gif", 
					   "images/redhours_02.gif", 
					   "images/redhours_04.gif", 
					   "images/redhours_05.gif", 
					   "images/redhours_sub.png"
					);
  document.imageArray = new Array(arrImages.length);

  for(var i=0; i<arrImages.length; i++) {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = arrImages[i];
  }
}