/**
 * General functions scripts
 * @author: Golan Cohen
 */
var body;var loading = '<div id="Loading"><img src="/images/layout/loading.gif" /></div>';dojo.addOnLoad(function() {if (dojo.byId('newMessage')) {var messagePopUp = new popUp();messagePopUp.cancelText = 'Close';messagePopUp.content = dojo.byId('newMessage').innerHTML;messagePopUp.create();}});function overlay(data) {if (dojo.isIE) {var body = document.documentElement;} else {var body = dojo.body();}dojo.query(body).style({overflow: "hidden"});var overlay = dojo.doc.createElement('div');overlay.id = 'Overlay';dojo.query(overlay).style({opacity: 0});dojo.query(overlay).place(dojo.byId('Inner'), 'first');var overlayContainer = dojo.doc.createElement('div');overlayContainer.id = 'OverlayContainer';dojo.query(overlayContainer).style({opacity: 0, height: "100%", width: "100%", top: "0px", left: '0px', position: 'fixed', zIndex: 999});dojo.query(overlayContainer).place(dojo.byId('Inner'), 'first');overlayContainer.innerHTML = data;overlay.style.display = 'block';var anim = dojo.anim(overlay, {opacity: 0.4}, 250);var anim2 = dojo.anim(overlayContainer, {opacity: 1}, 250);dojo.connect(anim, 'onEnd', anim2);anim.play();}function destroyOverlay() {var overlay = dojo.byId('Overlay');var overlayContainer = dojo.byId('OverlayContainer');dojo.anim(overlay, {opacity: 0}, 250).play();dojo.anim(overlayContainer, {opacity: 0}, 250).play();dojo.query(dojo.byId('Overlay')).orphan();dojo.query(dojo.byId('OverlayContainer')).orphan();if (dojo.isIE) {var body = document.documentElement;} else {var body = dojo.body();}dojo.query(body).style({overflow: "auto"});}function popUp() {this.width = 200;this.height = 125;this.title = '';this.content = '';this.callbackText;this.callbackFunc;this.cancelText = 'Cancel';this.callbackButton = '';this.create = function() {if (this.callbackFunc) {this.callbackButton = '<button id="callbackButton" style="background-color: #EEF3F7; border: 1px solid #557A9F; color: #235F9D; font-size: 0.9em;" onclick="' + this.callbackFunc + '(); return false;">' + this.callbackText + '</button>&nbsp;';}var element = dojo.doc.createElement('div');var dialogue = dojo.doc.createElement('div');dialogue.id = 'Dialogue';dojo.query(dialogue).place(element, 'first');dojo.query(dialogue).style({height: this.height + 'px',width: this.width + 'px',margin: this.height/-2 + 'px 0px 0px ' + this.width/-2 + 'px',top: '50%',left: '50%'});dialogue.innerHTML = '<div style="position: relative; height: 100%; width: 100%;">';dialogue.innerHTML += '	<div style="position: absolute; top: 0px; left: 0px; height:13px; width: 13px; background-image:url(\'/images/layout/dialogueCorners.png\');"></div>';dialogue.innerHTML += '	<div style="position: absolute; top: 0px; right: 0px;  height:13px; width: 13px; background-image:url(\'/images/layout/dialogueCorners.png\'); background-position: 0 -13px;"></div>';dialogue.innerHTML += '	<div style="position: absolute; top: 0px; left: 12px; height: 13px; width: ' + (this.width-25) + 'px; background-image:url(\'/images/layout/dialogueBorderTop.png\')"></div>';dialogue.innerHTML += '	<div style="position: absolute; top: 13px; left: 0px; height: ' + (this.height-25) + 'px; width: 13px; background-image:url(\'/images/layout/dialogueBorderLeft.png\')"></div>';dialogue.innerHTML += '	<div style="position: absolute; top: 13px; right: 0px; height: ' + (this.height-25) + 'px; width: 12px; background-image:url(\'/images/layout/dialogueBorderRight.png\')"></div>';dialogue.innerHTML += '	<div style="position: absolute; bottom: 0px; left: 0px; height:13px; width: 13px; background-image:url(\'/images/layout/dialogueCorners.png\'); background-position: 0 -39px;"></div>';dialogue.innerHTML += '	<div style="position: absolute; bottom: 0px; right: 0px;  height:13px; width: 13px; background-image:url(\'/images/layout/dialogueCorners.png\'); background-position: 0 -26px;"></div>';dialogue.innerHTML += '	<div style="position: absolute; bottom: 0px; left: 12px; height: 13px; width: ' + (this.width-25) + 'px; background-image:url(\'/images/layout/dialogueBorderBottom.png\')"></div>';dialogue.innerHTML += '	<div style="position: absolute; top: 13px; left: 12px; height: ' + (this.height-26) + 'px; width: ' + (this.width-24) + 'px; background-color: white;"></div>';dialogue.innerHTML += ' <div style="position: absolute; top: 7px; left: 2px; 20px; height: 15px; width: ' + (this.width-20) + 'px; padding-left: 15px; border-bottom: #557A9F solid 1px; font-size: 11px;">' + this.title + '</div>';dialogue.innerHTML += '	<div style="position: absolute; top: 6px; right: 10px;"><a href="#" onclick="destroyOverlay(); return false;"><img src="/images/layout/close.jpg" /></a></div>';dialogue.innerHTML += '	<div id="popupContent" style="position: absolute; top: 30px; left: 15px; height: ' + (this.height-60) + 'px; width: ' + (this.width-30) + 'px;">' + this.content + '</div>';dialogue.innerHTML += ' <div style="position: absolute; bottom: 5px; left:15px; height: 20px; width: ' + (this.width-30) + 'px; text-align: center;">' + this.callbackButton + '<button style="background-color: #EEF3F7; border: 1px solid #557A9F; color: #235F9D; font-size: 0.9em;" onclick="destroyOverlay(); return false;" id="closeButton">' + this.cancelText + '</button></div>';dialogue.innerHTML += '</div>';overlay(element.innerHTML);};}function submitForm(form) {dojo.require("dojo.io.iframe");overlay(loading);dojo.io.iframe.send({url: form.action + '/ajax/1',form: form.id,handleAs: 'json',load: function(response) {if (response.status == 0) {destroyOverlay();var html = '';for (var i = 0;  i < response.errors.length; i++) {html += '<span class="error">' + response.errors[i] + '</span><br />';}var hiddenPopUp = new popUp();hiddenPopUp.width = 300;hiddenPopUp.height = 150;hiddenPopUp.title = 'Collection errors';hiddenPopUp.cancelText = 'Close';hiddenPopUp.content = html;hiddenPopUp.create();} else if (response.status == 1) {window.location = response.url;} else {alert(response);}return response;},error: function(response) {alert(response);}});}function saveFormAndRedirect(formId, href) {var content = {};content['ajax'] = 1;var form = dojo.byId(formId);dojo.xhrPost({url: form.action,form: form,content: content,handleAs: 'json',load: function (response) {if (response.status == 0) {var html = '';for (var i = 0;  i < response.errors.length; i++) {html += '<span class="error">' + response.errors[i] + '</span><br />';}var hiddenPopUp = new popUp();hiddenPopUp.width = 300;hiddenPopUp.height = 150;hiddenPopUp.title = 'Collection errors';hiddenPopUp.cancelText = 'Close';hiddenPopUp.content = html;hiddenPopUp.create();} else if (response.status == 1) {window.location = href;}},error: function (response) {alert (response);}});}function searchBugs() {if (dojo.byId('query').value) {dojo.byId('bug_search').submit();} else {window.location = '/bugs/report';}}function subscribe() {var bugId = dojo.byId('bug_id').value;dojo.xhrPost({url: '/bugs/subscribe',content: {'bug_id': bugId},handleAs: 'json',load: function(response) {if (response.status == 0) {var hiddenPopUp = new popUp();hiddenPopUp.width = 300;hiddenPopUp.height = 150;hiddenPopUp.title = 'Report subscription';hiddenPopUp.cancelText = 'Close';hiddenPopUp.content = '<span class="error">' + response.message + '</span>';hiddenPopUp.create();} else if (response.status == 1) {var html = '<strong>Subscribers</strong><br />';for (var i = 0; i < response.subscribers.length; i++) {html += response.subscribers[i].user_nickname + '<br />';}dojo.byId('bug_subscribers').innerHTML = html;dojo.byId('user_subscription').innerHTML = '<a href="#" onclick="unSubscribe(); return false;" title="Click here to stop receiving email updates about this report"><img src="/images/layout/delet.gif" alt="Subscribe" title="Click here to stop receiving email updates about this report" height="11" width="11" /> Unsubscribe</a>';var hiddenPopUp = new popUp();hiddenPopUp.width = 300;hiddenPopUp.height = 150;hiddenPopUp.title = 'Report subscription';hiddenPopUp.cancelText = 'Close';hiddenPopUp.content = 'You have been subscribed to receive future updated for this report.<br />You can cancel your subscription by visiting this page and clicking Unsubscribe.';hiddenPopUp.create();}return response;},error: function(response) {alert(response);}});}function unSubscribe() {var bugId = dojo.byId('bug_id').value;dojo.xhrPost({url: '/bugs/unsubscribe',content: {'bug_id': bugId},handleAs: 'json',load: function(response) {if (response.status == 1) {var html = '<strong>Subscribers</strong><br />';for (var i = 0; i < response.subscribers.length; i++) {html += response.subscribers[i].user_nickname + '<br />';}dojo.byId('bug_subscribers').innerHTML = html;dojo.byId('user_subscription').innerHTML = '<a href="#" onclick="subscribe(); return false;" title="Click here to receive email updates about this report"><img src="/images/layout/addItem.gif" alt="Subscribe" title="Click here to receive email updates about this report" height="11" width="11" /> Subscribe</a>';var hiddenPopUp = new popUp();hiddenPopUp.width = 300;hiddenPopUp.height = 150;hiddenPopUp.title = 'Report subscription';hiddenPopUp.cancelText = 'Close';hiddenPopUp.content = 'You have been unsubscribed from this report and will not receive any future updates.';hiddenPopUp.create();} else {alert(response);}return response;},error: function(response) {alert(response);}});}function addPropertyField() {propertiesDiv = dojo.byId('properties');var propertiesCount = 0;for (var i = 0; i < properties.length; i++) {if (properties[i].tagName == 'DIV') {propertiesCount++;}}var newProperty = dojo.doc.createElement('div');newProperty.className = 'fieldset';var newLabel = dojo.doc.createElement('label');newLabel.className = 'nav';newLabel.innerHTML = '&nbsp;';dojo.query(newLabel).place(newProperty, 'last');var newPropertyName = dojo.doc.createElement('input');newPropertyName.type = 'text';newPropertyName.id = 'property_name-' + propertiesCount;newPropertyName.name = 'properties[property-' + propertiesCount +'][property_name]';newPropertyName.value = '';dojo.query(newPropertyName).place(newProperty, 'last');var newSpace = dojo.doc.createElement('span');newSpace.innerHTML = ":&nbsp;&nbsp;&nbsp;";dojo.query(newSpace).place(newProperty, 'last');var newPropertyValue = dojo.doc.createElement('input');newPropertyValue.type = 'text';newPropertyValue.id = 'property_value-' + propertiesCount;newPropertyValue.name = 'properties[property-' + propertiesCount +'][property_value]';newPropertyValue.value = '';dojo.query(newPropertyValue).place(newProperty, 'last');dojo.query(newProperty).place(propertiesDiv, "last");} function displayRankDialogue(node) {var rankDiv = dojo.byId(node); rankDiv.style.display = 'block'; var anim = dojo.anim(rankDiv, {height: 143}, 250); anim.play(); dojo.byId('RankCollectionPopUp').innerHTML = '<a href="#" onclick="slideOut(); return false;" id="SearchButton">Close</a>';}