rootUrl='/';
homeUrl='/Site';
i18n='pt';
$.scripts = Array();$.loadedScripts = Array();$(function () { $.globalWidth = $(document).width();$(window).load(function () { $.globalWidth = $(document).width();}).resize(function () { $.globalWidth = $(document).width();});flowmvc();});function flowmvc() { $.submiting = false;if ($.scrollTop) { $('html,body').animate({ scrollTop: $.scrollTop
});}
else { $.scrollTop = $(window).scrollTop();}
$('.ajaxProgress').bind('ajaxStart',function () { $(this).show();}).bind('ajaxComplete',function () { $(this).hide();})
$('.autopostback').each(function (index) { $(this).change(function () { if ($(this).parents('form:first').hasClass('validateform') && $(this).valid()) { $(this).parents('form:first').submit();}
else { $(this).parents('form:first').submit();}
return true;});});$('.autopostbackforce').each(function (index) { $(this).change(function () { submitForm($(this).parents('form:first'),true,$(this).attr('id'));});});$('span.successMessage').each(function (index) { $(this).fadeIn('slow')
.animate({ left: 0 },3000)
.fadeOut('slow');});if ($('form.validateform').length > 0) { if (typeof (JQueryVal) === 'undefined') { JQueryVal = true;$.ajax({ url: rootUrl + 'Static/Scripts/jquery.validate-1.6.min.js',dataType: 'script',async: false,cache: true });jQuery.validator.prototype.optional = function (element) { return false;};}
}
$.editors = Array();if ($('textarea.editor').length > 0) { if (typeof (CKEDITOR_BASEPATH) === 'undefined') { CKEDITOR_BASEPATH = rootUrl + 'Static/Scripts/ckeditor/';$.ajax({ url: rootUrl + 'Static/Scripts/ckeditor/ckeditor.js',dataType: 'script',async: false,cache: false });}
$('textarea.editor').each(function (index) { var rows = $(this).attr('rows');$.editors[$(this).attr('id')] = CKEDITOR.replace($(this).attr('id'),{ filebrowserBrowseUrl: homeUrl + '/Gallery/',filebrowserUploadUrl: homeUrl + '/Gallery/Upload',filebrowserWindowWidth: '1024',filebrowserWindowHeight: '600',uiColor: '#e6edf3',resize_enabled: false,disableNativeSpellChecker: true,height: 60 + (rows * 22) + 'px',toolbar:
[
['Bold','Italic','Underline','Strike'],['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],['Cut','Copy','Paste','PasteText','PasteFromWord'],['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],['Link','Unlink','Anchor'],['Image','Flash','MediaEmbed','Table','HorizontalRule','SpecialChar'],'/',['Styles','Format','Font','FontSize'],['TextColor','BGColor'],['Maximize','ShowBlocks','Source','-','Preview']
]
})
});for (var instanceName in CKEDITOR.instances) { CKEDITOR.instances[instanceName].on('blur',function () { var ckeditor = this;ckeditor.updateElement();$('#' + ckeditor.name).valid();});}
}
if ($('input.datepick').length > 0) { if (typeof (JQueryUI) === 'undefined') { JQueryUI = true;$.ajax({ url: rootUrl + 'Static/Scripts/jquery-ui-1.7.2.custom.min.js',dataType: 'script',async: false,cache: true });$.ajax({ url: rootUrl + 'Static/Scripts/jquery.ui/i18n/ui.datepicker-' + i18n + '.js',dataType: 'script',async: false,cache: true });}
$('input.datepick').each(function (index) { $(this).datepicker({ changeMonth: true,changeYear: true,constrainInput: true,showOn: 'none',showButtonPanel: true,closeAtTop: true,onClose: function () { $(this).focus();}
});});$('img.datepickimg').each(function (index) { $(this).click(function () { $(this).next().datepicker('show');});});$('img.datepickimgright').each(function (index) { $(this).click(function () { $(this).prev().datepicker('show');});});}
if ($('input.upload').length > 0) { if (typeof (JQueryUpload) === 'undefined') { JQueryUpload = true;$.ajax({ url: rootUrl + 'Static/Scripts/ajaxupload.3.9.js',dataType: 'script',async: false,cache: true });}
$('input.upload').each(function (index) { var parent = $(this).parents(':first');var id = $(this).attr('id').substring(6);var uploadButton = $(this);var hidden = parent.find('#' + id);var image = parent.find('#image' + id);var href = parent.find('#href' + id);var deleteButton = parent.find('#delete' + id);var status = parent.find('#status' + id);var mask = new RegExp(parent.find('#mask' + id).attr('value'));new AjaxUpload(uploadButton,{ action: homeUrl + '/Upload/upload',name: 'uploadfile',onSubmit: function (file,ext) { if (ext.length == 0 || !mask.test(ext)) { status.text('* Ficheiro não permitido.');return false;}
status.text('A enviar ficheiro...');},onComplete: function (file,response) { status.text('');if (response.beginsWith("success")) { var path = response.substring(7);if (image.length > 0) { image.attr('src',path + file);image.show();}
if (href.length > 0) { href.attr('href',path + file);href.show();}
hidden.val(file);deleteButton.show();uploadButton.hide();return false;}
else { status.text('Ocorreu um erro,contacte o Administrador.');return false;}
}
});deleteButton.click(function () { if ($.submiting)
return false;else $.submiting = true;var filename = '';if (image.attr('src') !== null)
filename += image.attr('src');if (href.attr('href') !== null)
filename += href.attr('href');$.ajax({ url: homeUrl + '/Upload/delete',data: 'filename=' + filename,cache: false,type: "POST",success: function (data) { image.hide();href.hide();deleteButton.hide();uploadButton.show();href.parent().find('object').remove();hidden.val('');$.submiting = false;return false;},error: function (data) { status = 'Ocorreu um erro,contacte o Administrador.';$.submiting = false;return false;}
});});});}
$('form.ajaxform').each(function (index) { formToSubmit = $(this);formToSubmit.find('input[type=submit]').each(function (index) { if ($(this).attr('name').length > 0)
$(this).click(function () { $(this).attr('id',$(this).attr('name'));});});formToSubmit.find('input[type=image]').each(function (index) { if ($(this).attr('name').length > 0)
$(this).click(function () { $(this).attr('id',$(this).attr('name'));});});formToSubmit.submit(function () { submitForm($(this));return false;});});$('form > meta[name=loader]').each(function (index) { eval($(this).attr('content'));$(this).remove();});runLoadedScripts();}
function resetScroll() { $('html,body').scrollTop(0);}
function _doFormPost(sender,formId,path,validate) { if (formId.length == 0) { formId = $(sender).parents('form:first').attr('id');}
formToPost = $('#' + formId);if (!validate) { formToPost.validate({ onsubmit: false });$(sender).parents('form:first').validate({ onsubmit: false });}
else if (!$(sender).parents('form:first').valid() || !formToPost.valid()) { return false;}
if ($(sender).hasClass('resetscroll')) { resetScroll();}
action = formToPost.attr('action');formToPost.attr('action',path);submitForm(formToPost,true,null);formToPost.attr('action',action);}
function _doPostBack(sender,id,value) { element = getElement(sender,id);if ($(sender).hasClass('resetscroll')) { resetScroll();}
$(element).val(value);$(element).parents('form:first').submit();}
function _toogleOrder(sender,value) { order = getElement(sender,'Searcher.Order');direction = getElement(sender,'Searcher.Direction');if ($(order).val() != value) { $(order).val(value);$(direction).val('False');}
else { $(direction).val($(direction).val().toLowerCase() == 'false' ? 'True' : 'False');}
$(order).parents('form:first').submit();}
function submitForm(form) { submitForm(form,false,null);}
function submitForm(form,overrideValidation,sender) { if ($.submiting)
return false;else { if (form.hasClass('validateform') && !overrideValidation) { if (!form.valid()) { formValidateSummary(form);return false;}
}
formValidateSummary(form);$.submiting = true;}
$.scrollTop = $(window).scrollTop();try { for (var instanceName in CKEDITOR.instances) { $.editors[instanceName].destroy();$.editors[instanceName] = null;}
}
catch (error) { } 
var data = form.serialize();if (sender != null && sender.length > 0) { data += '&sender=' + sender;}
else { form.find('input[type=submit]').each(function (index) { id = $(this).attr('id');if (id.length > 0) { data += '&sender=' + $(this).val();}
});form.find('input[type=image]').each(function (index) { id = $(this).attr('id');if (id.length > 0) { data += '&sender=' + $(this).val();}
});}
$.ajax({ url: form.attr('action'),data: data,type: "POST",success: function (result,textStatus,transport) { result = result.replaceAll('<script ','<div style="display:none" class="scriptdiv" ').replaceAll('</script>','</div>');if (result.indexOf('<html') == -1) { result = '<html><body><div>' + result + '</div></body></html>';}
id = form.attr('id');form.html($(result).find('#' + id).html());refresh = '.' + id + 'Update';$(refresh).each(function (index) { $($(refresh).get(index)).html($($(result).find(refresh).get(index)).html());});$('form > div.scriptdiv').each(function (index) { tmp = '<meta name="loader" content="' + $(this).html() + '" />';$(this).after(tmp).remove();});$.submiting = false;flowmvc();return false;},error: function (transport) { if (transport.status == 310) { window.location.href = transport.getResponseHeader("Location");return false;}
status = 'Ocorreu um erro,contacte o Administrador.';$.submiting = false;return false;}
});}
function showErrorTip(caller,error) { var form = $(caller).parents('form:first');errorElement = $('#' + $(caller).attr('id') + '_validationMessage',form);if (errorElement.attr('id') != null) { if (!errorElement.hasClass('asterisk')) { errorElement.append(error);}
else { errorElement.html('*');$(caller).blur(function () { var form = $(this).parents('form:first');if ($(this).valid())
form.find('#' + $(this).attr('id') + '_validationMessage').hide();else form.find('#' + $(this).attr('id') + '_validationMessage').show();formValidateSummary(form);});var validationSummary = form.find('.validation-summary-errors:first');var ul = validationSummary.find('ul:first');if (ul.size() == 0) { validationSummary.append($('<ul/>'));ul = validationSummary.find('ul:first');}
ul.append($('<li>').append(error).append($('</li>')));}
return;}
$(caller).after(error);}
function formValidateSummary(form) { if (form.find('.asterisk:visible:contains("*")').size() > 0) { form.find('.validation-summary-errors:first').show();}
else { form.find('.validation-summary-errors:first').hide();}
}
jQuery.fn.outerHTML = function (s) { return (s)
? this.before(s).remove()
: jQuery("<p>").append(this.eq(0).clone()).html();}
String.prototype.beginsWith = function (t,i) { if (i == false) { return (t == this.substring(0,t.length));}
else { return (t.toLowerCase() == this.substring(0,t.length).toLowerCase());}
}
String.prototype.endsWith = function (t,i) { if (i == false) { return (t == this.substring(this.length - t.length));}
else { return (t.toLowerCase() == this.substring(this.length - t.length).toLowerCase());}
}
String.prototype.replaceAll = function (strTarget,strSubString) { var strText = this;var intIndexOfMatch = strText.indexOf(strTarget);while (intIndexOfMatch != -1) { strText = strText.replace(strTarget,strSubString)
intIndexOfMatch = strText.indexOf(strTarget);}
return (strText);}
function getElement(sender,id) { var form = $(sender).parents('form:first');var element = form.find('#' + id);if ($(element).length == 0) { id = id.replaceAll('.','_');element = form.find('#' + id);}
return element;}
function loadScript(url) { if (jQuery.inArray(url,$.scripts) == -1) { $.scripts.push(url);}
}
function runLoadedScripts() { jQuery.each($.scripts,function (obj,url) { if (jQuery.inArray(url,$.loadedScripts) == -1) { $.ajax({ url: url,dataType: 'script',async: false,cache: true });$.loadedScripts.push(url);}
});$('form.validateform').each(function (index) { id = $(this).attr('id').replaceAll('-','_');try { func = eval('validate' + id);func();}
catch (error) { }
});}

