//Item: javascript
//Filename: myScript.js
//Description: this file contains basic routines functions that applies javascript

//----> declaration of variables <----------

var isDTHML = 0;	//dhtml capable
var isID = 0;		//W3C
var isLayer = 0;	//Netscape
var isAll = 0;		//IE
var stdBrowser = (document.getElementById)?true:false;
var count = 0;

//----> function to determine the kind of browser and whether they support DHML

function findDOM(){
	if(document.getElementById){	//cross browser
		isID = 1;
		isDHTML = 1;
	}
	else if(document.layers){	//Netscape
		isLayer = 1;
		isDHML = 1;
	}
	else if(document.all){		//IE
		isAll = 1;
		isDHTML = 1;
	}
}

function slideMenu(curMenu){
	var menu;
	
	if(stdBrowser){		//check if current browser supports layers
		//menu = document.getElementById(curMenu).style;
		menu = getObj(curMenu, 1);			
		//--->changes display's value
		menu.display = (menu.display == "block")?"none":"block";
	}
	return false;
}


//function objectObj -----
//Params: ObjectID, an object's id
//		  withStyle, tells whether function should returns object with style access
//Return Value: it returns a style object reference of the object parameter

function getObj(id, withStyle){

	findDOM();

	if(withStyle == 1){
		//check is browser supports well id
		if(isID){
			return (document.getElementById(id).style);
		}
		if(isAll){		//IE
	
			return (document.all[id].style);
		}
		if(isLayer){
			return (document.layers[id]);	
		}
	}
	else{
		if(isID){
			return (document.getElementById(id));
		}
		if(isAll){		//IE
			return (document.all[id]);
		}
		if(isLayer){
			return (document.layers[id]);	
		}
	}
}

//function rotate the ban2 words
function rotateBan2(){
	
	var mlseconds = 1000;
	var len = 4;	//the number of rotation times to do for each cicle
	
	if(document.images){
		count++;
		if(count == 1){
			showThis(1, "word1");				
		}
		else if(count == 2){
			showThis(1, "word2");
		}
		else if(count == 3){
			showThis(1, "word3");
		}
		else{
			showThis(0, "word1");
			showThis(0, "word2");
			showThis(0, "word3");
			count = 0;
		}
		
		
		setTimeout("rotateBan2()", mlseconds);
	}
}

//function to display a word

function showThis(flag, item){
	var itemObj;
	itemObj=getObj(item);
	
	itemObj.display =(flag)?"block":"none";	
}

function setDisplay(item){
	var itemObj;
	itemObj=getId(item);	
	itemObj.display =(itemObj.display=="none")?"block":"none";
}

//function to return a web item object
//it avoids the difference between IE's id and Netscape's layer support
function getId(item){	
	return (stdBrowser)?document.getElementById(item).style:eval("document." + item);
}

//function getParam
//Params: url, is the current browser's location address string
//Return value: it returns the first parameter in the address string
//			    it no parameters found, returns null

function getParam(url){
	var str = new String(url);
	str = str.substring((str.indexOf("?")+1));
	var params;
	var arg = null;
	//alert(str);
	
	if(str.length > 0){
		params = new Array(str.split(","));
	//	alert(params.length);
		if( params.length > 0){
			var temp = new String(params[0]);
			if(temp.indexOf("=") != -1){				
				arg = temp.substring(temp.indexOf("=")+1);
			}
			//alert(arg);
		}
	}
	return arg;
}

function hideItem(item){
	//alert("in hide");
	var obj=getId(item);
	//alert(obj.display);
	obj.display ="none";
}
/*
	params: an array that contains a list of ids
*/
function hide_objs(ids){
	//alert("size: "+ids.length);
	for(var i=0; i<ids.length; i++){
		hideItem(ids[i]);
	}
}

/*
	showItem
	shows a specific item in list

	Params
	 - an array that contains a list of ids
	 - the item to be shown
*/
function showItem(ids, item){
	//alert("in");
	hide_objs(ids);
	var obj=getId(item);
	obj.display ="block";
}

/*
	splits a string with a (;) as separator into an array
*/

function splitText(text){
	var str= new String(text);
	var list="";

	list=str.split(";");

	for(var i=0;i<list.length;i++){
		alert(list[i]);
	}
}

// toggle visibility 
function toggle( targetId ){
	
  if (document.getElementById){
	    target = document.getElementById( targetId );
  			if (target.style.display == "none" || target.style.display==""){
  				target.style.display = "block";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

/*
	scroll the window to a specific position
*/
function scrollWindow()
{
window.scrollTo(100,500)
}

/*
	set focus on a specific anchor
*/
function setFocus(num)
{
var x=document.anchors
x[num].focus()
}

/*
	coordinates
	Finds the X and Y coordinates on a Window
	
	Note: useful for image-mapping
*/

function coordinates()
{
	var x=event.clientX
	var y=event.clientY
	alert("X=" + x + " Y=" + y)
	/*document.form1.x.value = event.clientX;
	document.form1.y.value = event.clientY;*/
}

/*
	makeSelect
	focus and selects
*/
function makeSelect(anItem){
	anItem.select()
	anItem.focus()	
}

function popUpWindow(page, w, h){
	var properties = "width=" + w + ", height=" + h + ",scrollbars=yes, resizable=yes";
			
	window.open(page, "winRef", properties);
}

function showAnswer(anId, aColor, flag){
	var obj = getObj(anId, true);
	obj.color = aColor;
	obj.font = (flag)?"bold":"normal";
}
