var isIE = 0;
var isMac = 0;
if (navigator.appVersion.indexOf('Mac') != -1) {isMac = 1;}
if (navigator.appName.indexOf('Microsoft Internet Explorer') != -1) {isIE = 1;}

if ((isIE)&&(isMac)){
	document.write ('<style>');
	document.write('#vertical { margin-top: -65px}')
	document.write('#content_{ width: 405px; height:299px;}')
	document.write ('</style>');
}



userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);


function findElement(n,ly) {
	if (browserVers < 4)		return document[n];
	var curDoc = ly ? ly.document : document;
	var elem = curDoc[n];
	if (!elem) {
		for (var i=0;i<curDoc.layers.length;i++) {
			elem = findElement(n,curDoc.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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 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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; if ((val=val.value)!="") {
	  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
		if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
	  } else if (test!='R') { num = parseFloat(val);
		if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
		if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
		  min=test.substring(8,p); max=test.substring(p+1);
		  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


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];}
}

//blending images
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
} 


//pop up and unpop DIV
var lastobj ;
 

function popup( obj, L, T ) { 
	var el = document.getElementById(obj);
	
	if(lastobj)
	{	unpop(lastobj);}
	with( el.style ) {
		display = "block";
		position = "absolute";
		left = L;
		top = T; 
	}
	lastobj = el;
	return true;
}
function unpop( obj ) { obj.style.display = "none"; }


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function uploadwarn(pr)
{			
	window.open('uploadform.php?id='+pr,'uploadwindow','toolbar=yes,location=no,scrollbars=yes,resizable=yes,width=550,height=450');
	return false;
}

function refreshme()
{
	//document.forms[0].style.value = "refresh";
	//document.forms[0].submit();
	window.location="http://herbergerinstitute.asu.edu/alumni/virtual_mosaic/admin/edit.php?page=pics";
} 		



function limitText(limitField, limitCount, limitNum, e) {
	limitField.value = limitField.value.substring(0, limitNum);	// ensures length in case of Copy&Paste
	var obj = document.getElementById(limitCount);
	obj.innerHTML = limitNum - limitField.value.length;
	var goodkeys = new Array(8, 9, 33, 34, 35, 36, 37, 38, 39, 40, 46);
	for (i=0; i < goodkeys.length; i++) { if (e.keyCode == goodkeys[i]) return true; }	// allow delete, backspace, arrows, etc.
	if (limitField.value.length >= limitField.getAttribute("maxlength")) return false;	// if too many chars, just ignore key event
	return true;
}

function validate(form) {
  var e = form.elements;
  
  /* check if passwords the same */
  if (e['password'].value == "") 
  {
    alert('You did not enter a password.');
	return false;
  }
  if ((e['password'].length < 1) || (e['password'].length > 12)) 
  {
    alert('The password is the wrong length.');
  }
  
  if(e['password'].value != e['confirm'].value) 
  {
    alert('Your passwords do not match. Please type more carefully.');
    return false;
  }
  
  return true;
}


function UpdateProgramList(program)
{
	
	unitarray = new Array("Architecture + Landscape Architecture","Art","Art, Media + Engineering","Cross-Institute Degrees","Dance","Design Innovation","Music","Theatre and Film");
	
							 
	var programs = new Array(new Array('','Architecture Studies','Built Environment','Landscape Architecture','Housing & Community Development','Urban Design'), /*Architecture*/
					         new Array('','Art Education','Art History','Art Studies','Ceramics','Digital Art','Drawing','Fibers','Graphic Design','Intermedia','Metals','Museum Studies','Painting','Photography','Printmaking','Sculpture','Wood'), /*Art*/
					         new Array('Art, Media + Engineering'),  /*AME*/
							 new Array('','BA Arts','BA Design Studies','PhD Environmental Design & Planning'), /*Cross-Institute Degrees*/
							 new Array('Dance'), /*Dance*/
							 new Array('','BSD Graphic Design','BSD Industrial Design','BSD Interior Design','Master of Science in Design'), /*Design*/
					         new Array('','Band','Brass','Choir','Composition','Conducting','Jazz Studies','Keyboard','Lyric Opera Theatre','Music Education','Musicology','Music Therapy','Orchestra','Organ','Percussion','Strings','Theory','Voice','Woodwind'), /*Music*/
					         new Array('','Theatre','Film')); /*Theatre and Film*/							 
	
	unit = document.getElementById("selUnit").value;
	
	
	for(x=0;x<unitarray.length;x++)
	{
		if(unit == unitarray[x])
		{
			unit = x;
			break;
		}
	}
						
	document.EditForm.Program.options.length=0;
	
	CurrSel = document.EditForm.Program;
	for(x=0;x<programs[unit].length;x++)
	{
		//if(programs[unit][x] == program)
		//	CurrSel.options[CurrSel.options.length] = new Option(programs[unit][x], programs[unit][x], true, true);
		//else
			CurrSel.options[CurrSel.options.length] = new Option(programs[unit][x], programs[unit][x], false, false);
	}
	
	
	
}
function submitRegion (regionSelected)
	{
	document.EditForm.state.value = regionSelected;
	document.EditForm.submit();
	}

var LoadedImgs = 0;
	
function EnableMosaic()
{
	tbl = document.getElementById("mostable");
	tbl.style.visibility = "visible";
}



 function setOptions(chosen) {
var selbox = document.myform.opttwo;
 
selbox.options.length = 0;
if (chosen == " ") {
  selbox.options[selbox.options.length] = new Option('Please select unit first',' ');
 
}
if (chosen == "1") {
  selbox.options[selbox.options.length] = new Option('first choice - option one','oneone');
  selbox.options[selbox.options.length] = new Option('first choice - option two','onetwo');
}
if (chosen == "2") {
  selbox.options[selbox.options.length] = new Option('second choice - option one','twoone');
  selbox.options[selbox.options.length] = new Option('second choice - option two','twotwo');
}
if (chosen == "3") {
  selbox.options[selbox.options.length] = new Option('third choice - option one','threeone');
  selbox.options[selbox.options.length] = new Option('third choice - option two','threetwo');
}
}