if(!YAHOO.Mevia){ YAHOO.namespace("Mevia"); }

YAHOO.Mevia.pageWidth = function() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;}

YAHOO.Mevia.pageHeight = function() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 

YAHOO.Mevia.posLeft = function() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} 
YAHOO.Mevia.posTop = function() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} 

YAHOO.Mevia.posRight = function() {return posLeft()+pageWidth();} 
YAHOO.Mevia.posBottom = function() {return posTop()+pageHeight();}

YAHOO.Mevia.getFormCollections = function(collectionName,form){
	if(typeof(form).toLowerCase()=='string'){ form = YAHOO.util.Dom.get(form); }
	var a = [];
	var collection = form[collectionName+"[]"];
	if(collection){
		if(collection.tagName){
			if(collection.value != ''){					
				a.push(collection.value);
			}
		}else{
			for(var i=0;i<collection.length;i++){
				if(collection[i].value != ''){						
					a.push(collection[i].value);
				}
			}			
		}			
	}
	return a;
}

YAHOO.Mevia.getMultiCheckbox = function(collectionName, form, separator){
	if(typeof(form).toLowerCase()=='string'){ form = YAHOO.util.Dom.get(form); }
	var a = [];
	var collection = form[collectionName+"[]"];
	if(collection){
		if(collection.tagName){
			if(collection.checked){
				a.push(collection.value);
			}
		}else{
			for (var i=0;i<collection.length;i++) {
				if (collection[i].checked) {				
					a.push(collection[i].value);
				}
			}
		}					
	}
	
	if (separator) {
		return a.join(separator);
	};
	return a;
}

YAHOO.Mevia.getRadioValue = function(input_name){
	var radios = document.getElementsByName(input_name);
	if(radios){
		for(var i=0;i<radios.length;i++){
			if(radios[i].checked){
				return radios[i].value;
			}
		}		
	}
}

YAHOO.Mevia.checkboxIsChecked = function(input_id){
	var checkbox = YAHOO.util.Dom.get(input_id);
	return (checkbox.checked)? 1:0;
}

YAHOO.Mevia.checkboxIsNotChecked = function(input_id){
	var checkbox = YAHOO.util.Dom.get(input_id);
	return (checkbox.checked)? 0:1;
}

YAHOO.Mevia.removeMe = function(elt){
	var parent = elt.parentNode;
	parent.removeChild(elt);
}


YAHOO.Mevia.tabSwitcher = function(tabid){
	var yud = YAHOO.util.Dom;
	var links = yud.getElementsBy(function(){return true;},'a',tabid);
	var lis = yud.getElementsBy(function(){return true;},'li',tabid);
	YAHOO.util.Event.addListener(links,'click',function(){
		yud.removeClass(lis,'selected');
		yud.addClass(yud.getAncestorByTagName(this,"li"),'selected');
	});
}

YAHOO.Mevia.getDate = function(field_id){
	var yud = YAHOO.util.Dom;
	return yud.get(field_id+'_year').value+"-"+yud.get(field_id+'_month').value+"-"+yud.get(field_id+'_day').value;
}

YAHOO.Mevia.switchIcon = function(img, to)
{
	if(typeof(img).toLowerCase()=='string'){ img = YAHOO.util.Dom.get(img); }
	var regex = new RegExp("[a-zA-Z_]+\.png");
	var src = img.src;
	src = src.replace(regex, to);
	img.src = src;
}

YAHOO.Mevia.onsuccessInline = function(o)
{
	var json = eval("(" + o.responseText + ")");
	for (data in json) {
		if (data != 'default') {
			// console.log(json[data]);
			YAHOO.util.Dom.get(data).innerHTML = json[data];
		};
	}
}


YAHOO.Mevia.getMultiSelectValue = function(elt)
{
	if(typeof(elt).toLowerCase()=='string'){ elt = YAHOO.util.Dom.get(elt); }	
	var selectedArray = new Array();
	var i;
	var count = 0;
	var size = elt.options.length;
	for (i = 0; i < size; i++) {
		if (elt.options[i].selected) {
			selectedArray[count++] = elt.options[i].value;
		}
	}
	return selectedArray.join(',');
}

YAHOO.Mevia.getCollectionValues = function(collectionName, root, tag){
	var a = [];
	var collection = YAHOO.util.Dom.getElementsBy(function(elt)
	{
		if (!elt.name) {
			return false;
		}
		return elt.name == collectionName + "[]";
	}, tag, root);
	if(collection){
		if(collection.tagName){
			if(collection.value != ''){					
				a.push(collection.value);
			}
		}else{
			for(var i=0;i<collection.length;i++){
				if(collection[i].value != ''){						
					a.push(collection[i].value);
				}
			}			
		}			
	}
	return a;
}