
	var shc_root = './shoppingcart/' ;

	//	DETECTANDO EL NAVEGADOR Y SETEANDO LA VARIABLE BOOLEANA 'ie'

	var navegador = navigator.appName
	if (navegador == 'Microsoft Internet Explorer'){
		ie = true ;
	}
	else{
		ie = false ;
	}

	function getLeft(ele){
	     if (ele.offsetParent){ return ele.offsetLeft + getLeft(ele.offsetParent) ; }
	     else{ return ele.offsetLeft ; }
	}

	function getTop(ele){
		if (ele.offsetParent){ return (ele.offsetTop + getTop(ele.offsetParent)) ;  }
		else{ return (ele.offsetTop) ; }
	}

	function getWidth(ele){
	     return ele.offsetWidth ;
	}

	function getHeight(ele){
	     return ele.offsetHeight ;
	}

	function doAjax(){
		var xmlhttp = false ;
		try{
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP') ;
		}catch(e){
			try{
				xmlhttp = new ActiveXObject('Microsoft.XMLHTTP') ;
			}catch(E){
				xmlhttp = false ;
			}
		}
		if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
			xmlhttp = new XMLHttpRequest() ;
		}
		return xmlhttp ;
	}

	function completeHTML(id_container, response){
		$(id_container).innerHTML = response ;
	}

	function set(attribute, value){

		var temp_price = $('price').innerHTML ;
		var req = doAjax() ;

		if(req){
			req.onreadystatechange = function(){

				if(req.readyState == 4){
					Effect.BlindDown('product-details') ;
					$('product-details').innerHTML = req.responseText ;

					if($('price').innerHTML != temp_price){
						Effect.Pulsate('price') ;
					}

					var calendario = new anos() ;
					calendario.esParaFormulario(true) ;

				}
			}
			req.open("GET", shc_root + "ajax.php?att=" + attribute + "&val=" + value , true) ;
			req.send(null) ;
		}
	}

	function removeNotAvailableDiv(){
		if(document.getElementById('not_available')){
			document.getElementById('not_available').parentNode.removeChild(document.getElementById('not_available')) ;
		}
	}

	function initCart(){

		var table = $('products-cart') ;
		var inputs = table.getElementsByTagName('input') ;

		for(var i = 0 ; i < inputs.length ; i++){

			inputs[i].onblur = function(){
				removeNotAvailableDiv() ;
			}

			inputs[i].onkeyup = function(){

				removeNotAvailableDiv()
				regex = /[^0-9]/g ;
				_float = /[0-9.]/g ;
				no_float = /[^0-9.]/g ;

				this.value = this.value.replace(regex, '') ; // only numbers are valid

				var id_number = parseInt(this.id.split('-')[1]) ;

				var symbol_price = $('price-' + id_number).innerHTML ;

				var symbol = symbol_price.replace(_float, '') ;
				var price = symbol_price.replace(no_float, '') ;
				price = parseFloat(price) ;

				var container = $('subtotal-' + id_number) ;
				var subtotal = parseFloat(this.value * price).toFixed(2) ;
				container.innerHTML = '' + symbol + subtotal ;

				var input = this ;
				var req = doAjax() ;

				if(req){

					req.onreadystatechange = function(){

						if(req.readyState == 4){
							if(req.responseText.length > 0){

								var div = document.createElement('div') ;

								div.id = 'not_available' ;

								var x_container = getLeft(document.getElementById('contenedor_cart')) ;
								var y_container = getTop(document.getElementById('contenedor_cart')) ;

								div.style.left = (parseInt(getLeft(input)) - parseInt(x_container) + parseInt(getWidth(input))) + 'px' ;
								div.style.top = (parseInt(getTop(input)) - parseInt(y_container) + parseInt(getHeight(input))) + 'px' ;
								div.innerHTML = req.responseText ;

								input.parentNode.appendChild(div) ;
								input.value = document.getElementById('stocks_hidden').innerHTML ;

								var symbol_price = $('price-' + id_number).innerHTML ;
								var symbol = symbol_price.replace(_float, '') ;
								var price = symbol_price.replace(no_float, '') ;
								price = parseFloat(price) ;

								var container = $('subtotal-' + id_number) ;
								var subtotal = parseFloat(input.value * price).toFixed(2) ;
								container.innerHTML = '' + symbol + subtotal ;

								sumSubtotals() ;
							}
						}
					}

					req.open("GET", shc_root + "ajax.php?prd=" + id_number + "&stock=" + this.value , true) ;
					req.send(null) ;
				}
				sumSubtotals() ;
			}
		}
	}

	function sumSubtotals(){

		var table = $('products-cart') ;
		var total = parseInt(0) ;

		for(var j = 0 ; j < table.rows.length ; j++){
			for(var k = 0 ; k < table.rows[j].cells.length ; k++){

				var cell = table.rows[j].cells[k] ;

				if(cell.id.split('-')[0] == 'subtotal'){

					var inner_subtotal = cell.innerHTML ;

					var symbol = inner_subtotal.replace(_float, '') ;
					var price = inner_subtotal.replace(no_float, '') ;
					subtotal = parseFloat(parseFloat(price)) ;

					total += subtotal ;
				}
			}
		}
		$('total').innerHTML = '' + symbol + (total.toFixed(2)) ;
	}

	function initLogin(){

		var table = $('tbody_login') ;
		var inputs = table.getElementsByTagName('input') ;

		for(var i = 0 ; i < inputs.length ; i++){

			if(inputs[i].type == 'radio'){

				if(inputs[i].id == 'registered_true'){
					inputs[i].onclick = function(){
						$('_password').disabled = false ;
						$('div_captcha').style.display='';
					}
				}
				else{
					inputs[i].onclick = function(){
						$('_password').disabled = true ;
						$('_password').value = '' ;
						$('div_captcha').style.display='none';
					}
				}
			}
		}
	}

	function getPlace(region, area, zone, field){

		var container = field.parentNode ;

		var req = doAjax() ;

		if(req){
			req.onreadystatechange = function(){

				if(req.readyState == 4){

					container.innerHTML = req.responseText ;

					if(zone == -1){ $('_city').value = -1 ; }

					if(field.id == '_state'){ changePlace($('_state'), 0, $('_state').value, $('_city').value) ; }

					if($('_state').value == -1){ $('tr_optional_state').style.display = (ie ? 'block' : 'table-row') ; }
					else{ $('tr_optional_state').style.display = 'none' ; }

					if($('_city').value == -1){ $('tr_optional_city').style.display = (ie ? 'block' : 'table-row') ; }
					else{ $('tr_optional_city').style.display = 'none' ; }
				}
			}
			req.open("GET", shc_root + "ajax.php?rgn=" + region + "&area=" + area + "&zne=" + zone , true) ;
			req.send(null) ;
		}
	}

	function clearSelect(field){

		var newInner = $('_country').options[0].cloneNode(true) ;
		field.innerHTML = '' ;
		field.appendChild(newInner) ;
	}


	function changePlace(field, region_value, area_value, zone_value){

		var area		= $('_state')	;
		var zone		= $('_city')	;

		//--- when you change the country field ---//
		if(field.id == '_country' && region_value != 0){

			field.value = region_value ;
			getPlace(region_value, area_value, zone_value, area) ;
			area.disabled = false ;
		}
		else if(field.id == '_country' && region_value == 0){
			clearSelect(area)			;
			area.disabled		= true	;
			clearSelect(zone)			;
			zone.disabled		= true	;
		}

		//--- when you change the state field ---//
		if(field.id == '_state' && area_value != 0){
			field.value = area_value ;
			getPlace(region_value, area_value, zone_value, zone) ;
			zone.disabled = false ;
		}
		else if(field.id == '_state' && area_value == 0){
			zone.value	= true	;
			zone.disabled	= true	;
		}

		//--- when you change the city field ---//
		if(field.id == '_city'){
			if(zone_value == -1){
				$('tr_optional_city').style.display = (ie ? 'block' : 'table-row') ;
			}
			else{
				$('tr_optional_city').style.display = 'none' ;
			}
		}
	}

	function checkmail(input){
		var email = input.value ;
		if(email.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/)){
			input.style.borderColor = '#00ff00' ;
			return true ;
		}
		else{
			input.style.borderColor = '#ff0000' ;
			return false ;
		}
	}

















