var validator;
function aceptar(){
	generarValidador();
	if(validator.form()){
		call_bak("Add");
		//if (ret==true){
		//	form_ajax_files($("#ProductId").val());
		//	data="CatalogListView/"+$("#id").val()+"/"+$("#p").val()+"/"+$("#filters").val();
		//	call_bak(data);
		//}
	}
}

function generarValidador(){
	$("#summary").hide();
	$.validator.addMethod("uniqueField", function(value, element) {
			error=$("#field_taken").val();
			valido=false;
		   $('#method').val("uniqueField");
		   $.ajax({
	          /*type: "POST",*/
	          url: "ajax_operation.php",
	          cache: false,
	          async:false,
	          data: $('#f1').serialize()+ "&validator_field="+element.name+"&validator_value="+value,
	       success: function(data)
	       {
	          // if the user exists, it returns a string "true"
	          if(data == 1){
	          	$('#'+element.name+'_error').html(error);
	             valido= false;  // already exists
	          }
	          else{
	          	$('#'+element.name+'_error').html('');
		          valido= true;      // field is free to use
		      }
	       }
	     });
	     valido=1;
	     return valido;
	}, $("#field_taken").val());

	$.validator.addMethod("mayor18", function(value, element) {
	     if (CalAge(value)<18){
	     	valido=false;
	     }
	     else{
	     	valido=true;
	     }
	     return valido;
	},"Debe ser mayor a 18 a&ntilde;os");


	validator = $("#f1").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? '<p>You missed 1 field. It has been highlighted below</p>'
					: '<p>You missed ' + errors + ' fields.  They have been highlighted below</p>';
				$("#summary").html(message);
				$("#summary").show();
			} else {
				$("#summary").hide();
			}
		},

		errorPlacement: function(error, element) {
			if (error){
				$('#'+element.attr("id")+'_error').html(error);
				$('.'+element.attr("id")+'_error').html(error);
			}
			//alert(error.html);
			//error.appendTo( element.parent().next() );
			//error.appendTo( element);
		},
		highlight: function(element, errorClass) {
			$(element).addClass(errorClass);//.parent().prev().children("select").addClass(errorClass);
		},
		invalidHandler: function(e, validator2) {
	   		var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'El formulario contiene erorres. Por favor verifique que los datos sean ingresados en forma correcta.'
						: 'El formulario contiene erorres. Por favor verifique que los datos sean ingresados en forma correcta.';
					$("#summary").html("<div class='alert alert-danger error msg'>"+'<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>&nbsp;&nbsp;'+message+"</div>");
					$("#summary").show();
				} else {
					$("#summary").hide();
				}
			}
	});
}

/**
 * Concatenates the values of a variable into an easily readable string
 * by Matt Hackett [scriptnode.com]
 * @param {Object} x The variable to debug
 * @param {Number} max The maximum number of recursions allowed (keep low, around 5 for HTML elements to prevent errors) [default: 10]
 * @param {String} sep The separator to use between [default: a single space ' ']
 * @param {Number} l The current level deep (amount of recursion). Do not use this parameter: it's for the function's own use
 */
function print_r(x, max, sep, l) {

	l = l || 0;
	max = max || 10;
	sep = sep || ' ';

	if (l > max) {
		return "[WARNING: Too much recursion]\n";
	}

	var
		i,
		r = '',
		t = typeof x,
		tab = '';

	if (x === null) {
		r += "(null)\n";
	} else if (t == 'object') {

		l++;

		for (i = 0; i < l; i++) {
			tab += sep;
		}

		if (x && x.length) {
			t = 'array';
		}

		r += '(' + t + ") :\n";

		for (i in x) {
			try {
				r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1));
			} catch(e) {
				return "[ERROR: " + e + "]\n";
			}
		}

	} else {

		if (t == 'string') {
			if (x == '') {
				x = '(empty)';
			}
		}

		r += '(' + t + ') ' + x + "\n";

	}

	return r;

};
var_dump = print_r;



function form_ajax_files() {
	productId=$("#ProductIdSel").val();
	$.ajaxFileUpload({
			url:'doajaxfileupload.php?id='+$("#id").val()+'&ProductId='+productId+'&property_file_id='+$("#property_file_id").val()+'&property_file_tagname='+$("#property_file_tagname").val(),
			secureuri:false,
			cache: false,
			async:false,
			fileElementId:'property_'+$("#property_file_id").val(),
			success: function (data, status)
			{
				//alert(data);
			}
		})
}

function control_change(control){
	$('#property_'+control+'_error').html('');
}




function property_change(property_related, element, op){
	var miProp = new Array()
	i=0;
	if (call_property_validate(property_related)){
		$('.property_related_'+property_related).each(function(i) {
			miProp[i++]=$(this).val();
		});
	}
	for(i=0;i<miProp.length;i++){
		property_update(miProp[i], element.value, op);
	}
	if (op=='combo_filter') filter_search();
}

function property_update(id, rel,op){
	if ($("#AMBIENTE").val()=='FRONT'){
		url_p= $("#PATH_URL_MRW").val();
	}
	else{
		url_p= $("#SITE_URL_ADMIN").val();
	}
	$.ajax({
		url: url_p+"property?class=PAGeneric&method_property="+op+"&control_id="+$("#id").val()+"&CatalogPropertyId="+id+"&rel="+rel,
		async: false,
		data: $("#Frm1").serialize(),
		success: function(data){
			$("#"+op+"_"+id).html(data);
			$("."+op+"_"+id).html(data);
			/*if($("#company").hasClass('no_show')){
				$('#company :input').attr('disabled', true);
			}
			else{
				$('#basic_user :input').attr('disabled', true);
			}*/
		}
	});

}



function update_editor_control(){
	var editors = $("textarea.ckeditor");
    if (editors.length) {
        editors.each(function() {
            var editorID = $(this).attr("id");
            if (CKEDITOR){
            	if (CKEDITOR.instances[editorID]){
            		var instance = CKEDITOR.instances[editorID].updateElement();
            	}
            }
         });
    }
    
    var editors = $("textarea.ckeditor2");
    if (editors.length) {
        editors.each(function() {
            var editorID = $(this).attr("id");
            if (CKEDITOR){
            	if (CKEDITOR.instances[editorID]){
            		var instance = CKEDITOR.instances[editorID].updateElement();
            	}
            }
         });
    }
	
    
	var tags_list = $("input.tags_list");
    if (tags_list.length) {
        tags_list.each(function() {
        	 var tagid = $(this).attr("id");
        	 $(this).val(
        			$(".tagit-label",$("#"+tagid+"_list"))
        				.clone()
        				.text(function(index,text){ return (index == 0) ? text : "," + text; })
        				.text()
        		);
        	
        	/*
	       
	        alert(tagid);
	        $(this).val(
					$(".tagit-label",$(this))
						.clone()
						.text(function(index,text){ return (index == 0) ? text : "," + text; })
						.text()
				);
	        */
	      // $(this).val($("#"+tagid+"_list").tagit('tags'));
       });
    }
    
    $('#gallery_items').val('');	
    console.log("entro");
    $('.gallery-item').each(function(i) {
    	console.log($(this).attr("id"));
    	if ( $('#gallery_items').val()==''){
    		$('#gallery_items').val($(this).attr("id"));
    	}
    	else{
    		$('#gallery_items').val($('#gallery_items').val()+','+$(this).attr("id"));
    	}
    	if ($(this).hasClass('gallery_high')){
    		$('#gallery_high').val($(this).attr("id"));
    	}
    	 if (CKEDITOR){
    		 editorID="epigrafe_"+$(this).attr("id");
          	if (CKEDITOR.instances[editorID]){
          		data = CKEDITOR.instances[editorID].getData();
          		console.log(data);
          	}
          }
		
	});
		
	
   

    
    
    
    
}

function call_property_validate(property_id){
	if (!$("#validate_"+property_id).val())
		return true;
	var result=true;
	$("#selectedId").val(property_id);
	$.ajax({
		url: "ajax_operation.php?class=ModCatalogs&method=call_property_validate",
		data: $("#f1").serialize(),
		async:false,
		dataType: "json",
		success: function(data){
			if(data.result){
			}
			else{
				$("#property_"+property_id).val($("#oldvalue").val());
				alert(data.error);
				result=false;
			}
		}
	});
	return result;


}






function load_editor()
{
	
	
	 
	
	
	
	$(".cke_inline").each(function() {
		if (!$(this).hasClass("set_inline")){
			$(this).addClass("set_inline");
			CKEDITOR.inline( this);
		}
	});
	var $editors = $("textarea.ckeditor");

	    if ($editors.length) {
	        $editors.each(function() {
	        if(!$('#cke_'+$(this).attr("id")).length > 0){


        	   $(this).addClass('ckeditor-enabled')
		       var editorID = $(this).attr("id");
	            var instance = CKEDITOR.instances[editorID];
	            if (instance) { delete CKEDITOR.instances[editorID]; }
		            language= "es";
	              //if (language=='pr') language='pt-br';
	              if ($(this).hasClass("Basic")){
	              	tool="Basic";
	              	w=624;
	              	h=220;
	              }
	              else{
	              	tool="Full";
	              	w=800;
	              	h=350;
	              }
	              CKEDITOR.replace(editorID,{
					language: language,
					toolbar: tool,
					width:w,
					height:h
				});
	              
			}
	        });
	    }
	    
	    
	    var $editors = $("textarea.ckeditor2");

	    if ($editors.length) {
	        $editors.each(function() {
	        if(!$('#cke_'+$(this).attr("id")).length > 0){


        	   $(this).addClass('ckeditor-enabled')
		       var editorID = $(this).attr("id");
	            var instance = CKEDITOR.instances[editorID];
	            if (instance) { delete CKEDITOR.instances[editorID]; }
		            language= "es";
	              //if (language=='pr') language='pt-br';
	              if ($(this).hasClass("Basic")){
	              	tool="Basic";
	              	w=624;
	              	h=420;
	              }
	              else{
	              	tool="Full";
	              	w=800;
	              	h=350;
	              }
	              CKEDITOR.replace(editorID,{
					language: language,
					toolbar: tool,
					width:w,
					height:h
				});
	              
	             
			}
	        });
	    }


	//$('.ckeditor').ckeditor();

	//CKFinder.setupCKEditor( null, $("#SITE_URL_COMMON").val()+"www/extensions/ckfinder/" );


}

function limitChars(textarea, limit, infodiv)
{
	var text = textarea.value;
	var textlength = text.length;
	var info = document.getElementById(infodiv);

	if(textlength > limit)
	{
		info.innerHTML = 'No podes escribir mas de '+limit+' caracteres!';
		textarea.value = text.substr(0,limit);
		return false;
	}
	else
	{
		info.innerHTML = 'Te quedan '+ (limit - textlength) +' caracteres para escribir.';
		return true;
	}
}

function format(mail) {
		return mail.name + " &lt;" + mail.to + "&gt";
	}

function property_suggest(CatalogPropertyId,control) {
	id=$("#id").val();
	//	$("#PATH_URL_MRW").val()+:
	$("#"+control+"_"+CatalogPropertyId).autocomplete('ajax_autocomplete.php?id='+id+'&CatalogPropertyId='+CatalogPropertyId+'&Lang='+$("#Lang").val()+'&LangId='+$("#LangId").val(), {
		width: 260,
		multiple: true,
		mustMatch: true,
		autoFill: true,
		dataType: "json",
		parse: function(data) {
			return $.map(data, function(row) {
				return {
					data: row,
					value: row.Value,
					result: row.Value
				}
			});
		},
		formatItem: function(item) {
			$("#loading").hide();
			return item.Value;
		}
	});



}

function property_autocomplete(CatalogPropertyId,control) {

	id=$("#id").val();
	$("#"+control+"_"+CatalogPropertyId+"_autocomplete").autocomplete('ajax_autocomplete.php?id='+id+'&CatalogPropertyId='+CatalogPropertyId, {
		max: 800000000,
		mustMatch: true,
		matchContains: true,
		width: 260,
		selectFirst: false,
		dataType: "json",
		parse: function(data) {
			return $.map(data, function(row) {
				return {
					data: row,
					value: row.Value,
					result: row.Value
				}
			});
		},
		formatItem: function(item) {
			$("#loading").hide();
			return item.Value;
		}
	}).result(function(e, item) {
		$("#"+control+"_"+CatalogPropertyId).val(item.PropertyValueId);
		$("#loading").hide();
	});


}

function property_autocomplete_list() {
	if(document.f1.property_autocomplete){
		if(document.f1.property_autocomplete.value){
				property_autocomplete(document.f1.property_autocomplete.value,"property");
		}
		else{
			for(i=0; i<document.f1.property_autocomplete.length;i++) {
				property_autocomplete(document.f1.property_autocomplete[i].value,"property");
			}
		}
	}
	if(document.f1.filter_autocomplete){
		if(document.f1.filter_autocomplete.value){
				property_autocomplete(document.f1.filter_autocomplete.value,"filter");
		}
		else{
			for(i=0; i<document.f1.property_autocomplete.length;i++) {
				property_autocomplete(document.f1.filter_autocomplete[i].value,"filter");
			}
		}
	}
}

function property_suggest_list() {
	if(document.f1.property_suggest){
		if(document.f1.property_suggest.value){
				property_suggest(document.f1.property_suggest.value,"property");
		}
		else{
			for(i=0; i<document.f1.property_suggest.length;i++) {
				property_suggest(document.f1.property_suggest[i].value,"property");
			}
		}
	}

}



function catalog_export() {
	oIFrm = document.getElementById('myIFrm');
	oIFrm.src = 'catalog_export.php?'+$('#f1').serialize();
}

function get_product_log() {
	call_bak("get_product_log");
}

function property_file_link_add(id){
	$("#file_link_cant").val(parseInt($("#file_link_cant").val())+1);
	$("#class").val("Pfile_link");
	$("#method").val("property_file_link_add");
	$.ajax({
		url: "ajax_operation_property.php?id="+$("#id").val()+"&CatalogPropertyId="+id,
		async: false,
		data: $("#f1").serialize(),
		success: function(data){
			$("#new_url_file_"+id).html($("#new_url_file_"+id).html()+data);
			$("#property_"+id).val('');

		}
	});
}

function property_file_link_remove(id){
	$("#file_link_"+id).html('');

}


function load_uploadify()
{
	
	$('a.uploadify').each(function(){

		if (!$(this).hasClass('uploadify_set')){
			$(this).addClass('uploadify_set')
			id=$(this).attr('id').replace(/property_/, "");
			ProductId=0;
			session_id=$("#session_id").val();
			if ($("#ProductId").val()){
				ProductId=$("#ProductId").val();
			}
			buttonImgSrc=null;
			if ($(this).hasClass('coupon_foto')){
				type='coupon_foto';
				buttonText='Agregar Foto'
				buttonImgSrc="imagenes/icons2/png/48x48/image_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '.jpg,.gif,.png';
				fileDesc='Image Files';
				sizeLimit=4 ;


			}
			else if ($(this).hasClass('news_foto')){
				type='news_foto';
				buttonText='Agregar Foto'
				buttonImgSrc="imagenes/icons2/png/48x48/image_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '.jpg,.gif,.png';
				fileDesc='Image Files';
				sizeLimit= 4 ;


			}
			else if ($(this).hasClass('news_foto2')){
				type='news_foto';
				buttonText='Agregar Foto'
				buttonImgSrc="imagenes/icons2/png/48x48/image_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '.jpg,.gif,.png';
				fileDesc='Image Files';
				sizeLimit= 4 ;


			}
			else if ($(this).hasClass('news_audio')){
				type='news_audio';
				buttonText='Agregar Audio'
				buttonImgSrc="imagenes/icons2/png/48x48/speaker_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '.mp3';
				fileDesc='Audio Files';
				sizeLimit= 4;


			}
			else if ($(this).hasClass('news_video')){
				type='news_video';
				buttonText='Agregar Video'
				buttonImgSrc="imagenes/icons2/png/48x48/digital_camcorder_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '.flv,.avi';
				fileDesc='Video Files';
				sizeLimit= 10;


			}

			else if ($(this).hasClass('news_dni')){
				type='catalog';
				buttonText='Agregar DNI'
				fileExt= '.jpg,.gif,.png';
				sizeLimit= 4;
			}
			else{
				fileExt= '.jpg,.gif,.png';
				sizeLimit= 4;
				type='catalog';
				buttonText='Agregar Foto'
			}
			Lang=$("#Lang").val();
			if ($("#AMBIENTE").val()=='backend'){
				url_site=$("#SITE_URL_ADMIN").val();
				script=url_site+'ajax_uploadify.php';
			}
			else{
				url_site=$("#PATH_URL_MRW").val();
				script=url_site+'uploadify';
			}
			if (buttonImgSrc){
				if (!$(this).hasClass('news_foto2')){
					$('#'+this.id ).html('<img src="'+buttonImgSrc+'">');
				}
				
			}
			else{
				$('#'+this.id ).html('<span class="upload_txt">'+buttonText+'</span>');
			}
				
			$('#'+this.id ).append( "<div class='preview_galery'></div>" );
			var myDropzone = new Dropzone('#'+this.id +" .preview_galery",
					{
				url: script,
				paramName: "Filedata",
				maxFilesize:sizeLimit,
				acceptedFiles:fileExt,
				params: {
					'uploadify_id': id,
					'ProductId': ProductId,
					'Lang': Lang,
					'type': type,
			      },
			    clickable: '#'+this.id,
			    
			    success: function(file, response){
			    	var objResponse = jQuery.parseJSON(response)
			    	if (objResponse.show_type=='append'){
						$('#galery_'+objResponse.id).append(objResponse.html);
					}
					else if (objResponse.show_type=='append_2'){
						//$('#galery_set_'+objResponse.id).append(objResponse.html);
						$('#galery_'+objResponse.id).append(objResponse.html);
					}
					else if (objResponse.show_type=='replace_all'){
						$('#galery_all_'+objResponse.id).html(objResponse.html);
					}
					else{
						$('#galery_'+objResponse.id).html(objResponse.html);
					}
	                
	            }
			}
			);
				
			

		}
	});
	
	$('input.uploadify').each(function(){

		if (!$(this).hasClass('uploadify_set')){
			$(this).addClass('uploadify_set')
			id=$(this).attr('id').replace(/property_/, "");
			ProductId=0;
			session_id=$("#session_id").val();
			if ($("#ProductId").val()){
				ProductId=$("#ProductId").val();
			}
			buttonImgSrc=null;
			if ($(this).hasClass('coupon_foto')){
				type='coupon_foto';
				buttonText='Agregar Foto'
				buttonImgSrc="imagenes/icons2/png/48x48/image_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '*.jpg;*.gif;*.png';
				fileDesc='Image Files';
				sizeLimit=1024 * 1024 * 2 ;


			}
			else if ($(this).hasClass('news_foto')){
				type='news_foto';
				buttonText='Agregar Foto'
				buttonImgSrc="imagenes/icons2/png/48x48/image_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '*.jpg;*.gif;*.png';
				fileDesc='Image Files';
				sizeLimit=1024 * 1024 * 2 ;


			}
			else if ($(this).hasClass('news_audio')){
				type='news_audio';
				buttonText='Agregar Audio'
				buttonImgSrc="imagenes/icons2/png/48x48/speaker_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '*.mp3';
				fileDesc='Audio Files';
				sizeLimit=1024 * 1024 * 4;


			}
			else if ($(this).hasClass('news_video')){
				type='news_video';
				buttonText='Agregar Video'
				buttonImgSrc="imagenes/icons2/png/48x48/digital_camcorder_add.png";
				buttonImgWidth="48px";
				buttonImgHeight="48px";
				fileExt= '*.flv;*.avi';
				fileDesc='Video Files';
				sizeLimit=1024 * 1024 * 10;


			}

			else if ($(this).hasClass('news_dni')){
				type='catalog';
				buttonText='Agregar DNI'
			}
			else{
				type='catalog';
				buttonText='Agregar Foto'
			}
			Lang=$("#Lang").val();
			if ($("#AMBIENTE").val()=='backend'){
				url_site=$("#SITE_URL_ADMIN").val();
				script=url_site+'ajax_uploadify.php';
			}
			else{
				url_site=$("#PATH_URL_MRW").val();
				script=url_site+'uploadify';
			}
			if (buttonImgSrc){
				$(this).uploadify({
					'uploader'       : url_site+'js/uploadify/swf/uploadify.swf',
					'script'         : script,
					'cancelImg'      : url_site+'imagenes/cancel.gif',
					'auto'           : true,
					'multi'          : true,
					'fileExt'    : fileExt,
					'fileDesc'    : fileDesc,
					'sizeLimit'	: sizeLimit,
					'buttonImg': buttonImgSrc,
					'width': buttonImgWidth,
					'height': buttonImgHeight,
					'wmode': 'transparent',
					'scriptData':  {uploadify_data:'uploadify_id='+id+'|||ProductId='+ProductId+'|||Lang='+Lang+'|||type='+type} ,
					onComplete: function(event, queueID, fileObj, response, data) {

					objResponse=(eval('(' + response + ')'));

						if (objResponse.show_type=='append'){
							$('#galery_'+objResponse.id).append(objResponse.html);
						}
						else if (objResponse.show_type=='append_2'){
							//$('#galery_set_'+objResponse.id).append(objResponse.html);
							$('#galery_'+objResponse.id).append(objResponse.html);
						}
						else if (objResponse.show_type=='replace_all'){
							$('#galery_all_'+objResponse.id).html(objResponse.html);
						}
						else{
							$('#galery_'+objResponse.id).html(objResponse.html);
						}


					},
					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("Se ha producido un error en la carga del archivo.\nRevise por favor que el archivo que intenta subir tiene el formato y el tama\u00f1o permitido.");
						//alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
						else
						alert('error '+d.type+": "+d.text);
						}
				});


			}
			else{
				$(this).uploadify({
					'uploader'       : url_site+'js/uploadify/swf/uploadify.swf',
					'script'         : script,
					'cancelImg'      : url_site+'/images/cancel.gif',
					'auto'           : true,
					'multi'          : true,
					'buttonText' 	: buttonText,
					'scriptData':  {uploadify_data:'uploadify_id='+id+'|||ProductId='+ProductId+'|||Lang='+Lang+'|||type='+type} ,
					onComplete: function(event, queueID, fileObj, response, data) {

					objResponse=(eval('(' + response + ')'));

						if (objResponse.show_type=='append'){
							$('#galery_'+objResponse.id).append(objResponse.html);
						}
						else if (objResponse.show_type=='append_2'){
							//$('#galery_set_'+objResponse.id).append(objResponse.html);
							$('#galery_'+objResponse.id).append(objResponse.html);
						}
						else if (objResponse.show_type=='replace_all'){
							$('#galery_all_'+objResponse.id).html(objResponse.html);
						}
						else{
							$('#galery_'+objResponse.id).html(objResponse.html);
						}


					},
					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);
						}
				});
			}

		}
	});
}


function get_lang(obj,LangSelId)
{
	module=$(obj).closest("div.module-contents").attr("id");
	$('#LangSelId').val(LangSelId);
	call_back_module(module,get_lang);

}



function load_datepicker_controls(){

$.datepicker.setDefaults({
		clearText: 'Limpiar', clearStatus: '',
		closeText: 'Cerrar', closeStatus: '',
		prevText: '&lt;Ant', prevStatus: '',
		nextText: 'Sig&gt;', nextStatus: '',
		currentText: 'Hoy', currentStatus: '',
		monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
		'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
		monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
		'Jul','Ago','Sep','Oct','Nov','Dic'],
		monthStatus: '', yearStatus: '',
		weekHeader: 'Sm', weekStatus: '',
		dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;dabo'],
		dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
		dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
		dayStatus: 'DD', dateStatus: 'D, M d',
		dateFormat: 'dd/mm/yy', firstDay: 0,
		initStatus: '', isRTL: false,
		yearRange: '-85:+10'
	});
	$('input.date-pick').each(function(){
		$(this).datepicker({showStatus: true,
			    showOn: "both",
			    buttonImage: $("#PATH_URL_MRW").val()+"imagenes/calendar.gif",
			    buttonImageOnly: true,
			    startDate:'05/03/1920',
			    endDate:'05/11/2108',
			    changeMonth: true,
				changeYear: true
				}
		 );
	});

	$('input.date-time-pick').each(function(){
			$(this).datetimepicker({showStatus: true,
			    showOn: "both",
			    buttonImage: $("#PATH_URL_MRW").val()+"imagenes/calendar.gif",
			    buttonImageOnly: true,
			    startDate:'05/03/1920',
			    endDate:'05/11/2108',
			    changeMonth: true,
				changeYear: true
				});
	});


}


function CalAge(bDay) {

    var now = new Date();
/*    var mm = document.getElementById('ddlmnths').value;
    var ddr = document.getElementById('ddldays');
    var dd = ddr.options[ddr.selectedIndex].value;
    var yy = document.getElementById('ddlyrs').value;
     bDay = dd + "/" + mm + "/" + yy;
   */

    bD = bDay.split('/');
   	    if (bD.length == 3) {
        	   born = new Date(bD[2], bD[1] * 1 - 1, bD[0]);
              years = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
    }
    return years;
}
