// JavaScript Document
/*
Open Centered Popup Window Script-
© DHTML Shock (www.dhtmlshock.com)
To add more shock to your site, visit www.DHTML Shock.com
*/
function OpenBrWindow(theURL,winName,features,myWidth,myHeight,isCenter){//v3.0
if(window.screen)if(isCenter)if(isCenter=="true"){
var myLeft=(screen.width-myWidth)/2;
var myTop=(screen.height-myHeight-120)/2;
features+=(features!='')?',':'';
features+=',left='+myLeft+',top='+myTop;
}
window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
function RefrescarCerrar()
{
window.opener.location.reload();
window.close()
}
function CerrarVentana()
{
window.close()
}
function RedireccionarCerrar(r_url)
{
window.opener.location=r_url;
window.close()
}

function toggleDisplay() {
var elements = Array.prototype.slice.call(arguments);
arrayEach(elements, function (arg) {
var element = ref(arg);
if (element) {
element.style.display = (element.style.display != "none" ? "none" : "");
}
});
}

function toggleDispOnLoad(r_id_bloc, r_cookie){
	//var elements = Array.prototype.slice.call(arguments);
	//alert(elements);
	//arrayEach(elements, function (arg) {
		//var element = ref(arg);
		
		if (Get_Cookie(r_cookie)==0){
			//element.style.display="none";
			document.getElementById(r_id_bloc).style.display="none";
			document.getElementById(r_id_bloc+'open').style.display="none";
			document.getElementById(r_id_bloc+'closed').style.display="";
		}else{
			//alert(arg);
			//element.style.display="";
			document.getElementById(r_id_bloc).style.display="";
			document.getElementById(r_id_bloc+'open').style.display="";
			document.getElementById(r_id_bloc+'closed').style.display="none";
		}
	//});
}

function arrayEach(array, func) {
for (var i = 0; i < array.length; i++) func(array[i]);
}

function ref(instance_or_id) {
return (typeof(instance_or_id) == "string") ? document.getElementById(instance_or_id) : instance_or_id;
}

// onclick="Set_Cookie( 'IdIngredientOpen' , '{{IdIngredient}}' , 0 , '/' , false );"
function Set_Cookie(name,value,expires,path,domain,secure) {
	var cookieString = name + "=" +escape(value) +
   ( (expires) ? ";expires=" + expires.toGMTString() : "") +
   ( (path) ? ";path=" + path : "") +
   ( (domain) ? ";domain=" + domain : "") +
   ( (secure) ? ";secure" : "");
	document.cookie = cookieString;
}

//t.SetVariable "OpenedFolders", "<script type='text/javascript'>toggleDispOnLoad('d'+Get_Cookie('IdIngredientOpen'));"
function Get_Cookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
} 
function tczShowAjaxJQ(sUrl, DIVdestino){
	$.ajax({
		method:"get",url: sUrl,
		//beforeSend: function(){$("#loading").show("fast");}, //show loading just when link is clicked
		//complete: function(){ $("#loading").hide("fast");}, //stop showing loading when the process is complete
		success:function(html){
			//$("#"+DIVdestino).slideDown("fast"); //animation
			$("#"+DIVdestino).html(html);
			//$("#"+DIVdestino).effect("highlight", {}, 2000);
			//$("span[title]").tooltip({tip:'.tooltip',effect:"slide",fadeOutSpeed:100,predelay:400,position:"bottom right",offset: [-50, -50]}).dynamic();
			$('#AjaxForm').validate();
		}
	});
}

function load_google_map(r_initLat,r_initLong) {
	if (GBrowserIsCompatible()){
        var map = new GMap2(document.getElementById("GMap"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        var center = new GLatLng(r_initLat,r_initLong);
        map.setCenter(center,16);
        geocoder = new GClientGeocoder();
        var marker = new GMarker(center, {draggable: false});  
        map.addOverlay(marker);
	}
}
