/**
*Function to Add a website to fdefault search engine of the browser.
*Now only availale on FireFox. 
*/
function addsearchengine () {
   if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
     window.sidebar.addSearchEngine("<?=WEB_URL?>lib/doceos_noticias.src","<?=WEB_URL?>img/doceos_noticias.gif", "<?=LANG_MSG110?>", "");
     } else {     
       alert("Sorry! Your browser doesn't support this function.");
     }
};

/**
*Function to Add a website to default page of the browser.
*Now only available on IE. 
*/
function addashomepage(myurl){
	if(document.all){
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(myurl);
	 }else{
		 	 alert("Sorry! Your browser doesn't support this function.");
	 }
};

/**
*Function to Add a website to bookmark of the browser.
*Now only available on IE. 
*/
function addtobookmark(myurl) { 
	if (window.external) {
	window.external.AddFavorite(myurl,myurl) 
	}else{ 
		alert("Sorry! Your browser doesn't support this function."); 
	}
} 



/**
* to show a layer with announcements
* using AJAX to retireve the url data
* @parameters 
* urltoshow  - the url of the announcement page
* timeinsegs - the time @ which the announce layer close automatically
* width		 - the width of the layer. will be the screen width if given as 0 
* height	 - the height of the layer. will be the screen height if given as 0 
* coordx	 - the left space of the layer.  
* coordy	 - the top space  of the layer. 
*/

function showAnnounce (urltoshow, timeinsegs, width, height, coordx, coordy){
	
	//create Div 
	newdiv 				= document.createElement ('div');
	newdiv.id 				= 'announceDiv';
	newdiv.style.display 	= 'none'; 
	document.body.appendChild (newdiv); 
	
	//checking whether  XMLHTTP Object is avialable
	var res = 0;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
		} 
	catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
			}
		catch (E) {
			try {
				xmlhttp= new XMLHttpRequest()
				} 
			catch (ee) {
				res = 1;
				
				}
		}
	}
	
	//Creating XMLHttpRequest Object ..
	if (window.XMLHttpRequest) { 
		http = new XMLHttpRequest(); 
	}else if(window.ActiveXObject){	
		http = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	urltoshow += "?pseudoParam=" + new Date().getTime();//adding pseudoParam to avoid taking chached data.
	
	//opening the urltoshow with get method
	http.open('get',urltoshow ,false);
	http.setRequestHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
	http.setRequestHeader('Cache-Control', 'public');
	http.send(null);
	response = http.responseText;
	
	//calculating layer width and height if the width and height set to 0
	widthPercentage     = (coordx!=0) ? 100- Math.round((coordx /screen.width)*100) : 100;
	heightPercentage    = (coordy!=0) ? 100- Math.round((coordy /screen.height)*100): 100;
	
	//checking the layer display parameters
	width				= (width!=0)  ? width   : widthPercentage + "%";
	height 				= (height!=0) ? height 	: heightPercentage  + "%";
	
	//setting layer styles  ..........
	var styleObj 		= document.getElementById('announceDiv').style;
	styleObj.position 	= "absolute";
	//styleObj.display  	= "";
	styleObj.width 		= width;
	styleObj.height 	= height;
	styleObj.left 		= coordx;
	styleObj.top 		= coordy;
	
	//putting url data to layer..
	if(response !=""){
	   document.getElementById('announceDiv').innerHTML =   "<table width=100%><tr><td height=20 align='right'>[<a href=\"javascript:opacity('announceDiv', 100, 0,2000);\">close</a>]</td></tr><tr><td>" + 			response + "</td></tr><table>";
	}else{
		document.getElementById('announceDiv').innerHTML = "No announcements!";
	}
	opacity('announceDiv',0,100,2000);
	setTimeout("opacity('announceDiv',100,0,2000)",timeinsegs);


}




function wopen (mypage, myname, w, h, s, r) {
  var winL = Math.round((screen.width - w) / 2);
  var winT = Math.round((screen.height - h) / 2);
  var winprops = 'height='+h+',width='+w+',scrollbars='+s+',resizable='+r;
  win = window.open(mypage, myname, winprops);
  win.moveTo(winL,winT);
}


function show_box (refid) {
   if (document.getElementById(refid).style.visibility=='hidden') { 
   	 document.getElementById(refid).style.visibility='visible'; 
   	 document.getElementById(refid).style.display='inline'; 
   } else { 
   	 document.getElementById(refid).style.visibility='hidden'; 
   	 document.getElementById(refid).style.display='none' 
   };		
}

function addsearchengine () {
   if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
     window.sidebar.addSearchEngine("<?=WEB_URL?>lib/doceos_noticias.src","<?=WEB_URL?>img/doceos_noticias.gif", "<?=LANG_MSG110?>", "");
     } else {     
       alert("<?=LANG_MSG101?>");
     }
};

function show_elem (refid, isshow) {
   switch (isshow) {
   	case 'visible': 
      document.getElementById(refid).style.visibility='visible'; 
   	  document.getElementById(refid).style.display='inline';
   	  break;
   	default:
   	case 'none':
      document.getElementById(refid).style.visibility='hidden'; 
   	  document.getElementById(refid).style.display='none'
   	  break;   	  
   }	
};

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);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
