function MostrarCalendario(nombre, ubicacion)
	{
	    if (ubicacion == "")
	    {
	        alert("Debe seleccionar Ubicacion entrega");
	    }
	    else
	    {
		    //obj = document.getElementById(nombre)
		    //wind = window.open ('http://www.regalooriginal.com/regalosoriginales/calendario/default.aspx?nombre='+ nombre,'calendario','nostatus, notoolbar, nolocation, nomenubar, noresizable, noscrollbars, height=197, width=157');
		    //wind = window.open ('http://localhost/regalooriginal/calendario/default.aspx?nombre='+ nombre +'&ubicacion='+ ubicacion,'calendario','nostatus, notoolbar, nolocation, nomenubar, noresizable, noscrollbars, height=215, width=157');
		    wind = window.open ('calendario/default.aspx?nombre='+ nombre +'&ubicacion='+ ubicacion,'calendario','nostatus, notoolbar, nolocation, nomenubar, noresizable, noscrollbars, height=215, width=157');
		    //alert(obj.value);
		    wind.focus();
		}
	}
	

function isNumeric(valor)
{
    aux = parseInt(valor, 10);
    return !isNaN(aux);
}


function insertText(campo,texto) 
	{ 
		if (campo.setSelectionRange)
		{ 
			campo.value = campo.value.substring(0,campo.selectionStart) + texto + campo.value.substring(campo.selectionStart,campo.selectionEnd) + campo.value.substring(campo.selectionEnd,campo.value.length); 
		} 
		else 
			if (document.selection && document.selection.createRange) 
			{ 
				campo.focus(); 
				var range = document.selection.createRange(); 
				range.text = texto + range.text; 
			} 
	} 

function dayofWeek(day)
	{
		switch( day ) {
			case 0: s = "Sunday"; break;
			case 1: s = "Monday"; break;
			case 2: s = "Tuesday"; break;
			case 3: s = "Wednesday"; break;
			case 4: s = "Thursday"; break;
			case 5: s = "Friday"; break;
			case 6: s = "Saturday"; break;
			default: s = "Unknownday"
		}
	return s;
	}
	
function monthofYear(mon)
	{
		switch( mon ) {
			case 0: s = "January"; break;
			case 1: s = "February"; break;
			case 2: s = "March"; break;
			case 3: s = "April"; break;
			case 4: s = "May"; break;
			case 5: s = "June"; break;
			case 6: s = "July"; break;
			case 7: s = "August"; break;
			case 8: s = "September"; break;
			case 9: s = "October"; break;
			case 10: s = "November"; break;
			case 11: s = "December"; break;
			default: s = "Unknownmonth"
		}
	return s;
	}
	
	function calcular_fecha(fecha)
	{ 
		//calculo la fecha que recibo  en formato espaņol dd/mm/yyyy
		//La descompongo en un array 
		var array_fecha = fecha.split("/") 
		//si el array no tiene tres partes, la fecha es incorrecta 
		if (array_fecha.length!=3) 
			return false 

		//compruebo que los ano, mes, dia son correctos 
		var ano 
		ano = parseInt(array_fecha[2], 10); 
		if (isNaN(ano)) 
			return false 

		var mes 
		mes = parseInt(array_fecha[1], 10); 
		if (isNaN(mes)) 
			return false 

		var dia 
		dia = parseInt(array_fecha[0], 10); 
		if (isNaN(dia)) 
			return false 
			
		newFecha = new Date();
		newFecha.setFullYear(ano,mes - 1, dia)
		
		return newFecha;    
	} 
      
/*      lastmod = document.lastModified     // get string of last modified date
      lastmoddate = Date.parse(lastmod)   // convert modified string to date
      if(lastmoddate == 0){               // unknown date (or January 1, 1970 GMT)
         document.writeln("Last Modified: Unknown")
      } else {
1:      d = new Date(lastmod);
2:      document.write("Day=", day=dayofWeek(d.getDay()), ", ");
3:      document.write("Month=", mon=monthofYear(d.getMonth()), ", ");
4:      document.write("Date=", dte=d.getDate(), ", ");
5:      document.write("Year=", year=d.getYear(), "&lt;br&gt;");
6:      document.write("Last Modified: ", day + ", " + mon + " " + dte + ", " + year);
      }// 
*/

function VaciarCombo(combo){
	var select = document.getElementById(combo);
	for (m = select.options.length-1; m>=0; m--)
		select.options[m] = null;
}
function CargarCombos(combo,x){

	valor="";
	if (document.getElementById(combo).selectedIndex != -1)
	{
		valor = document.getElementById(combo).value;
	}
	
	VaciarCombo(combo);
	
	var select = document.getElementById(combo);
	selectedarray=eval(x);
	for (i=0; i<selectedarray.length; i++)
		select.options[i] = new Option(selectedarray[i].text,selectedarray[i].value);
		
	entro = false;
	for (i = 0; i < document.getElementById(combo).length; i++) 
	{
		if (document.getElementById(combo).options[i].value == valor)
		{
			entro = true;
			document.getElementById(combo).options[i].selected = true;
		}
	}
	
	if (!entro)
		document.getElementById(combo).options[0].selected = true;
					
	//select.options[0].selected = true;
}

function textCounter(field,cntfield,maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}

function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
		return (true)
	} else {
		return (false);
	}
}

function cancelarSubmit(aEvent)
{
    aEvent.cancelBubble = true;
    if (aEvent.stopPropagation) aEvent.stopPropagation();
    return false;
}

function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;

   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
}

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
}

function Trim( str ) {
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}