/*
 * Helpers script! Depends on ui.core.js
 */


/*
 * Loads the header page and hides all Js requirements messages!
 */
function initOdp()
{
		// 1 - load the logo and the photos to the header div!
		$("div#Header").load("http://www.oficinadeportugues.net/headerphotos.html");
}

/*
 * Changes the src of the image 
 */
function ImageSrc(imageId,imgSrc)
{
	document.images[imageId].src = imgSrc;
}

/*
 * Corrects the logo position!!
 */
function Logo()
{	
	var ielogo = document.getElementById("IELogoDiv");
	var otherslogo = document.getElementById("OthersLogoDiv");

	if(navigator.userAgent.indexOf("MSIE")<0)
	{
		ielogo.style.display='none';
		otherslogo.style.display = 'block';
	}
		
	else
	{
		ielogo.style.display = 'block';	
		otherslogo.style.display = 'none';
	}
	
}

/*
 * Opens a popup 
 */
function popup(page,width,height)
{
 
	return window.open(page,"popup","toolbar=0,location=0,resizable=0,width="+width+",height="+height);

}

/*
 *  If new window is true opens a new window  
 * else redirects the current window to the given url
 */
function goto(url, newwindow)
{
	if(newwindow)
		window.open(url);
		
	else window.location = url;
}

/*
 * Hides all elements with a given name.
 */
function HideElements(elemsName)
{
	$("[name='"+elemsName+"'").hide();
	  
}

function CenterElementById(elemId)
{
	//Get the window height and width  				
	var winH = $(window).height();  
	var winW = $(window).width();  

	//Set the popup window to center  
	$(id).css('top',  winH/2-$(id).height()/2);  
	$(id).css('left', winW/2-$(id).width()/2); 	
}

/*
* Load a xml file
*/
function loadXML(xmlSrc, async)
{
	var xmlDoc;
	
	if($.browser.msie)
	{
	   xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
	   xmlDoc.async = async; 
	   while(xmlDoc.readyState != 4) {}; 

	   xmlDoc.load(xmlSrc); 

	}
	
	else if($.browser.mozilla)
	{
	   xmlDoc=document.implementation.createDocument("", "", null);

       xmlDoc.load(xmlSrc);
	}
	
	else //safari or chrome
	{

		var xmlhttp = new window.XMLHttpRequest();
		xmlhttp.open("GET",xmlSrc,false);
		xmlhttp.send(null);
		xmlDoc = xmlhttp.responseXML.documentElement; 

	} 
		
	return xmlDoc;
}

/*
 * Returns the value of the specified query string or default_ if it doesn't exists
 */
function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

/*
 * Prints the content of the element with the given id
 */
function printContent(id){
	str="<div style='margin:20px;'><img src='http://oficinadeportugues.net/images/logo/logotipoOficinaDePortugues.png' /></div>" + $(id).html();
	newwin=window.open('','Oficina de Portugues','left=100,top=100,width=400,height=400');
	newwin.document.write('<HTML>\n<HEAD>\n');
	newwin.document.write('<TITLE>Print Page</TITLE>\n');
	newwin.document.write('<script>\n');
	newwin.document.write('function chkstate(){\n');
	newwin.document.write('if(document.readyState=="complete"){\n');
	newwin.document.write('window.close()\n');
	newwin.document.write('}\n');
	newwin.document.write('else{\n');
	newwin.document.write('setTimeout("chkstate()",2000)\n');
	newwin.document.write('}\n');
	newwin.document.write('}\n');
	newwin.document.write('function print_win(){\n');
	newwin.document.write('window.print();\n');
	newwin.document.write('chkstate();\n');
	newwin.document.write('}\n');
	newwin.document.write('<\/script>\n');
	newwin.document.write('<style type="text/css" media="print">body {font-family : "Times New Roman",Times,serif;font-size : 12pt; } *{color : #000000;background : #ffffff; text-align:center;}</style>\n');
	newwin.document.write('</HEAD>\n');
	newwin.document.write('<BODY onload="print_win()">\n');
	newwin.document.write(str);
	newwin.document.write('</BODY>\n');
	newwin.document.write('</HTML>\n');
	newwin.document.close();
}
//-->		