// JavaScript Document
var inStock;


function resize(){
size = getWindowSize();
document.getElementById('contentTd').height = (size[1]-129)+'px';   //ff 126  opera 127  ie 129
document.getElementById('contentTd').style.width = (size[0]-160-160-10)+'px';
tol = 20;

/*if (document.getElementById('homeDiv')){
	document.getElementById('homeDiv').style.height = (size[1]-120-9-150)+'px';
	document.getElementById('promotionTd').style.width = '240px';
}

if (document.getElementById('gridDiv')){
	document.getElementById('gridDiv').style.height = (size[1]-175-27)+'px';
}

if (document.getElementById('pageDiv')){
	//document.getElementById('pageDiv').style.height = (size[1]-175)+'px';
}*/

if (document.getElementById('markerFullTop')){

	a = getPixelsFromTop(document.getElementById('markerFullTop'));
	b = getPixelsFromTop(document.getElementById('markerFullBottom'));
	var fullHeight = b - a;
	
	if (document.getElementById('markerTop1')){
		e = getPixelsFromTop(document.getElementById('markerTop1'));
		f = getPixelsFromTop(document.getElementById('markerTop2'));
		top = f - e;
	}else{var top = 0;}
	
	if (document.getElementById('markerBottom1')){
		c = getPixelsFromTop(document.getElementById('markerBottom1'));
		d = getPixelsFromTop(document.getElementById('markerBottom2'));
		bottom = d - c;
	}else{var bottom = 0;}		
	contentHeight = document.getElementById('contentTd').height - top - bottom-8; 
	document.getElementById('mainContentTable').height = document.getElementById('contentTd').height+'px';
	document.getElementById('contentDiv').style.height = contentHeight+'px';
}
}

function getPixelsFromTop(obj){
	objFromTop = obj.offsetTop;
	while(obj.offsetParent!=null) {
		objParent = obj.offsetParent;
		objFromTop += objParent.offsetTop;
		obj = objParent;
	}
	return objFromTop;
}

/*function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth,myHeight];
}*/

function center(obj){
		var windowSize = getWindowSize();
		var scrolly;
		if (document.documentElement.scrollTop){scrolly = document.documentElement.scrollTop;}
		if (window.pageYOffset){scrolly = window.pageYOffset;}
		if (scrolly == undefined){scrolly = 0;}
		obj.style.top = ((windowSize[1]/2)-(obj.offsetHeight/2)+scrolly)+'px';	
		obj.style.left = ((windowSize[0]/2)-(obj.offsetWidth/2))+'px';
	}
	

	function getWindowSize() {
	var windowHeight = 0;
		if (typeof(window.innerHeight) == 'number') {
			windowHeight = window.innerHeight;
		}
		else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			}
			else {
				if (document.body && document.body.clientHeight) {
					windowHeight = document.body.clientHeight;
				}
			}
		}
		
	 var windowWidth = 0;
		if (typeof(window.innerWidth) == 'number') {
			windowWidth = window.innerWidth;
		}
		else {
			if (document.documentElement && document.documentElement.clientWidth) {
				windowWidth = document.documentElement.clientWidth;
			}
			else {
				if (document.body && document.body.clientWidth) {
					windowWidth = document.body.clientWidth;
				}
			}
		}	
		return Array(windowWidth,windowHeight);
	}
	
	var interval;
	var toWidth;
	var toHeight;
	
	function float(id,width,height){
	var floater = document.getElementById('floater');
	var shadow = document.getElementById('shadow');
	shadow.style.display = 'block';
	toWidth = width;
	toHeight = height;
	center(floater);
	getData(id,width,height);
	floater.style.visibility = 'visible';
	interval = setInterval(grow,50);
	}
	
	function bubble(id,obj){
	var bubble = document.getElementById('bubble');
	var correct = 0;
	//position on cursor
	var windowSize = getWindowSize();
	var position = findPos(obj);
	if (position[1] > (windowSize[1]-160)){
		correct = -160;
	}
	bubble.style.top = position[1]+correct+'px';
	bubble.style.left = position[0]+80+'px';
	fillBubble(id);
	bubble.style.visibility = 'visible';
	}
	
	function closeBubble(){
	var bubble = document.getElementById('bubble');
	bubble.style.visibility = 'hidden';
	bubble.innerHTML = "";
	}
	
	function grow(){
	var floater = document.getElementById('floater');
	var content = document.getElementById('floaterContent');
	
		floater.style.height = Math.ceil(parseInt(floater.offsetHeight) + parseInt(((toHeight-floater.offsetHeight)/3)))+'px';
		floater.style.width = Math.ceil(parseInt(floater.offsetWidth) + parseInt(((toWidth-floater.offsetWidth)/3)))+'px';
		content.style.height = Math.ceil(parseInt(content.offsetHeight) + parseInt(((toHeight-43-43-content.offsetHeight)/3)))+'px';
		content.style.width = Math.ceil(parseInt(content.offsetWidth) + parseInt(((toWidth-43-43-content.offsetWidth)/3)))+'px';
		//document.getElementById('debug').innerHTML = document.getElementById('debug').innerHTML + "<br>Height:"+floater.offsetHeight+"-"+((100-floater.offsetHeight)/2);
	center(floater);
		if (floater.offsetHeight >= (toHeight-2)){
			clearInterval(interval);
		}
	}
	
	function close(){
	var floater = document.getElementById('floater');
	var content = document.getElementById('floaterContent');
	var shadow = document.getElementById('shadow');
	//var productTable = document.getElementById('productTable');
	//productTable.style.width = "";
	//productTable.style.height = "";
	content.innerHTML = "";
	floater.style.visibility = 'hidden';
	shadow.style.display = 'none';
	floater.style.height = "";
	floater.style.width = "";
	content.style.height = "";
	content.style.width = "";
	floater.style.top = "";
	floater.style.left = "";
	}
	
	function getData(id,width,height){
	var content = document.getElementById('floaterContent');

	content.innerHTML = "<img src='templates/template1/loading.gif' border='0'/>";
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			content.innerHTML = ajaxRequest.responseText;
		}
	}

	ajaxRequest.open("GET", "./content.php?location=answerQuestion&id="+id, true);
	ajaxRequest.send(null); 
	}
	
	function fillBubble(id){
	var bubble = document.getElementById('bubble');

	bubble.innerHTML = "<img src='templates/template1/loading.gif' border='0'/>";
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			bubble.innerHTML = ajaxRequest.responseText;
			//var productTable = document.getElementById('productTable');	
			//productTable.style.width = (width-86)+'px';
			//productTable.style.height = (height-86)+'px';
		}
	}

	ajaxRequest.open("GET", "content.php?location=prodPic&id="+id, true);
	ajaxRequest.send(null); 
	}
	
	function searchSite(){
		var searchField = document.getElementById('tags');
		if (searchField.value == ""){
			alert('Debes especificar que vas a buscar');
		}else{
			location = '?location=products&tags='+searchField.value;
		}
	}
	
	function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
	}
	
	
	function askQuestion(){
	var content = document.getElementById('floaterContent');
	var name = document.getElementById('name');
	var tel = document.getElementById('tel');
	var email = document.getElementById('email');
	var question = document.getElementById('question');

	//content.innerHTML = "<img src='templates/template1/loading.gif' border='0'/>";
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			content.innerHTML = ajaxRequest.responseText;
		}
	}

	message.innerHTML = "";	
	error="";

	if (name.value == ""){
		error = "Debes ingresar tu nombre.<br>";
	}
	
	if (email.value == ""){
		error = error+"Debes ingresar tu email.<br>";
	}
	
	if (question.value == ""){
		error = error+"Debes ingresar una pregunta.<br>";
	}
	
	if (error == ""){
		ajaxRequest.open("GET", 'content.php?location=askQuestion&name='+name.value+'&email='+email.value+'&tel='+tel.value+'&question='+question.value+'', true);
		ajaxRequest.send(null);
	}else{
		message.innerHTML = error;
	} 
	}
	
	
	function login(){
	var username = document.getElementById('username');
	var password = document.getElementById('password');
	
		if (username.value != "" && password.value != ""){
			document.loginForm.action = window.location.href;
			document.loginForm.submit();
		}	
	}
	
	function logMyAccount(){
			document.logMyAccount.submit();
	}
	
	function doCupon(user){
		var cuponValue = document.getElementById('cuponValue');
		if (cuponValue != ""){
			document.cuponForm.submit();	
		}
	}
	
	
	function decrease(id,user){
	var itemQuantity = document.getElementById('Q'+id).value;
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){//alert(ajaxRequest.responseText);
			if (ajaxRequest.responseText == "1"){
				location = window.location.href;		
			}else{
				alert('No es posible comunicarse con el servidor. Por favor revisa tu conexion.');
			}
		}
	}

	ajaxRequest.open("GET", "cart.php?cartAction=subItem&id="+id+"&itemQuantity="+itemQuantity+'&userId='+user, true);
	ajaxRequest.send(null); 
	}
	
	function increase(id,user){
	var itemQuantity = document.getElementById('Q'+id).value;
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){//alert(ajaxRequest.responseText);
		var temp = ajaxRequest.responseText.split("|");
		
			if (ajaxRequest.responseText == "1"){
				location = window.location.href;		
			}else if(ajaxRequest.responseText == "outOfStock"){
				alert('out of stock');
			}else if(temp[0] == "remaining"){
				alert('Solo tenemos '+temp[1]+' unidades disponibles en el momento');	
			}else{
				alert('No es posible comunicarse con el servidor. Por favor revisa tu conexion.');
			}
		}
	}

	ajaxRequest.open("GET", "cart.php?cartAction=addItem&id="+id+"&itemQuantity="+itemQuantity+'&userId='+user, true);
	ajaxRequest.send(null); 
	}
	
	function addItem(id,user){
	var itemQuantity = document.getElementById(id+'Quantity').value;
	var ajaxRequest;
	if (itemQuantity > 0){
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){//alert(ajaxRequest.responseText);
		var temp = ajaxRequest.responseText.split("|");
		
			if (ajaxRequest.responseText == "1"){
				location = window.location.href;		
			}else if(ajaxRequest.responseText == "outOfStock"){
				alert('out of stock');
			}else if(temp[0] == "remaining"){
				alert('Solo tenemos '+temp[1]+' unidades disponibles en el momento');	
			}else{
				alert('No es posible comunicarse con el servidor. Por favor revisa tu conexion.');
			}
		}
	}

	ajaxRequest.open("GET", "cart.php?cartAction=addItem&id="+id+"&itemQuantity="+itemQuantity+"&fromContent=1&userId="+user, true);
	ajaxRequest.send(null); 
	}else{
		alert('Debes ingresar la cantidad de unidades que deseas agregar al carrito');	
	}
	}
	
	function emptyCart(user){
	var empty = confirm('Estas seguro que deseas vaciar tu carrito?');
	if (empty){
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){//alert(ajaxRequest.responseText);
			if (ajaxRequest.responseText == "1"){
				location = window.location.href;		
			}else{
				alert('No es posible comunicarse con el servidor. Por favor revisa tu conexion.');
			}
		}
	}

	ajaxRequest.open("GET", "cart.php?cartAction=emptyCart&userId="+user, true);
	ajaxRequest.send(null);
	}
	}
	
	function perPage(str){
		var sel = document.getElementById('perPage');
		location = str+sel.options[sel.selectedIndex].value;	
	}
	
	function orderBy(str){
		var sel = document.getElementById('orderBy');
		location = str+sel.options[sel.selectedIndex].value;	
	}
	
	function orderDir(str){
		var sel = document.getElementById('orderDir');
		location = str+sel.options[sel.selectedIndex].value;	
	}
	
	function passwordRate(id){
		var test = 0;	
		var field = document.getElementById(id);
		var feedBack = document.getElementById('passwordRating');

		var filter = /[a-z]/;
		if (filter.test(field.value)){test = test + 2;}
		var filter = /[A-Z]/;
		if (filter.test(field.value)){test = test + 2;}
		var filter = /[0-9]/;
		if (filter.test(field.value)){test = test + 2;}
		
		test += field.value.length-6;		
	
		
		var fullWidth = 100;
		var coef = fullWidth/10;
		var val = coef*test;
		var empty = fullWidth - val;
		var color = "";
		if (test <= 1){color = "#ff0000";}
		if (test == 2){color = "#ff6600";}
		if (test == 3){color = "#ff6600";}
		if (test == 4){color = "#ff9900";}
		if (test == 5){color = "#ffcc00";}
		if (test == 6){color = "#ffff33";}
		if (test == 7){color = "#ccff00";}
		if (test == 8){color = "#99ff00";}
		if (test == 9){color = "#66ff00";}
		if (test > 9){color = "#33cc00";}
		feedBack.innerHTML = "<font color='#000000'>Nivel de Seguridad<br></font>";
		feedBack.innerHTML += "<table class='passwordRating' width='"+fullWidth+"px' height='20px'><tr><td width='"+val+"px' bgcolor='"+color+"'></td><td width='"+empty+"px'></td></tr></table>";
	}
	
	
	function fastCartPreview(){
	var bubble = document.getElementById('fastCartPreviewWindow');
	var id = document.getElementById('fastNip').value;
	var fastWarning = document.getElementById('fastWarning');
	fastWarning.innerHTML = "";
	
	if (id != ""){
	
	bubble.innerHTML = "<img src='templates/template1/loading.gif' border='0'/>";
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var response = ajaxRequest.responseText.split("|");
			bubble.innerHTML = response[0];
			inStock = response[1];
		}
	}

	ajaxRequest.open("GET", "content.php?location=product&fastCartNip="+id, true);
	ajaxRequest.send(null);
	}
	}
	
	function fastAdd(user){

	var bubble = document.getElementById('fastCartPreviewWindow');
	var id = document.getElementById('fastNip').value;
	var q = document.getElementById('fastQ').value;
	var fastWarning = document.getElementById('fastWarning');
	fastWarning.innerHTML = "";
	var rxp = /^[0-9]*$/;
	var warning = "";
	
	if (id.search(rxp) == -1){
		warning = "Debes especificar un NIP valido.<br>";
	}else if (id == ""){
		warning += "Debes especificar un NIP.<br>";
	}
	
	if (q.search(rxp) == -1){
		warning += "Debes especificar una cantidad valida.<br>";
	}else if (q == ""){
		warning += "Debes especificar una cantidad.<br>";
	}
	
	/*else if(inStock == 0){
		warning += "El producto esta agotado.";	
	}else if (q > inStock){
		warning += "En el momento tenemos "+inStock+" Unidades.";	
	}*/
	
	if (warning == ""){
	//bubble.innerHTML = "<img src='templates/template1/loading.gif' border='0'/>";
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	// Create a function that will receive data sent FROM ".$DB_PREFIX."the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){//alert(ajaxRequest.responseText);
			//bubble.innerHTML = ajaxRequest.responseText;
			//fastWarning.innerHTML = "<font color='#009900'><b>"+q+" unidades fueron agregadas al carrito.</font>";
			var temp = ajaxRequest.responseText.split("|");
			
			if (ajaxRequest.responseText == "1"){
				location = window.location.href;		
			}else if(ajaxRequest.responseText == "outOfStock"){
				fastWarning.innerHTML = "El producto esta agotado.";
			}else if(temp[0] == "remaining"){
				fastWarning.innerHTML = "En el momento tenemos "+temp[1]+" unidades.";
			}else{
				alert('No es posible comunicarse con el servidor. Por favor revisa tu conexion.');
			}
		}
	}

	ajaxRequest.open("GET", "cart.php?cartAction=addItem&nip="+id+"&itemQuantity="+q+"&fromContent=1&userId="+user, true);
	ajaxRequest.send(null);
	}else{
		fastWarning.innerHTML = warning;
	}

	}
	
	
	
	function spreadTheWord(){
	var email = document.getElementById('regSpreadTheWord');
	var div = document.getElementById('spreadTheWordDiv');
	var warningDiv = document.getElementById('spreadTheWordWarningDiv');
	
	//bubble.innerHTML = "<img src='templates/template1/loading.gif' border='0'/>";
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){//alert(ajaxRequest.responseText);
			var temp = ajaxRequest.responseText.split("|");
			
			if (temp[0] == "1"){
				div.innerHTML = "Gracias! "+email.value+" recibira una invitacion a D'oro!";		
			}else if(temp[0] == "0"){
				switch(temp[1]){
					case "exists":
						warningDiv.innerHTML = email.value+" ya fue notificado!";
					break;
					
					case "notValidEmail":
						warningDiv.innerHTML = "<font color='#FF0000'><b>Debes ingresar un correo valido</font>";
					break;
					
					default:
						warningDiv.innerHTML = "<font color='#FF0000'><b>Error de Comunicacion, intenta mas tarde</font>";
					break;
				}
			}else{
				alert('OOPS!, parece haber un error en la conexion. Por favor intentalo mas tarde.');	
			}
		}
	}

	ajaxRequest.open("GET", "content.php?location=spreadTheWord&email="+email.value, true);
	ajaxRequest.send(null);
	}
	
	
	
	function newsletter(){
	var email = document.getElementById('regNewsletter');
	var div = document.getElementById('newsletterDiv');
	var warningDiv = document.getElementById('newsletterWarningDiv');
	
	//bubble.innerHTML = "<img src='templates/template1/loading.gif' border='0'/>";
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){//alert(ajaxRequest.responseText);
			var temp = ajaxRequest.responseText.split("|");
			
			if (temp[0] == "1"){
				div.innerHTML = "Gracias "+email.value+"!, De hoy en adelante recibiras informacion y promociones de D'oro!";		
			}else if(temp[0] == "0"){
				switch(temp[1]){
					case "exists":
						warningDiv.innerHTML = email.value+" ya esta inscrito!";
					break;
					
					case "notValidEmail":
						warningDiv.innerHTML = "<font color='#FF0000'><b>Debes ingresar un correo valido</font>";
					break;
					
					default:
						warningDiv.innerHTML = "<font color='#FF0000'><b>Error de Comunicacion, intenta mas tarde</font>";
					break;
				}
			}else{
				alert('OOPS!, parece haber un error en la conexion. Por favor intentalo mas tarde.');	
			}
		}
	}

	ajaxRequest.open("GET", "content.php?location=newsletterSubscribe&email="+email.value, true);
	ajaxRequest.send(null);
	}
	
/*function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 return [myWidth,myHeight];
}*/
	
	document.onmousemove = setFastPreviewPosition;
	function setFastPreviewPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
	if (document.getElementById('bubble')){
		winSize = getWindowSize();
		limit = winSize[1]-300;
		
		if (cursor.y > limit){
			dy = limit-cursor.y;
			document.getElementById('bubble').style.top = (cursor.y+dy)+'px';
		}else{
			document.getElementById('bubble').style.top = cursor.y+'px';
		}
	}
   // return cursor;
	}

	
	

var pos = 0;	
function move(){
	pos++;
	if (pos+35 > document.getElementById('scrollerText').scrollHeight){
		pos = 0;	
	}
	document.getElementById('scroller').scrollTop = pos;
}
  
function move_up() {
	setInterval('move()',100);
	//alert(document.getElementById('scrollerText').scrollHeight);
}

function paymentType(type){
	switch (type){
		case 'CC':
			document.getElementById('checkOutFormCC').style.display = 'block';
			document.getElementById('checkOutFormDB').style.display = 'none';
			document.getElementById('checkOutFormTB').style.display = 'none';
		break;
		
		case 'DB':
			document.getElementById('checkOutFormCC').style.display = 'none';
			document.getElementById('checkOutFormDB').style.display = 'block';
			document.getElementById('checkOutFormTB').style.display = 'none';
		break;
		
		case 'TB':
			document.getElementById('checkOutFormCC').style.display = 'none';
			document.getElementById('checkOutFormDB').style.display = 'none';
			document.getElementById('checkOutFormTB').style.display = 'block';
		break;
	}
}

function pay(type,key){
	if ((type=='CC' && document.getElementById('regAgree').checked == true) || type!='CC'){
	
	var ajaxRequest;  
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('error - your browser does not support ajax technology');
				return false;
			}
		}
	}
		
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){//alert(ajaxRequest.responseText);
		var temp = ajaxRequest.responseText.split("|");
			
			if (temp[0] == "1"){
				document.location.href = temp[1];		
			}else if(temp[0] == "0"){
				document.getElementById('warning').innerHTML = "<font color='#FF0000'><b>"+temp[1];
				document.getElementById('payCCBtn').disabled = false;
			}else{
				alert('OOPS!, parece haber un error en la conexion. Por favor intentalo mas tarde.');	
				document.getElementById('payCCBtn').disabled = false;
			}
		}
	}

var str = "";	
switch (type){
//get data to send	
	case 'CC':
		var type = document.getElementById('regCardType').options[document.getElementById('regCardType').selectedIndex].value;
		var emisor = document.getElementById('regEmisor').value;		
		var cardNumber = crypt(document.getElementById('regCardNumber').value,key);		
		var cardName = document.getElementById('regCardName').value;		
		var month = document.getElementById('regMonth').options[document.getElementById('regMonth').selectedIndex].value;
		var year = document.getElementById('regYear').options[document.getElementById('regYear').selectedIndex].value;
		var code = document.getElementById('regCardCode').value;
		
		str = "regPaymentType=CC&regCardType="+type+"&regEmisor="+emisor+"&regCardNumber="+cardNumber+"&regCardName="+cardName+"&regMonth="+month+"&regYear="+year+"&regCardCode="+code;
	break;
	
	case 'DB':
	str = "regPaymentType=DB";
	break;
	
	case 'TB':
	str = "regPaymentType=TB";
	break;
}
ajaxRequest.open("GET", "cart.php?cartAction=pay&"+str, true);
ajaxRequest.send(null);
document.getElementById('payCCBtn').disabled = true;
	}else{
		alert("Para pagar tu pedido con tarjeta de credito por favor selecciona el recuadro \"Acepto los terminos y condiciones de venta\" ");	
	}
}

function crypt(string,key){
	var str = string;
	
	return str;
}

function popup(url){
	popupWindow = window.open(url, "DetalledelProducto", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300px,height=400px");
}

function fillShipping(){
if (document.getElementById('fillShippingCheckbox').checked == true){
	document.getElementById('regShippingName').value = document.getElementById('regBillingName').value;
	document.getElementById('regShippingRFC').value = document.getElementById('regBillingRFC').value;
	document.getElementById('regShippingContact').value = document.getElementById('regBillingContact').value;
	document.getElementById('regShippingAddress').value = document.getElementById('regBillingAddress').value;
	document.getElementById('regShippingColony').value = document.getElementById('regBillingColony').value;
	
	document.getElementById('regShippingCity').value = document.getElementById('regBillingCity').value;
	document.getElementById('regShippingState').selectedIndex = document.getElementById('regBillingState').selectedIndex;
	document.getElementById('regShippingPhoneCode').value = document.getElementById('regBillingPhoneCode').value;
	document.getElementById('regShippingPhone').value = document.getElementById('regBillingPhone').value;
	document.getElementById('regShippingFaxCode').value = document.getElementById('regBillingFaxCode').value;
	document.getElementById('regShippingFax').value = document.getElementById('regBillingFax').value;
}else{
	document.getElementById('regShippingName').value = "";
	document.getElementById('regShippingRFC').value = "";
	document.getElementById('regShippingContact').value = "";
	document.getElementById('regShippingAddress').value = "";
	document.getElementById('regShippingColony').value = "";
	
	document.getElementById('regShippingCity').value = "";
	document.getElementById('regShippingState').selectedIndex = 0;
	document.getElementById('regShippingPhoneCode').value = "";
	document.getElementById('regShippingPhone').value = "";
	document.getElementById('regShippingFaxCode').value = "";
	document.getElementById('regShippingFax').value = "";
}
}


function showHelp(){
	var h = document.getElementById('help');
	center(h);
	h.style.visibility = 'visible';
}

function closeHelp(){
	var h = document.getElementById('help');
	
	h.style.visibility = 'hidden';
}

function showTerms(){
	var h = document.getElementById('terms');
	center(h);
	h.style.visibility = 'visible';
}

function closeTerms(){
	var h = document.getElementById('terms');
	
	h.style.visibility = 'hidden';
}

function showFreeDescription(){
	var h = document.getElementById('freeDescription');
	center(h);
	h.style.visibility = 'visible';
}

function closeFreeDescription(){
	var h = document.getElementById('freeDescription');
	
	h.style.visibility = 'hidden';
}