function submitonce(valor){
	if (valor==1) {
		document.getElementById('SubmitButton').style.display="none"
		document.getElementById('ProcessMsg').style.display="block"
	} else {
		document.getElementById('SubmitButton').style.display="block"
		document.getElementById('ProcessMsg').style.display="none"
	}
}

// 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,r_zoom){
	if (GBrowserIsCompatible()){
		if(r_zoom==undefined){r_zoom=15;}
        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,parseFloat(r_zoom));
        geocoder = new GClientGeocoder();
        var marker = new GMarker(center, {draggable: false});  
        map.addOverlay(marker);
	}
}

function TczJQWindowUpload(sUrl,r_width,r_title,r_id_item,r_url_dest,r_IdDivDest,r_type){
	/*$.blockUI({css:{
		border:'none',padding:'15px',backgroundColor:'#000', 
		'-webkit-border-radius':'10px','-moz-border-radius':'10px',opacity: .8,color: '#fff'},
		overlayCSS:{opacity:0},
		message:'<p>Obteniendo datos...</p>'
	}); */
	$('#Dialogo').load(sUrl,function(){
	$('#Dialogo').dialog({
		title:r_title,
		width:r_width,
		resizable:false,
		modal:true,
		open:function(){
			//$.unblockUI();
			if($('#uploadify').length){
				$('#uploadify').uploadify({
				uploader:'/js/jquery.uploadify-v2.1.0/uploadify.swf',
				script:'/js/jquery.uploadify-v2.1.0/uploadify.php',
				scriptData:{'type': r_type,'id_item': r_id_item},
				cancelImg:'/js/jquery.uploadify-v2.1.0/cancel.png',
				folder:'/media',
				queueID:'fileQueue',
				auto:true,
				multi:false,
				onError:function(a, b, c, d) {
					//if (d.status == 404)alert('Could not find upload script. Use a path relative to: <?= getcwd() ?>');
					//else if (d.type === "HTTP")alert('error '+d.type+': '+d.status);
					//else if (d.type ==="File Size")alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
					//else alert('error '+d.type+': '+d.text);
					alert('error '+d.type+': '+d.info);
				},
				//alert('Error al subir el archivo'+d.type + ': ' + d.info)},
				onAllComplete:function(){
					$.ajax({
					method:"get",url: r_url_dest,
					success:function(html){
						$("#"+r_IdDivDest).html(html);
  						
						}
					});
					$('#Dialogo').dialog('close');
					$('#Dialogo').dialog('destroy');
				}
				});
			}
		},
		close:function(){$(this).dialog('destroy');}
    });
});
}

function ConfirmActionJQ(sUrl, DIVdestino){
	var dialog=$('<div>&iquest; Eliminar los elementos seleccionados ?</div>').insertAfter('#Dialogo');
	$(dialog).dialog({
		title:'Atenci&oacute;n',
		resizable:false,
		modal:true,
		buttons:{
			'Eliminar': function(){
				var arr_IdItemsD=[]; 
				$('input:checkbox:checked').each(function(){arr_IdItemsD.push($(this).val());}); 
				tczShowAjaxJQ(sUrl,DIVdestino);
				$(this).dialog('close');
				return false;
			},
			Cancel: function() {
				$(this).dialog('close');
			}
		}
	});
}

function JQAjaxPost(r_URL, r_divDest, r_type){
	//r_fields=r_fields.replace(',','","');
	//r_fields='"'+r_fields+'"';
	//alert(r_fields);
	//var aryTest=[r_fields];
	//var aryTest=r_fields.split(',');
	//var v_fields="{";
	//for (i=0;i<aryTest.length;i++){
	//alert(aryTest[i]+'_val');
	//document.write(aryTest[i]);
	//v_fields = v_fields+""+aryTest[i]+":\""+$("#"+aryTest[i]).val()+"\",";
	//}
	//var strLen = v_fields.length;
	//v_fields = v_fields.slice(0,strLen-1); 
	//v_fields=v_fields+"}";
	//alert(v_fields);
	//return false;
	$.post(r_URL,
		{id_ar:$("#id_ar").val(), is_submit:$("#is_submit").val(), from_email:$("#from_email").val(), to_email:$("#to_email").val(), aditional_message:$("#aditional_message").val()},
		function(data){
			$("#"+r_divDest).html(data);
		//$("#sendEmail").slideUp("normal", function() {
			//$("#"+r_divDest).before('<h1>Success</h1><p>Your email was sent.</p>');
		//}
		//);
	});  
}

jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};