//General Image Swap, Popups Scripts

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function popUp(strURL,strType,strHeight,strWidth) {
 var strOptions="";
 if (strType=="console") strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;
 if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
 if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
 window.open(strURL, 'newWin', strOptions);
}

function change(div,message)	{
	document.getElementById(div).innerHTML = message;
}

//Typewriter Script

var delay=50;
var currentChar=1;
var destination="biography_content";
function type()
{
	//if (document.all)
	{
		var dest=document.getElementById(destination);
		if (dest)// && dest.innerHTML)
		{
			dest.innerHTML=text.substr(0, currentChar)+"_";
			currentChar++;
			if (currentChar>text.length)
			{
				//currentChar=1;
				//setTimeout("type()", 5000);
				clearTimeout(typer);
			}	
			else
			{
				typer=setTimeout("type()", delay);
			}
		}
	}
}

function startTyping(textParam, delayParam, destinationParam)
{
	text=textParam;
	delay=delayParam;
	currentChar=1;
	destination=destinationParam;
	type();
}




// Typewriter Script

var mIndex = 0;
var nIndex = 0;
var pauseInterval;
var nInterval;
// constants
var WRAP = true;			//change to false to stop wrapping
var PAUSE = true;			// change to false to stop the pause
var PAUSE_INTERVAL=1000;		// millisecond value for pause between strings
var DISPLAY_INTERVAL = 10;		// millisecond value for rate of display on individual characters.
function displayText() {
	if(nIndex<=mString[mIndex].length) {
		if(mString[mIndex].charAt(nIndex) == " ")
			document.getElementById("biography_content").innerHTML = document.getElementById("biography_content").innerHTML + " ";
		else
			document.getElementById("biography_content").innerHTML+=mString[mIndex].charAt(nIndex);
			//alert(document.getElementById("biography_content").innerHTML);
		nIndex++;
	} else {
		nIndex=0;
		if(PAUSE) {
			clearInterval(nInterval);
			pauseInterval = setTimeout("dummyFunction()",PAUSE_INTERVAL);
		} 
		if(WRAP)
			document.getElementById("biography_content").innerHTML+="<p>"
		//if(mIndex < mString.length-1)	
		mIndex++;
	}
}

function dummyFunction() {
	clearInterval(pauseInterval);
	if(mIndex==0 || !WRAP)
		document.getElementById("biography_content").innerHTML = "";
	startInterval();
}

function startInterval() {
	if(mIndex == mString.length)	{
		clearInterval(nInterval);
		return;	
	}
	else
		nInterval = setInterval("displayText()",DISPLAY_INTERVAL);
}



//Form Checking Scripts

function isEmail (s)
{   
 
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function checkEmail(value,message)
{
  if (!isEmail(value))
    {
      alert(message)
      return false;
    }  

  return true;
}

function verify_email(form) {

  if (!checkEmail(document.forms[form].email.value,'{pw.lang.email_error}')) {
	return false;			
  }
}

function verify_email_key(e) {
  if (!e) var e = window.event;
  if (e.keyCode) code = e.keyCode;
  else if (e.which) code = e.which;

  if (code==13) {
	return verify_email();
  }
}

function verify_form(form) 
{
	if (document.forms[form].fullname.value.length==0) 
	{
		alert("Oops, you forgot to fill in your name!");
		return false;
	}
	if (document.forms[form].email.value.length==0) 
	{
		alert("Oops, you forgot to fill in your email address!");
		return false;
	}
	if (!verifyEmail(document.forms[form].email.value)) 
	{
		alert("Your email address doesn't seem right.  Please enter a valid email address.");
		return false;			
	}
	if (!checkNum(document.forms[form].handphone.value)) 
	{
		alert("You have entered an invalid phone number.  Please enter a valid phone number.");
		return false;			
	}
	else
		return true;
}

