//file: includes/commonJSScripts.js

/* ************************************************************************************** */

function changeCursor(inOut,curSpan) {
    switch (inOut) {
        case "in"  : eval("document.all." + curSpan + ".style.cursor = 'hand'"); break;
        case "out" : eval("document.all." + curSpan + ".style.cursor = 'pointer'"); break;
    }
}

/* ************************************************************************************** */

var curPic = 1;
function showPic(picName) {
	if (picName == "prev") {
		curPic--;
		if (curPic == 0) curPic = 16;
	} else {
		curPic++;
		if (curPic == 17) curPic = 1;
	}
		
	if (curPic <= 10) {
		document.all.btsSpacer.width 	= 70;
		document.all.btsPic.width		= 200;
		document.all.btsPic.height		= 150;
		document.all.btsPic.src			= "images/ammw_" + curPic + ".jpg";
	} else {
		document.all.btsSpacer.width 	= 125;
		document.all.btsPic.width		= 113;
		document.all.btsPic.height		= 150;
		document.all.btsPic.src			= "images/ammw_" + curPic + ".jpg";
	}
}

/* ************************************************************************************** */

var count = 0;
function showLayer(layerName) {
	switch(layerName) {
		case "acc" : curStyle = document.all.accLayer.style.display;
					 if (curStyle == "inline") {
						 document.all.accLayer.style.display = "none";
					 } else {
						 document.all.accLayer.style.display = "inline";
					 }
					 break;
		case "pic" : curStyle = document.all.picLayer.style.display;
					 if (curStyle == "inline") {
						 document.all.picLayer.style.display = "none";
					 } else {
						 document.all.picLayer.style.display = "inline";
					 }break;
	}
}

/* ************************************************************************************** */

function checkData() {
    var email   = contactWilliam.emailAddress.value;
    var name    = contactWilliam.name.value;
    var nameValid, emailValid = false;
    
    if (name == "") {
        alert("You forgot to enter your name.");
    } else if (email == "") {
        alert("You forgot to enter your e-mail address.");
    } else {
        nameValid = true;
    }
    
    if (email != "") {
        if (!validateEmail(email)) {
            alert("Your e-mail address appears to be invalid.  Please correct it before continuing.");
        } else {
            emailValid = true;
        }
    }
    
    if ((nameValid) && (emailValid)) {
        contactWilliam.submit();
        alert("Thank you!  Your e-mail has been sent.");
    }
}

/* ************************************************************************************** */

function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
var objRegExp  = /(^[a-z]([a-z_\.-]*)@([a-z_\.-]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.-]*)@([a-z_\.-]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}

/* ************************************************************************************** */

function loadPages(sectionName) {
    switch (sectionName) {
        case "snapshots" : document.all.topPage.src    = "snapshots/snapTop.html";
                           document.all.bottomPage.src = "snapshots/snapBottom.html";
                           break;
        case "resume"    : document.all.topPage.src    = "resume/resumeTop.html";
                           document.all.bottomPage.src = "resume/resumeBottom.html";
                           break;
        case "theatre"   : parent.document.all.bottomPage.src = "resume/theatre.html";
                           break;
        case "film"      : parent.document.all.bottomPage.src = "resume/film.html";
                           break;
        case "television": parent.document.all.bottomPage.src = "resume/television.html";
                           break;
        case "training"  : parent.document.all.bottomPage.src = "resume/training.html";
                           break;
        case "skills"    : parent.document.all.bottomPage.src = "resume/skills.html";
                           break;
        case "bio"       : document.all.topPage.src    = "bioTop.html";
                           document.all.bottomPage.src = "bioBottom.html";
                           break;
        case "contact"   : document.all.topPage.src    = "contactTop.html";
                           document.all.bottomPage.src = "contactBottom.html";
                           break;
        case "oncamera"  : document.all.topPage.src    = "onCamera/onCameraTop.html";
                           document.all.bottomPage.src = "onCamera/onCameraBottom.html";
                           break;
        case "home"      : document.all.topPage.src    = "blank.html";
                           document.all.bottomPage.src = "blank.html"; 
                           break;
    }
}

/* ************************************************************************************** */

function resetForm() {
    contactWilliam.name.value           = "";
    contactWilliam.emailAddress.value   = "";
    contactWilliam.comment.value        = "";
}

/* ************************************************************************************** */

function showMenuHdr(sectionName) {
    switch (sectionName) {
        case "oncamera"    : document.all.titleBarRight.innerHTML = "on camera"; break;
        case "snapshots"   : document.all.titleBarRight.innerHTML = "snap shots"; break;
        case "soundbytes"  : document.all.titleBarRight.innerHTML = "sound bytes"; break;
        case "resume"      : document.all.titleBarRight.innerHTML = "resume"; break;
        case "bio"         : document.all.titleBarRight.innerHTML = "bio"; break;
        case "contact"     : document.all.titleBarRight.innerHTML = "contact"; break;
        case "home"        : document.all.titleBarRight.innerHTML = "<img src='images/spacer.gif' width='40' height='0' border='0'>"; break;
    }
}

/* ************************************************************************************** */

function showImage(imgNum) {
    var newImg      = "<img src='images/full/" + imgNum + "' width='150' height='224' border='0'>";
    var imgDispArea = "<img src='images/spacer.gif' width='15' height='0' border='0'>" + newImg;
    
    if (imgNum != "blank") {
        parent.frames.document.all.bottomLeftCell.innerHTML = imgDispArea;
    } else {
        parent.frames.document.all.bottomLeftCell.innerHTML = "&nbsp;";
    }
}

/* ************************************************************************************** */

function loadVideo(video) {
    switch (video) {
        //case "reelAct"      : window.open("http://www.reelact.com/userPages/viewVideo.php?id=517",'reelACT','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=480,height=380'); break;
        case "reelAct"      : parent.frames.document.all.bottomPage.src = "onCamera/reelAct.html";
                              parent.frames.document.all.bottomLeftCell.innerHTML = "<br><br> ReelACT"; break;
        case "boyWillie"    : parent.frames.document.all.bottomPage.src = "onCamera/pianoLesson.html";
                              parent.frames.document.all.bottomLeftCell.innerHTML = "<br><br><br> Boy Willie <br> 'Piano Lesson'"; break;
        case "kadi"         : parent.frames.document.all.bottomPage.src = "onCamera/visualAspirations.html";
                              parent.frames.document.all.bottomLeftCell.innerHTML = "<br><br><br> Kadi <br> 'Visual Aspirations'"; break;
    }
}

/* ************************************************************************************** */

function gatherInfo(){
	var F=document.contactWilliam;
	document.location=MailtoStr(F.name.value,F.comment.value);
}

/* ************************************************************************************** */

function MailtoStr(name,comment){
	var S="mailto:contactWilliam@williamathomas.com?";
	bPairAdded=false;
	S+=MaybeNameValue("subject","E-mail From williamathomas.com",true);
	S+=MaybeNameValue("body",comment,true);
	return S;
}
/* ************************************************************************************** */

function MaybeNameValue(strName,strValue,bEscape){
	var S="";
	if(strValue.length>0){
		if(bPairAdded)
			S+="&";
		if(bEscape!=null && bEscape)
			S+=strName+"="+escape(strValue);
		else
			S+=strName+"="+strValue;
		bPairAdded=true;
	}
	return S;
}

/* ************************************************************************************** */