// Javascript para Que Comer

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


// Funcion para manejar la navegacion cruzada por tipo y zona
function catsubmit(targetForm){
	var cat1 = document.catnavform.cat1.value;
	var cat2 = document.catnavform.cat2.value;
	
	if(cat1 == "" && cat2 == ""){
		return false;
	}
	else{
		if(cat1 == "" || cat2 == ""){
			if(cat1 == ""){
				document.location.href='/c/'+cat2;
			}
			else{
				document.location.href='/c/'+cat1;
			}
		}
		else{
			document.location.href='/c/'+cat1+cat2;
		}
	}
}



function submitDonMenuColonia(){
	var colonia = document.donmenu.colonia.value;
	window.open('http://donmenus.com/colonias/'+colonia+'/sucursales/?bf4e=qcomr&vm=vpp');
}

function submitDonMenu(){
	document.donmenu.submit();
}


function verDonMenu(url){
	var winOrdena = null;
	settings = "width=" + screen.availWidth + ",height=" + screen.availHeight + ",top=0,left=0,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	winOrdena = window.open('','ordenaframe',settings);

	// write frameset to new window
	winOrdena.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	winOrdena.document.write('<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="es-ES">');
	winOrdena.document.write('<head>');
	winOrdena.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
	winOrdena.document.write('<title>Ver Men&uacute; · Qué Comer · Guía de Restaurantes de Monterrey N.L. México</title>');
	winOrdena.document.write('<link rel="stylesheet" href="http://www.quecomer.com/wp-content/themes/quecomer960/style.css" type="text/css" media="screen" />');
	winOrdena.document.write('</head>');
	winOrdena.document.write('<frameset rows="41,*" frameborder="no" framspacing="0" border="0">');
	winOrdena.document.write('<frame name="outside_top" src="http://www.quecomer.com/wp-content/themes/quecomer960/frames/top.html" scrolling="no" border="0" marginheight="0" marginwidth="0">');
	winOrdena.document.write('<frame name="outside_bottom" src="'+url+'">');
	winOrdena.document.write('</frameset>');
	winOrdena.document.write('</body>');
	winOrdena.document.write('</html>');
}


function getDonMenuSelects(){
	var municipio = document.donmenu.municipio.value;
	jQuery('#colonia').replaceWith('<select name="colonia" id="colonia"><option value="">Cargando...</option></select>');
	jQuery.get("/wp-content/themes/quecomer960/dm_select.php", { municipio: document.donmenu.municipio.value },
		function(data){
	    	jQuery('#colonia').replaceWith(data);
	    }
	);
}


// http://www.ajaxray.com/blog/2007/11/08/jquery-controlled-dependent-or-cascading-select-list-2/
function makeSublist(parent,child,isSubselectOptional,childVal){
	jQuery("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	jQuery('#'+parent+child).html(jQuery("#"+child+" option"));
	
		var parentValue = jQuery('#'+parent).attr('value');
		jQuery('#'+child).html(jQuery("#"+parent+child+" .sub_"+parentValue).clone());
	
	childVal = (typeof childVal == "undefined")? "" : childVal ;
	jQuery("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');
	
	jQuery('#'+parent).change( 
		function(){
			var parentValue = jQuery('#'+parent).attr('value');
			jQuery('#'+child).html(jQuery("#"+parent+child+" .sub_"+parentValue).clone());
			if(isSubselectOptional) jQuery('#'+child).prepend("<option value='none'> -- Select -- </option>");
			jQuery('#'+child).trigger("change");
                        jQuery('#'+child).focus();
		}
	);
}

