var MENU_FOCUSED = false;
var MENU_NAME = '';

IE4 = (document.all) ? 1 : 0;       // browser is Internet Explorer 4
NS4 = (document.layers) ? 1 : 0;    // browser is Netscape 4

ver4 = (IE4 || NS4) ? 1 : 0;  // know that we have version 4 browser
                              // this will be required for non-dhtml browsers
function setMenuFocused() {
	MENU_FOCUSED = true;
}
function startHideMenu(whichElement) {
	MENU_FOCUSED = false;
	MENU_NAME = whichElement;
	hideMenu();
	return;
} // end startHideMenu()

var globalCounter = 0;
function hoverMenu() {
	var status = true;
	
	var s1 = 'ra';
	var temp = 'ndom';
	var whichElement = s1.concat(temp,globalCounter);

	arrayOfLayers = ['random0','random1','random2','random3','random4'];
	maxNbrOfLayers = 5;

	if (status == true) {
		setMenuFocused()
	    vis = 'visible';
	}
	else if (status == false) {
	   vis = 'hidden';
	}


	  // checking which browser
	  if (IE4) {
    	 for (i=0;i<maxNbrOfLayers;i++) {
        	 layerName = arrayOfLayers[i];
	         if (layerName == whichElement) {
    	        // get its index first
        	    layerIndex = i;
            	theElement = eval("document.all." + arrayOfLayers[i] + ".style");
	            theElement.visibility=vis;
    	     } // check if layer exists
        	 else {
	            theElement = eval("document.all." + arrayOfLayers[i] + ".style");
    	        theElement.visibility='hidden'; 
        	 } // set other layers to hidden
	     } // end if for loop
 	  } // end of IE4

	  else if (NS4) { // netscape or similar browser
	     for (i=0;i<maxNbrOfLayers;i++) {
    	     layerName = arrayOfLayers[i];
	         if (layerName == whichElement) {
    	        // get its index first
	            layerIndex = i;
    	        theElement = eval("document." + arrayOfLayers[i]);
	            theElement.visibility=vis; 
    	     } // check if layer exists
	         else {
	            theElement = eval("document." + arrayOfLayers[i]);         
    	        theElement.visibility='hidden'; 
        	 } // set other layers to hidden
	     } // end if for loop
	  } // end of NS
	  else { // for Opera browser
	     for (i=0;i<maxNbrOfLayers;i++) {
    	     layerName = arrayOfLayers[i];
        	 if (layerName == whichElement) {
	            // get its index first
    	        layerIndex = i;
        	    theElement = eval(document.getElementById(arrayOfLayers[i])).style;  
	            theElement.visibility=vis; 
    	     } // check if layer exists
	         else {
    	        theElement = eval(document.getElementById(arrayOfLayers[i])).style;  
        	    theElement.visibility='hidden'; 
	         } // set other layers to hidden
	     } // end if for loop
	  } // end of Opera
	  globalCounter++;
	  if (globalCounter == 5) globalCounter=0;
window.setTimeout("hoverMenu()",3000);
} // end hoverOver function

function hideMenu() {
	if (!MENU_FOCUSED) hoverMenu(MENU_NAME,t);
	return;
}











function reloadPage() {
	var promotion = document.temp.promotion_id[document.temp.promotion_id.selectedIndex].value;
  	if (promotion == '') return false;
  	
	location.href = '/profiles/?promotion=' + promotion + '';
   	return false;
}
function shutDownOther() {
	var root = document.profile;
	root.uniother.style.backgroundColor='#D8D8D8';
	root.uniother.value = 'other';
	root.uniother.disabled=true;
}
function turnOnOther() {
	var root = document.profile;
	root.uniother.style.backgroundColor='#FFFFFF';
	root.uniother.value = '';
	root.uniother.disabled=false;
}
function checkOther() {
	var other = document.profile.university_id[document.profile.university_id.selectedIndex].value;
	if (other == 'other') turnOnOther();
	else shutDownOther();
	return false;
}
function shutDownWork() {
	var root = document.profile;
	root.work.style.backgroundColor='#D8D8D8';
	root.work.disabled=true;
}
function turnOnWork() {
	var root = document.profile;
	root.work.style.backgroundColor='#FFFFFF';
	root.work.disabled=false;
}
function checkWork() {
	var work = document.profile.work_id[document.profile.work_id.selectedIndex].value;
	if (work == 'Enter Job') turnOnWork();
	else shutDownWork();
	return false;
}

function validateAddForm() {
	var root = document.profile;
	
	var name = root.name.value;
	var telephone = root.telephone.value;
	var address = root.address.value;
	var promotion = root.year1.value;
	var year = root.year.value;
	var month = root.month.value;
	var day = root.day.value;
	var bac = root.bac_id.value;
	var children = root.children_number.value;
	
	if (name == '' || telephone == '' || address == '' || year == '' || month == '' || day == '' || promotion == '' || bac == '') {
		alert('Please fill up all the required fields.');
		return false;
	}
	if (children != '') {
		if (isNaN(children)) {
			alert('Please enter a numeric value for the Number of Children.');
			root.children_number.select();
			return false;
		}
	}
	return true;
}

function popImage(imageURL,imageTitle){
	//alert(imageURL);
	defaultWidth  = 500;
	defaultHeight = 500;
	//alert(imageURL);
	var optNN='scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left=20,top=20';
	var optIE='scrollbars=no,resizable=yes,width=150,height=100,left=20,top=20';

	var AutoClose = true;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
		var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
		var optIE='scrollbars=yes,width=150,height=100,left=100,top=100';

		//if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
			writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
			writeln('<sc'+'ript>');
			writeln('var isNN,isIE;');
			writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');
			writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');
			writeln('if (isIE){');
			writeln('window.resizeTo(100,100);');
			writeln('width=100-(document.body.clientWidth-document.images[0].width);');
			writeln('height=100-(document.body.clientHeight-document.images[0].height);');
			writeln('window.resizeTo(width,height);}');
			writeln('if (isNN){');
			writeln('window.innerWidth=document.images["Image"].width;');
			writeln('window.innerHeight=document.images["Image"].height;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');
			writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<img name="Image" src="'+imageURL+'" style="display:block"></body></html>');
			close();
		}
}

function submitNewsletter(){
	var root = document.newsletter;
	var name = root.name.value;
	var email = root.email.value;
															
	if (name == ''){
		alert('Please give your name');
		root.name.focus();
		return false;
	}
	if (email == ''){
		alert('Please give your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var email = root.email.value;
	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}

	var subscribe1 = root.subscribtion[0].checked;
	var subscribe2 = root.subscribtion[1].checked;
	if (!subscribe1 && !subscribe2) {
		alert('Please make a selection');
		return false;
	}
	
	return true;
}

function validateContactForm() {
	var root = document.contact;
	var name = root.name.value;
	var email = root.email.value;
	var subject = root.subject.value;
	var message = root.message.value;
	
	if (name == '' || email == '' || subject == '' || message == '') {
		alert('Please fill up all the fields.');
		return false;
	}
	return true;
}
function validateSearchForm() {
	var search = document.search1.search.value;
	if (search =='') { 
		alert('Please enter a keyword to search for.');
		return false;
	}
	window.open('/search/display_search.php?search='+search+'', "SearchProfiles", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=400,top=50,left=300");
	return false;
}