function openLinkInNewWindow(link){
	if(link.toLowerCase().indexOf("http://")==-1){
		link = "http://"+link;
	}
	window.open(link,"_blank");
}

function popup(page,width,height,text) {
    window.open(page,'_blank','toolbar=no,screenX=150,screenY=30,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+ width +',height='+ height);
    
}

function newWin(url) {
	window.open(url, '_blank');
	return false;
}

function newWinForm(element) {
	element.target="_blank";
	element.submit();
}

function togleVisibility(element){
	if(element.style.display=="block"){
		element.style.display="none";
	}
	else{
		element.style.display="block";
	}
}

function switchCheckboxValue(id){
	document.getElementById(id).checked==true?document.getElementById(id).checked=false:document.getElementById(id).checked=true;
}

function bookmarkLink() {
 	title = document.title; 
 	url = location.href;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }
 
 function adClick(url,ad_id,ad_type_id) {
	document.location="adclick.php?ad_id="+ad_id+"&ad_type_id="+ad_type_id+"&url="+url;
	return false;
}

function checkIntegerValue(element){
	val=parseInt(element.value);
	if(element.value!=""){
		if(isNaN(val)){
			val=0;
		}
		element.value=val;
	}
}

function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
		thefield.value = ""
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
}

function toggleView(cookieName){
	state="closed";
	if(getCookie(cookieName)=="closed")state="opened";
	setCookie(cookieName,state,300);	
}

function selectTab(id)
{   
    if(id!=0)
    {
    	document.getElementById("submenu"+id).style.display = "block";
    	document.getElementById("menu"+id).className = "menuTabSelected";
    	//hide default tab	
        if(defaultMenu!=id && defaultMenu!=0)
        {
            document.getElementById("submenu"+defaultMenu).style.display = "none";
            document.getElementById("menu"+defaultMenu).className = "menuTab";
        }
    }
}
    
function unselectTabs()
{	
    for(i=1; i<max; i++)
    {
        if(document.getElementById("submenu"+i)==undefined) break;
        document.getElementById("submenu"+i).style.display = "none";
        document.getElementById("menu"+i).className = "menuTab";
        if(defaultMenu!=0)
        {
            if(defaultMenu==i)
            {            	
                document.getElementById("submenu"+i).style.display = "block";
                document.getElementById("menu"+i).className = "menuTabSelected";
            }
        }
    }
}

function bookmark(title,url,web){
	if (window.sidebar){ // firefox	
		window.sidebar.addPanel(title, url, web);
	}
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all){// ie
		window.external.AddFavorite(url, title);
	}
}

function resizeMap( map, latlng ) {
  
  
  
  // map: an instance of GMap2
  // latlng: an array of instances of GLatLng
  var latlngbounds = new GLatLngBounds( );
  for ( var i = 0; i < latlng.length; i++ )
  {
    latlngbounds.extend( latlng[ i ] );
  }
  map.setCenter( latlngbounds.getCenter( ), map.getBoundsZoomLevel( latlngbounds )-1 );
  
  
  
  
}