/*
 * Hide e-mail from bots
 *
 * Usage: <script type="text/javascript">print_mail_to_link('info');</script>
 */
var rhs1 = "some-domain";
var rhs2 = ".com";

function print_mail_to_link( lhs ) 
{
   document.write("<a href=\"mailto");
   document.write(":" + lhs + "@");
   document.write(rhs1 + rhs2 + "\">" + lhs + "@" + rhs1 + rhs2 + "<\/a>");
}



/*
 * pops up centered window
 *
 * link example:	<a href="page.html" onClick="pop_win('page.html','','450', '250','resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no');return false;">
 * settings example: 'resizable=yes,scrollbars=yes,toolbar=yes,status=yes,menubar,location,directories'
 */
var win = null;
function pop_win( mypage, myname, w, h, features )
{
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	
	if (winl < 0)
		winl = 0;
	
	if (wint < 0)
		wint = 0;
	
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;

	win = window.open( mypage, myname, settings );
	win.window.focus();
}


// as suggested in: http://www.adobe.com/devnet/activecontent/articles/devletter.html
// example:	<script type="text/javascript">print_flash("160","399","/upload/aspectai/flash/home_animation.swf","");</script>
function print_flash(width,height,fileName,noembed)
{
   document.write('<object style="position:relative;z-index:5;" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="'+height+'" width="'+width+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">\n');
   document.write('<param value="'+fileName+'" name="Movie" />\n');
   document.write('<param value="'+fileName+'" name="Src" />\n');
   document.write('<param value="transparent" name="WMode" />\n');
   document.write('<param value="-1" name="Play" />\n');
   document.write('<param value="-1" name="Loop" />\n');
   document.write('<param value="High" name="Quality" />\n');
   document.write('<param value="-1" name="Menu" />\n');
   document.write('<param value="always" name="AllowScriptAccess" />\n');
   document.write('<param value="ShowAll" name="Scale" />\n');
   document.write('<param value="0" name="DeviceFont" />\n');
   document.write('<param value="0" name="EmbedMovie" />\n');
   document.write('<param value="#ffffff" name="BGColor" />\n');
   document.write('<param value="1" name="SeamlessTabbing" />\n');
   document.write('<param value="0" name="Profile" />\n');
   document.write('<param value="0" name="ProfilePort" /><embed src="'+fileName+'" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"><noembed>'+noembed+'</noembed></embed></object>\n');
}


/*
 * Form validation:
 * http://www.webcheatsheet.com/javascript/form_validation.php
 */
function validateFormOnSubmit(theForm) {
	var reason = "";
//	reason += validateEmpty(theForm.first_name,'first name');
//	reason += validateEmpty(theForm.last_name,'last name');
//	reason += validatePhone(theForm.phone);
//	reason += validateEmail(theForm.email);

	var elem = document.getElementById('workshopSelection');
	if (!theForm.item_name.checked)
	{
		elem.style.background = '#FFEB94';
        reason += "Please select one of the workshops.\n";
	} else {
		elem.style.background = '#FFF';
	}

	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
		return false;
	} else {

		//
		// set the custom field text
		//
		var txt = "";
		txt += "School Name: "+theForm.school_name.value+" ___ \n";
		txt += "School District: "+theForm.school_district.value+" ___ \n";
		txt += "School Address: "+theForm.school_address.value+" ___ \n";
		txt += "Grade Level :"+theForm.grade_level.value+" ___ \n";
		txt += "Participants Names: "+theForm.participants.value+"\n";
		theForm.custom.value = txt;
	}

	return true;
}

function validateForm2OnSubmit(theForm) {
	var reason = "";
	reason += validateEmpty(theForm.fullname,'full name');
	reason += validateEmail(theForm.email);
	reason += validateEmpty(theForm.suggestion,'suggestion');

	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
		return false;
	}

	return true;
}

function validateEmpty(fld,txt) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = '#FFEB94'; 
        error = "Please enter your "+txt+".\n"
    } else {
        fld.style.background = '#ffffff';
    }
    return error;   
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = '#FFEB94';
        error = "Please enter your email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFEB94';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFEB94';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = '#ffffff';
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = "Please enter a phone number.\n";
        fld.style.background = '#FFEB94';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = '#FFEB94';
    } else {
        fld.style.background = '#ffffff';
    }
    return error;
}



/*
 * Image preloader
 */
/*
var myimages=new Array();
function preloadimages()
{
for (i=0;i<preloadimages.arguments.length;i++)
	{
	myimages[i]=new Image();
	myimages[i].src=preloadimages.arguments[i];
	}
}

//
// calling the function - make sure baseDir is defined before general.js
//
preloadimages(baseDir+'imgs/image1.gif',baseDir+'imgs/image2.gif');
*/

//
// Adobe Dreamweaver CS3 Image Rollover
//
/*
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 MM_findObj(n, d) { //v4.01
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);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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_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];}
}
*/

