

// Author: Rafael Lima (http://rafael.adm.br)
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 
		    'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:
		    is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();


gotoLocation = function ( l ) { document.location.href= l; }

function displayError ( formNode , validators )
{
    var errorHTML = "";

    for(var i=0;i<validators.length;i++){
        errorHTML += "<li>" + validators[i].message + "</li>";
    }
     
    //YAHOO.util.Dom.setStyle ( 'errorDisplay','display','block' );
    fadeIn ( 'errorDisplay' );
    YAHOO.util.Dom.get ('errorDisplay').innerHTML = "Please fix the following problems -<br/><ul>" + errorHTML + "</ul>"; 	  
}

function displayErrorAdditional ( message )
{

    //YAHOO.util.Dom.setStyle ( 'errorDisplay','display','block' );
    fadeIn ( 'errorDisplay' );
    if ( YAHOO.util.Dom.get ('errorDisplay').innerHTML.indexOf ( message ) == -1 ) 
    YAHOO.util.Dom.get ('errorDisplay').innerHTML = "<ul><li>" + message + "</li></ul>"; 
}



isValidDomain = function ( url )
{


	// elimnates localhost, intranet etc..
	if ( url.indexOf ( '.' ) == -1 ) return null;
	
	var parts = url.split ( '.' );
	
	if ( parts.length == 4 )
	{
		var isIP = true;
		for ( x = 0 ; x < parts.length ; x++ )
		{
			if ( !isInt ( parts [ x ] ) ) isIP = false;
		}
		
		if ( isIP  ) return null;
	}
	
	return url;
}


 // popular urls that get entered that don't return what 
 // you'd expect get changed here.
 special = function ( u )
 {
    switch ( u )
    {
     case 'wikipedia.org':
     case 'http://wikipedia.org':
        return 'http://en.wikipedia.org/wiki/Main_Page';
     default: return u;   
     
    }
 };
 
 
 
isInt = function ( x ) 
{
	var y=parseInt(x);
	if (isNaN(y)) return false;
	return x==y && x.toString()==y.toString();
} 


loadCalais = function ( url )
{

    var calaisCallback =
    {
      success: function(o) {$('calaisGraph').innerHTML = o.responseText;},
      failure: function(o) {$('calaisGraph').innerHTML = '<br/><br/><strong color="red">Could not load Calais Meta Data for this site. Either an error occured or the request timed out.</strong>';},
      timeout: 60000
    }
    	

    var transaction = YAHOO.util.Connect.asyncRequest('GET', 'frenchPort.asmx?URL=' + escape(url), calaisCallback); 

    $('calaisGraph').innerHTML = '<br/><br/><div style="text-align:center"><img src="IMG/loader.gif"/></div>';

}



function fadeIn ( id, speed, force )
{
if ( force == null ) force=true;
if ( speed == null) speed=0.2;
 if ( document.all && force ) {
 $(id).style.display='inline';
 return;
 }

 if ( $(id).style.display=='none' || $(id).style.display=='' )
 {
 YAHOO.util.Dom.setStyle ( id, 'opacity',0);
 $(id).style.display='block';
 }

 anim = new YAHOO.util.Anim(id, { opacity: { to: 1 } }, speed, YAHOO.util.Easing.easeOut );
 anim.animate ();

}

function fadeOut ( id, speed )
{
 if ( document.all  ) { $(id).style.display='none';return; }
if ( speed == null) speed=0.2;
 anim = new YAHOO.util.Anim(id, { opacity: { to: 0 } }, speed, YAHOO.util.Easing.easeOut );
 anim.animate ();
 setTimeout ( '$(\'' + id + '\').style.display=\'none\'',(speed*1000)+5 );
}



CancelCreate = function ( loc )
{

    if ( confirm ( 'This action will cancel the process. Are you sure?' ) )
    {
        document.location.href = loc;
    }
}