
/*******************BANNERS*************************/

function out_of_date(ob){
	var banner = document.getElementById(ob);	
	var current_browser = browser_type();
	if(current_browser == 'ie'){
	var objects = document.getElementsByTagName("object");
	for(i=0;i<objects.length;i++){
		var my_childnodes = objects[i].childNodes;
			for(u=0;u<my_childnodes.length;u++){
				var my_param = my_childnodes[u].getAttribute('name');
				var my_param_val = my_childnodes[u].getAttribute('value');
				if(my_param=='id' && my_param_val ==ob){
					objects[i].style.display = 'none';
					objects[i].removeNode(true);
				
				}
			}
	}

	}else{
	//MOZ//works perfectly
	banner.parentNode.removeChild(banner);
	}
	void(0);
}




/*******************NOTICIAS*************************/
var news_archive_view_state = 'please_select';
function news_archive_page_act(){
	
	var sel = document.getElementById('news_viewer_type');
	switch(sel.value){
		case 'please_select':
			alert('Por favor selecciona:');
		break;
		case 'bydate':
			div_to_show = 'news-archive-bydate-selector';
			div_to_hide = 'news-archive-bykeyword-selector';
		break;
		case 'keyphrase':
			div_to_show = 'news-archive-bykeyword-selector';
			div_to_hide = 'news-archive-bydate-selector';
		break;
	}
	var di = document.getElementById(div_to_show);
	var di_hide = document.getElementById(div_to_hide);
	di.style.visibility = 'visible';
	di_hide.style.visibility = 'hidden';
	news_archive_view_state = sel.value;
}




/*******************MENU*************************/

function setactive(ob,col){
var links = document.getElementsByTagName('a');
for(x=0;x<links.length;x++){
	if(links[x]==ob){
		
		//alert(links[x]+'found::ob');
		links[x].style.color='#'+col;
	}else{
		links[x].style.color='';
	}
}

}


/*******************GENERAL*************************/

function browser_type (){
	if (window.XMLHttpRequest) {
	 	return 'moz';
	}
	if(window.ActiveXObject){
	 	 return 'ie';
	}else{
	 	return 'default';
	}

}


function g (id,url){
	/*animate while loading */
	
	var attributes1 = { 
	opacity: { from: 2, to: 0 }
	}; 
	
	var attributes2 = { 
	opacity: { from: 0, to: 2 }
	};
	/*
	var anim_1 = new YAHOO.util.Anim('body_div', attributes1, 10.5, YAHOO.util.Easing.easeOut); 
	var anim_2 = new YAHOO.util.Anim('body_div', attributes2, 10.5, YAHOO.util.Easing.easeOut); 
	anim_1.animate();
	
	*/
	
	
	var element = document.getElementById(id);
 	if (!element) {
  	alert("Bad id : [" + id +
   	"] no layer avalible" +
   	"You need a div or span element " +
   	"with this id in your page.");
  	return;
 	}
	
	element.innerHTML = l(url);
	//corners(id,url);
	scroll(0,1);
	
	
	//anim_2.animate();
}


function l(url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    return(req.responseText);
  } else {
    alert("Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.");
  }
}



function add_page (id,url){
var element = document.getElementById(id);
//element.innerHTML += c_template[0]+l(url)+c_template[1];
element.innerHTML += l(url);
}



c_template = Array('<div><b class="rc"><b class="rc1"><b></b></b><b class="rc2"><b></b></b><b class="rc3"></b><b class="rc4"></b><b class="rc5"></b></b><div class="rcfg">','</div><b class="rc"><b class="rc5"></b><b class="rc4"></b><b class="rc3"></b><b class="rc2"><b></b></b><b class="rc1"><b></b></b></b></div>');
function corners (id,url){
	var element = document.getElementById(id);
	element.innerHTML = c_template[0]+l(url)+c_template[1];
}


 function gm_initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13); 		//set the client details here
      }
    }



/* TRESORG AJAX PAYPAL STORE [CLIENT SIDE]				...needs php to work		*/
/*							items	names	prices									*/
/*
tresorg.store.cart = new Array(new Array(),new Array(),new Array());	//the way its meant
tresorg.store.total_items = 0;
tresorg.store.total_price = 0;

tresorg.store.add_to_cart = function(item_id,item_name,item_price){
	tresorg.store.total_items += 1;
	tresorg.store.cart['item'][tresorg.store.total_items] = item_id;
	tresorg.store.cart['name'][tresorg.store.total_items] = item_name;
	tresorg.store.cart['price'][tresorg.store.total_items] = item_price;

}
*/
/*
tresorg.store.view_cart = function (){
	for(i=0;i<tresorg.store.total_items;i++){
		//	@todo	edit,validate from here //
		ret += '<div class="tienda_all">';
			ret += '<div class="tienda_pa_title">';
				ret += tresorg.store.cart['name'][i] + '<a href="javascript:">'
	}
	
	// show in body_div with a link "back to the store" //
	
}

tresorg.store.

tresorg.store.check_out = function (){
	// show a preview of the items	//
	// be able to edit the items	// 
}

*/

/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function pop_img($dir){
	window.open($dir);
}

/*******************FORMS*************************/

function check_form_field($form_id,$field_id){
$field = document.forms[$form_id].elements[$field_id];
if($field.value == ''){
	return true;
}else{
	return false;
}
}

function check_form ($form_id){
$canWeSend=1;	//we can send, lets make shure though...
$return_form = 'index.php?view=submit_form';
$elements = document.forms[$form_id].elements;
$f_top = $elements.length;
//alert($f_top);
for($fc=0;$fc<$f_top;$fc++){

switch(true){
case $elements[$fc].name == 'obligar':
	//alert('campo abligatorio:'+$elements[$fc].value);
	if(check_form_field($form_id,$elements[$fc].value)){
	$canWeSend=0;
	alert('¿'+$elements[$fc].value+'? ');
	}else{
	
	}
break;
}//switch END

switch(true){
	case $elements[$fc].name == 'obligar':
	break;
	case $elements[$fc].name == 'Submit':
	break;
	default:
	$return_form += '&'+$elements[$fc].name+'='+$elements[$fc].value;
	break;
}
}//for END

if($canWeSend==1){
g('body_div',$return_form);
}

}
