/* Version: $Id: modal.js 311 2009-09-22 06:44:31Z prskavecl $ */

/**
 * Modal window object
 * @author Jozef Lukac, LMC s.r.o.
 */


/**
* We are using YUI. We need Dictionary, URLManager and also some files: container-min.js, dispatcher-min.js, utilities.js
*
*
* All u need to use Modal window is register an event and appropriate method and pass some params to the method.
* Let's say u want to register modal template 'basketModalTemplate' which shows on click at the elemnt with id='click_me'.
* U can do it by following:
*    Modal.register('click_me', 'click', "tpl", {header: __('basket'), tpl: 'basketModal', preventDefault : true});
*
* Using: Moda.register([element],[event],[method], [object of params])
*
* element can be an object as well, if event is ommited, click will be used,
*
* method can be:
*   tpl-for showing template,
*  elm- for showing some element content inside the window, or
*  url- for showing some url inside the window
*/

var util = YAHOO.util;

/**
* Main Modal window object
*/
var Modal = {

		  /**
		  * Initializes the modal window
		  *
		  * @param DomElement|null renderObj
		  * @returns void
		  */
		    init : function(name, renderObj) {
			if (!this._windows) {
				this._windows = {};
			}
			if (!this._windowStack) {
				this._windowStack = [];
			}
			
		    this._windows[name] = new YAHOO.widget.Panel("modal-window-"+name,{
		      width: this.modalWidth,
		      fixedcenter: true,
		      close: true,
		      draggable: true,
		      zIndex:40,
		      modal: true,
		      visible: false,
		      constraintoviewport: true,
		      underlay: 'none',
		      effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.3}]
		      });
		     this._windows[name].setBody('');
		     this._windows[name].setHeader('');
		     if (renderObj) {
		    	 this._windows[name].render(renderObj);
		     } else {
		    	 this._windows[name].render(document.body);
		     }
		     this._windowStack[this._windowStack.length] = name;
		    },
		    
		    /**
		  * Sets the contents of the window.
		  *
		  * @param string pHeaderStr window header
		  * @param string pBodyStr window content
		  * @param object pTemplate
		  */
		    set : function(pHeaderStr, pBodyStr, pTemplate) {    	
		      var name = pTemplate.toString();
		      if (!this._windows || !this._windows[name]) {
		    	if (pTemplate.getRenderObj) {
		    		this.init(name, pTemplate.getRenderObj());
		    	} else {
		    		this.init(name);
		    	}
		      } 
		    	  
		    	  
		      if (pBodyStr) this._windows[name].setBody(pBodyStr);
		      if (pHeaderStr) this._windows[name].setHeader(pHeaderStr);
		      
		      if (typeof pTemplate.showEvent != 'undefined') {
		    	  this._windows[name].showEvent.subscribe(pTemplate.showEvent);
		      }
		      this._windows[name].show();
		    },

		    /**
		  * Hides the window.
		  *
		  * @returns void
		  */
		    hide : function(name){
		      if (!name) {
		    	  name = this._windowStack.pop();
		      }
		      if (this._windows[name]) {
		    	  this._windows[name].hide();    	  
		    	  this._windows[name] = null;
		      }
		    },

		    /**
		  * Method for displaying URL inside the window
		  *
		  * @param string pHeaderStr window header
		  * @param string pUrl URL of the page to display
		  */
		    showUrl : function(pHeader, pUrl) {
		      var callback = {
		      onLoad : function(o) {
		        Modal.hide();
		        Modal.set(pHeader, o.innerHTML);
		         },
		      onStart : function(o) {
		        Modal.set(__('Loading'), __('Please wait'));
		      }
		      }
		      /**
		      * We need an element to put the content into, so we create one first.
		      */
		      if (!document.getElementById('Modal-result-container')) {
		        var el = document.createElement("div");
		        el.id = 'Modal-result-container';
		        el.style.display = 'none';
		        document.body.appendChild(el);
		      }
		      YAHOO.util.Dispatcher.fetch('Modal-result-container', pUrl, callback);
		    },
		    /**
		  * Method for displaying Element inside the window.
		  *
		  * @param string pHeaderStr window header
		  * @param string pElmId id of the element to display
		  */
		  showElm : function(pHeader, pElmId) {
		    var lElm = document.getElementById(pElmId);
		    if (!lElm) {return false;}

		    this.set(pHeader, lElm.innerHTML);
		    return true;
		  },

		    /**
		  * Method for displaying a template inside the window.
		  *
		  * @param string pHeaderStr window header
		  * @param string pTpl a template to display
		  */
		  showTpl : function(pHeader, pTpl, pTplVars) {
		    /**
		    *  We have the name of the template, but we need template object. Ugly hack...
		    */
		    try {
		      var tpl = eval(pTpl);
		    }
		    catch (err) {
		      try {
		                    console.warn('no such template loaded '+pTpl);
		            }
		            catch(err){

		            }
		      /*
		      * We do not have such template, probably...
		      */
		      return false;
		    }
			if (pTplVars && pTplVars['modalWidth']) {
				this.modalWidth = pTplVars['modalWidth']; 
			} else {
		    	this.modalWidth = "340px";
			}
		    /**
		    * Set the variables that we want to override
		    */
		    if(pTplVars) {
		      for(lVar in  pTplVars) tpl.vars[lVar] = pTplVars[lVar];
		    }
		    this.set(pHeader, tpl.get(), tpl);
		    return tpl;
		  },

		    /**
		  * Registers event and method with args to call.
		  *
		  * @param string pElmId: id of the element to observe
		  * @param string pEvent: name of the event. If ommited, click will be used
		  * @param string pMethod: a method of Modal to call when pEvent occures. This corresponds to the method of this class written in lower-case without show prefix, 'url','elm','tlp' etc...
		  * @param array pArgs: Array of arguments for callback f-cion
		  */
		  register : function(pElmId, pEvent, pMethod, pArgs) {

		    pArgs['pMethod'] = pMethod;
		    if (!pEvent) pEvent = 'click';
		    YAHOO.util.Event.on(pElmId, pEvent, Modal.dispatch, pArgs);


		    /**
		    * Just some d-Bug infos. Uncomment following...
		    */

		    /*var lArgs = "";
		    if(pArgs) {
		      for(lArg in  pArgs) lArgs += lArg + '=' + pArgs[lArg] + ",";
		    }
		    console.warn('Modal: new evet registered: ' + pEvent + ', elmId: ' + pElmId + ', method: ' + pMethod + ',args: ' + lArgs);
		    */
		  },

		    /**
		  * Method for dealing with registered events. It's responsible for calling proper method with proper args when event occures on element.
		  * This method shoul not be called directly
		  *
		  * @param string pEvent: event to observe
		  * @param array pArgs: array of args for Method
		  */
		  dispatch : function(pEvent, pArgs) {
			var tpl = null;
		    switch (pArgs['pMethod']) {
		      case 'url':
		          /**
		          * Set the preventDefault for all registered showUrl calls
		          */
		          pArgs['preventDefault'] = true;
		          Modal.showUrl(pArgs['header'], pArgs['url']);
		        break;
		      case 'elm':
		          Modal.showElm(pArgs['header'], pArgs['id']);
		        break;
		      case 'tpl':
		          tpl = Modal.showTpl(pArgs['header'], pArgs['tpl'], pArgs['vars']);
		        break;
		    }
		    if ((pArgs['preventDefault'] && pArgs['preventDefault'] == true) 
		    		|| (tpl != null && tpl.preventDefault && tpl.preventDefault() == true)) {    	
		      if(YAHOO.env.ua.ie) pEvent.returnValue = false;
		      else  YAHOO.util.Event.preventDefault(pEvent);
		    }
		    if(pArgs['focus'] && document.getElementById(pArgs['focus'])) {
		      document.getElementById(pArgs['focus']).focus();
		    }
		  }
		}


/**
* Modal Templates definitions
*/

var userLoginTemplate = {
		  vars : {loginTextDisplay : 'inline',
		      loginTextBadPasswordCompanyDisplay : 'none',
		      loginTextBadPasswordDisplay : 'none',
		      loginTextUnknownDisplay : 'none',
		      redirect  : '',
		      basketLogin : false
		  },
		  get : function(){
	// TODO: remove cookie functions to special file and include it when it is needed (tip: when initModals is set)
	function readCookie(name) { 
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	  
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+";";
	}

	function eraseCookie(name) {
	  var cookie_date = new Date();  // current date & time
	  cookie_date.setTime(cookie_date.getTime() - 1);
	  var domain = document.domain.split('.')[document.domain.split('.').length-2]+'.'+document.domain.split('.')[document.domain.split('.').length-1];
	  document.cookie = name += "=; expires=" + cookie_date.toGMTString() + "; path=/; domain=."+domain;
	}
	  
	var errorMessage = readCookie('message_errorId');
	if (errorMessage != null) {
		if (errorMessage.indexOf('incorrect_password_company') !== 0) {
			this.vars.loginTextDisplay = 'none';
			this.vars.loginTextBadPasswordDisplay = 'inline';
			eraseCookie('message_errorId');			  
		}
	}
	  
    return '<div class="modal modalLarge">'+
'<div class="modalCnt">'+
	'<div id="loginreg"><img src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" alt="" align="left" />'+
	  '<strong><label id="loginText" style="display:' +this.vars.loginTextDisplay + '"> <br />' + (this.vars.basketLogin ? __('basketLogin') : __('PleaseSignIn')) + '</label>'+
      '<label id="loginTextBadPassword" style="color:red;display:' + this.vars.loginTextBadPasswordDisplay  + ';">' + __('incorrect_password') +
      '<a href="' + URLManager.getUrl('G2') + '">' + __('company_login') + '</a></label>'+
      '<label id="loginTextBadPasswordCompany" style="color:red;display:' + this.vars.loginTextBadPasswordCompanyDisplay + ';">' +
       __('incorrect_password_company') + ' <a href="' + URLManager.getUrl('G2') + '">' + __('company_login') + '</a></label>'+
      '<label id="loginTextUnknown" style="color:red;display:' + this.vars.loginTextUnknownDisplay + ';"><br/>' + __('trylater') + '</label>'+
      '</strong> '+
	  '<div class="clear"></div>'+
	  '<div class="box">'+
	   '<form action="' + URLManager.getUrl('Jobs_Muj_Registrace') + '" method="post" name="register">'+
	   '<h3>' + __('mdl_why_register') + '</h3>'+
		  '<ul>'+
       '<li><strong>' + __('mdl_basket_heading') + '</strong>' + __('mdl_basket_text') + '</li>'+
       '<li><strong>' + __('mdl_agent_heading') + '</strong>' + __('mdl_agent_text') + '</li>'+
       '<li><strong>' + __('mdl_cv_heading') + '</strong>' + __('mdl_cv_text') + '</li>'+
		  '</ul>'+
		  '<div class="clear"></div>'+
		  '<input name="submit" type="submit" class="submit" value="' + __('mdl_register') + '" />'+
	   '</form>'+
	  '</div>'+
		'<div class="box_2">'+
		  '<form action="' + URLManager.getUrl('login') +'" method="post" name="login">'+
		  '<input type="hidden" name="action" value="login" />' +
		  (this.vars.redirect != '' ? '<input type="hidden" name="redirect" value="' + this.vars.redirect + '" />' : '') +
		  '<h3>' + __('mdl_login_heading') + '</h3>'+
		  '<table width="100%" border="0">'+
			'<tr>'+
			  '<td><label for="modEmail">' + __('email') + '</label>'+
			  '<input type="text" name="email" id="modEmail" /></td>'+
			'</tr>'+
			'<tr>'+
			  '<td><label for="modPassword">' + __('password') + '</label>'+
			  '<input type="password" name="password" id="modPassword" />'+
			  '<a href="' + URLManager.getUrl('Jobs_Muj_Forget_Password') + '">' + __('forgot_password') + '</a></td>'+
			'</tr>'+
			'<tr>'+
			  '<td class="modalCheck">'+
			  '<input id="modPermanent" name="permanent" type="checkbox" value="1" tabindex="3" style="width:15px;height:15px;margin:0" title="' + __('security_warning') + '" /> ' + __('mdl_permanent_login') + '</td></label>'+
			'</tr>'+
		  '</table>'+
		  '<input name="submit" type="submit" class="submit" value="' + __('mdl_login') + '" />'+
		  '</form>'+
		'</div>'+
		'<div class="clear"></div>'+
	'</div>'+
'</div>'+
'</div>';
   }
};

 var userLoginTemplateOld = {
  vars : {loginTextDisplay : 'inline',
      loginTextBadPasswordCompanyDisplay : 'none',
      loginTextBadPasswordDisplay : 'none',
      loginTextUnknownDisplay : 'none',
      redirect  : '',
      basketLogin : false
  },
  get : function(){
	// TODO: remove cookie functions to special file and include it when it is needed (tip: when initModals is set)
	function readCookie(name) { 
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	  
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+";";
	}

	function eraseCookie(name) {
	  var cookie_date = new Date();  // current date & time
	  cookie_date.setTime(cookie_date.getTime() - 1);
	  var domain = document.domain.split('.')[document.domain.split('.').length-2]+'.'+document.domain.split('.')[document.domain.split('.').length-1];
	  document.cookie = name += "=; expires=" + cookie_date.toGMTString() + "; path=/; domain=."+domain;
	}
	  
	var errorMessage = readCookie('message_errorId');
	if (errorMessage != null) {
		if (errorMessage.indexOf('incorrect_password_company') !== 0) {
			this.vars.loginTextDisplay = 'none';
			this.vars.loginTextBadPasswordDisplay = 'inline';
			eraseCookie('message_errorId');			  
		}
	}
    return '<img src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" alt="" align="left" class="good_ghost" />'+
      '<strong><label id="loginText" style="display:' +this.vars.loginTextDisplay + '"> <br />' + (this.vars.basketLogin ? __('basketLogin') : __('PleaseSignIn')) + '</label>'+
        '<label id="loginTextBadPassword" style="color:red;display:' + this.vars.loginTextBadPasswordDisplay  + ';">' + __('incorrect_password') +
        '<a href="' + URLManager.getUrl('G2') + '">' + __('company_login') + '</a></label>'+
        '<label id="loginTextBadPasswordCompany" style="color:red;display:' + this.vars.loginTextBadPasswordCompanyDisplay + ';">' +
         __('incorrect_password_company') + ' <a href="' + URLManager.getUrl('G2') + '">' + __('company_login') + '</a></label>'+
        '<label id="loginTextUnknown" style="color:red;display:' + this.vars.loginTextUnknownDisplay + ';"><br/>' + __('trylater') + '</label>'+
      '</strong> <br /><br />'+
      '<form name="login" method="post" action="' + URLManager.getUrl('login') +'">' +
       '<input type="hidden" name="action" value="login" />' +
       (this.vars.redirect != '' ? '<input type="hidden" name="redirect" value="' + this.vars.redirect + '" />' : '') +
        '<div class="box-3">'+
          '<table width="100%" border="0">'+
            '<tr>'+
              '<td width="50"><strong><label for="modEmail">' + __('email') + '</label></strong></td>'+
              '<td width="150"><input tabindex="1" type="text" name="email" id="modEmail" style="width:135px" /></td>'+
              '<td>&nbsp;</td>'+
            '</tr>'+
            '<tr>'+
              '<td><strong><label for="modPassword">' + __('password') + '</label></strong></td>'+
              '<td><input type="password" tabindex="2" name="password" id="modPassword" style="width:135px" /></td>'+
              '<td align="center"><a href="' + URLManager.getUrl('Jobs_Muj_Forget_Password') + '" style="font-size:11px">' + __('forgot_password') + '</a></td>'+
            '</tr>'+
            '<tr>'+
              '<td>&nbsp;</td>'+
              '<td style="margin:0px;padding:0px;font-size:11px"><label for="modPermanent" title="' + __('security_warning') + '">'+
              '<input class="cbx" id="modPermanent" name="permanent" type="checkbox" value="1" tabindex="3" style="width:15px;height:15px;margin:0px;" /> ' + __('permanent_login') + '</label></td>'+
              '<td align="center">&nbsp;</td>'+
            '</tr>'+
          '</table>'+
        '</div>'+
        '<div style="float:right" align="right">'+
          '<input name="submit" type="submit" tabindex="4" class="submit" value="' + __('login') + '"/>'+
        '</div>'+
        '<div style="float:left;margin-top:8px"><a href="' + URLManager.getUrl('Jobs_Muj_Registrace') + '" class="arrow" style="background:transparent url(' + URLManager.getUrl('Jobs_Images2') + 'icon_arrow.gif) no-repeat scroll 0px 3px; font-size:11px; padding-left:12px;">' + __('register') + '</a></div>'+//Class arrow doesnt work
        '<br/><div class="clear">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>'+
      '</form>';
      }
};
var changePassTemplate = {
  vars : {},
  get : function(){
    return '<div id="changepass" style="display:block;"><img src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" alt="" align="left" class="good_ghost" /> <br />' +
    '<strong id="changeText" style="color:#F00">' + __('temporary_login') + '</strong><strong id="changeTextError" style="color:#F00; display:none;">' + __('password_dont_match') + '</strong> <br /> <br />' +
    '<form action="#" method="get" name="changepassword" onsubmit="checkPassword(\'oldpasswd\', \'passwd1\', \'passwd2\'); return false;">' +
      '<div class="box_2">'+
        '<table width="100%" border="0">'+
          '<tr>'+
            '<td width="170"><strong>' + __('current_password') + '</strong> <strong>:</strong></td>'+
            '<td><input type="password" name="oldpasswd" style="width:135px" id="oldpasswd" /></td>'+
          '</tr>'+
          '<tr>'+
            '<td width="170"><strong>' + __('new_password') + '</strong> (' + __('min6letters') + ')<strong>:</strong></td>'+
            '<td><input type="password" name="passwd1" style="width:135px" id="passwd1" /></td>'+
          '</tr>'+
          '<tr>'+
            '<td><strong>' + __('re_new_password') + ':</strong></td>'+
            '<td><input type="password" name="passwd2" style="width:135px" id="passwd2" /></td>'+
          '</tr>'+
        '</table>'+
      '</div>'+
      '<div style="float:right" align="right">'+
        '<input name="submit" type="submit" class="submit" value="' + __('save') + '" />'+
      '</div>'+
      '<div class="clear"></div>'+
    '</form>'+
  '</div>'+
  '</div>';
  }
}

callbackBasket = {
		success: function(o) {
					},
		failure: function(o) {
					},
		argument: []
}
function setBasketPopup() {
	var transaction = YAHOO.util.Connect.asyncRequest('GET', '' + (document.domain.match('^absolvent\.') !== null ? URLManager.getUrl('Absolvent_Basket_Popup') : URLManager.getUrl('Basket_Popup')) , callbackBasket, null);
}

var basketModalTemplate ={
  vars : {},
  get : function(){
  	var offerStr = '';
  	if(basketCount && basketCount>0){
  	    switch (basketCount){
  	    	case 1:
  	    		offerStr = __('Jobs_JD_1_Nabidku');
  	    		break;
  	    	case 2:
				offerStr = __('Jobs_JD_2_Nabidky');
				break;
			case 3:
				offerStr = __('Jobs_JD_3_Nabidky');
				break;
			case 4:
				offerStr = __('Jobs_JD_4_Nabidky');
				break;
			case 5:
				offerStr = __('Jobs_JD_5_Nabidek');
				break;
			default:
				offerStr = __('Jobs_JD_5_Nabidek');
				break;
		}
  	}
  	
    return  '<div id="modal-basket" style="display:block;"><img src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" alt="" align="left" class="good_ghost" /><br /> ' +
      '<strong>'+ __('add2cart') + '</strong><br />' +
      ''+ __('in_cart') + ' <span id="basketCnt3">' + basketCount + ' ' + offerStr + '</span><br />' +
      '<div style="margin-left:42px">' +
        '<form action="#" method="post" name="login_form" style="font-size:11px">' +
          '<br />' +
          '<input class="cbx" type="checkbox" name="checkbox" value="checkbox" style="width:15px;height:15px;margin:0px" />' +
          '&nbsp;&nbsp;' + __('noshow_again') + '<br />' +
          '<br />' +
          '<div class="clear"></div>' +
          '<table width="100%" border="0" cellpadding="0" cellspacing="0">' +
            '<tr>' +
             '<td align="left">' +
              '<input name="button" type="button" class="submit_basket" value="'+ __('show_cart') + '" onclick="if(document.login_form.checkbox.checked) { setBasketPopup(); setTimeout(function() {document.location=URLManager.getUrl(\'Jobs_Muj_Basket\');}, 2000); } else { document.location=URLManager.getUrl(\'Jobs_Muj_Basket\'); }"/>' +
             '</td>' +
             '<td align="right">' +
        		'<input name="button" type="button" class="submit" value="'+ __('continue') + '" onclick="if(document.login_form.checkbox.checked) setBasketPopup(); Modal.hide();" />' +
             '</td>' +
            '</tr>' +
          '</table>' +
        '</form>' +
      '</div>' +
      '<script type="text/javascript">' +
  		'var callback =  {' +
    			'success: function(o) {' +
    						'},' +
  	  		'failure: function(o) { // something wrong' +
  	  					'},' +
  	  		'argument: []' +
  		'}' +
  		'function setBasketPopup() {' +
  			'var transaction = YAHOO.util.Connect.asyncRequest(\'GET\',' + URLManager.getUrl('Jobs_Basket_Popup') + ', callback, null);' +
    	'}' +
      '</script>'+
    '</div>';
  }

}



var emptySearchModalTemplate = {
  vars : {},
  get : function(){
    return '<div>'+
    			'<img align="left" alt="duch" src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" class="good_ghost" />'+
      '<p>' + __('PleaseChooseAtLeastOneItemSoIWillKnowWhatToFind') + '</p><br />'+
      '<form action="#" method="post" style="font-size:11px; text-align: center;">'+
        '<input name="button" type="button" class="submit" value="'+ __('continue') + '" onclick="Modal.hide();" />'+
      '</form>'+
    '</div>';
    }
}

var overloadSearchModalTemplate = {
		  vars : {},
		  get : function(){
		    return '<div>'+
		    			'<img align="left" alt="duch" src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" class="good_ghost" />'+
		      '<p>' + __('PleaseUnselectSomeItems') + '</p><br /><br />'+
		      '<form action="#" method="post" style="font-size:11px; text-align: center;">'+
		        '<input name="button" type="button" class="submit" value="'+ __('continue') + '" onclick="Modal.hide();" />'+
		      '</form>'+
		    '</div>';
		    }
		}

var searchFormSimpleTemplate = {
  vars :
  {
	lLocalityOptions : [],
  	lLocModalBranch : ''
  },
  get : function(){
	  var lLocalityOptionsString = '';
	  for (lLocalityOptionIndex in this.vars.lLocalityOptions) {
		  var lLocalityOption = this.vars.lLocalityOptions[lLocalityOptionIndex];
		  lLocalityOptionsString += '<option value="' + lLocalityOption.value + '" '
		  				+ (lLocalityOption.highlight ? 'style="font-weight:bold"': '') + '>'
		  				+ (lLocalityOption.highlight ? '' : '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')
		  				+ (lLocalityOption.deep ? new Array(lLocalityOption.deep+1).join('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;') : '')
		  				+ lLocalityOption.name + '</option>' + "\n";
	  }
    return '<div id="modal-search-locality">'+
		'<img align="left" alt="duch" src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" class="good_ghost" /><strong>' + __('JOBS_T_Modal_Locality_Select') + '</strong> '+
		'<br /><br />'+
		    '<form action="' + URLManager.getUrl('Jobs_form_dispatcher') + '" method="get" target="_top" name="locModalForm">'+
				'<input type="hidden" name="module" value="JobsSearchResults" />'+
				'<input type="hidden" name="lang" value="' + URLManager.getLang() + '" />'+
				'<input type="hidden" name="srch[prof][]" value="' + this.vars.lLocModalBranch + '" id="locModalBranch" />'+
				'<input type="hidden" name="srch[from]" value="simple" />'+
				'<input type="hidden" name="srch[agent][]" value="202900001" />'+
				'<input type="hidden" name="srch[agent][]" value="202900002" />'+
				'<input type="hidden" name="srch[emp][]" value="201300001;201300002;201300003" />'+
				  '<select name="srch[local]" style="margin:20px; margin-left:40px; width:250px;">'+
					lLocalityOptionsString+
				  '</select>'+
				  '<div align="right">'+
					'<input name="submit" type="submit" class="submit" value="' + __('Jobs_JD_CB_ValidacePokracovat') + '"/>'+
				  '</div>'+
		    '</form>'+
		'</div>';
	}
}

var validationResultTemplate = {
  vars : {
  	title : 'pleaseCheckThisDataBeforeSubmit',
	submit_title : 'defaultCONTINUE',
  	errs: null
  },
  get : function(){
    // solve defaults, so case when calling of dictionary for translation is necessary
    if (this.vars.title == 'pleaseCheckThisDataBeforeSubmit') this.vars.title = __(this.vars.title);
    if (this.vars.submit_title == 'defaultCONTINUE') this.vars.submit_title = __('continue');
	  var err = '<div style="margin: 8px 8px 8px 42px; line-height: 150%;">';
	  err+= '<p>' + (this.vars.title? '<span style="color:red">' + this.vars.title + '</span><br />' : '') ;

  	  if(this.vars.errs) {
        for(var i in this.vars.errs) {
	  	  err+= '<strong><span style="color: red;">*</span> ' + this.vars.errs[i] + '</strong> <br />';
	  	}
		  err += "</p></div>";
  		};
      return '<div>' +
		'<img src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" alt="" align="left" style="margin-right:5px" />' +
		  err +
	    '</div>' +
	    '<div style="float: right;">' +
	  	  '<input class="submit" value="' + this.vars.submit_title + '"  onclick="Modal.hide();" type="submit"><br />&nbsp;' +
	    '</div>' +
	    '<div class="clear"><br />&nbsp;</div>&nbsp;';
  } // get
}

var attachmentValidationTemplate = {
  vars : {
	title: 'noAttachmentAttachedSendAnyway',
	submit_title : 'defaultSEND',
	cancel_title : 'defaultCANCEL',
	isValid : false
	},
  get : function(){
    // solve defaults, so case when calling of dictionary for translation is necessary
    if (this.vars.title == 'noAttachmentAttachedSendAnyway') this.vars.title = __(this.vars.title);
    if (this.vars.cancel_title == 'defaultCANCEL') this.vars.cancel_title = __('CANCEL');
    if (this.vars.submit_title == 'defaultSEND') this.vars.submit_title = __('SEND');
  
 	if(this.validate()) return Modal.hide();
	return '<div>' +
		'<img src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" alt="" align="left" style="margin-right:5px" />' +
		'<br />'+
		'<strong>' + this.vars.title + '</strong>' +
		'<br /><br />' +
		'<div style="float:right">' +
		'<input value="' + this.vars.submit_title + '" class="submit" onclick="document.getElementById(\'questionary\').submit();" type="submit" />' +
		'&nbsp;<input type="submit" class="submit" value="' + this.vars.cancel_title + '" onclick="Modal.hide();" />' +
	'</div>'+
	'<div class="clear">&nbsp;</div>&nbsp;';
    },
  validate: function(){
	var questionaryForm = document.getElementById('questionary');
	for (var i= 0; i<questionaryForm.length; i++){
		if(questionaryForm.elements[i].type == 'file'){
			if(questionaryForm.elements[i].value != '') {
				return true;
			}
		}
	}
	return false;
    }
}


var sendToAFriendTemplate = {
  vars : {
	pdjd_id: 0,
	pdjd_name: '',
	pdjd_url: '',
	email_r: '',
	name: '',
	email: ''
	},
  get : function(){
	return '<form style="font-size:11px" name="nazor" method="get" action="/" xmlns="http://www.w3.org/1999/xhtml" onsubmit="return recommendCheck();">'+
			'<input type="hidden" id="pdjd_id" name="pdjd_id" value="' + this.vars.pdjd_id + '"/>' +
			'<input type="hidden" id="pdjd_name" name="pdjd_name" value="' + this.vars.pdjd_name + '"/>' +
			'<input type="hidden" name="jdurl" value="' + this.vars.pdjd_url + '"/>'+
			'<input type="hidden" name="send" value="send"/>'+
			'<input type="hidden" name="module" value="JobForward"/>' +
			'<input type="hidden" name="lang" value="' + URLManager.getLang() + '"/>' +
			'<div class="quad">'+
				'<table cellspacing="0" cellpadding="2" class="txt12">' +
					'<tr>' +
						'<td align="right" style="width:110px; !width: 140px;">' +
							'<span class="red">*</span>' +
							'<strong>' + __('recipientsEmail') + ':</strong>' +
						'</td>' +
						'<td align="right">' +
							'<input class="txtinp" type="text" name="email_r" id="email_r" value="' + this.vars.email_r + '" />' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td align="right">' +
							'<span class="red">*</span>' +
								'<strong>' + __('yourName') + ':</strong>' +
						'</td>'+
						'<td align="right">' +
							'<input class="txtinp" type="text" name="name" id="name_r" value="' + this.vars.name + '" />' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td align="right">' +
							'<span class="red">*</span>' +
							'<strong>' + __('yourEmail') + ':</strong>' +
						'</td>' +
						'<td align="right">' +
							'<input class="txtinp" type="text" name="email" id="youremail_r" value="' + this.vars.email + '" />' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2"> </td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">' +
							'<strong>' + __('message') + ':</strong>' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2" align="right">' +
							'<textarea style="width:290px" class="txtinp" rows="5" name="message"></textarea>' +
						'</td>' +
					'</tr>' +
					'</table>'+
				'</div>'+
				'<div style="float:right">' +
					'<input value="' + __('SEND') + '" class="submit" type="submit"/>' +
				'</div><br /><br />' +
				'<div class="clear">&#160;</div>' +
			'</form>';
	}
}


var recommendToAFriendTemplate = {
  vars : {
		pdjd_id: 0,
		pdjd_name: '',
		pdjd_url: '',
		email_r: '',
		firstname: '',
		surname: '',
		email: '',
		phone: '',
		companyName: ''
	},
  get : function(){
	return '<form action="/" method="get" name="nazor" style="font-size:11px" xmlns="http://www.w3.org/1999/xhtml" onsubmit="return recommendCheck2();">' +
			'<input type="hidden" id="pdjd_id_2" name="pdjd_id" value="' + this.vars.pdjd_id + '" />' +
			'<input type="hidden" id="pdjd_name_2" name="pdjd_name" value="' + this.vars.pdjd_name + '"/>'+
			'<input type="hidden" name="jdurl" value="' + this.vars.pdjd_url + '"/>'+
			'<input type="hidden" name="module" value="JobRecommend"/>'+
			'<input type="hidden" name="send" value="send"/>'+
			'<input type="hidden" name="lang" value="' + URLManager.getLang() + '"/>' +
			'<div class="quad">'+
				'<table class="txt12" cellpadding="2" cellspacing="0">'+
					'<tr>'+
						'<td colspan="2">'+
							'<img style="margin-right: 10px; margin-bottom: 10px; float: left;" src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif"/>'+							
							'<div style="float: left; width: 250px; margin-top: 5px;">' + __('Jobs_JD_T_PreposlatDoporuceniText') + '</div>' +
							'<br style="clear: both" />' +
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td style="width:110px; !width: 140px;" align="right">'+
							'<span class="red">*</span>'+
							'<strong>' + __('recipientsEmailAddress') + ':</strong>'+
						'</td>'+
						'<td>'+
							'<input id="email_r" name="email_r" type="text" class="txtinp" style="width:154px" value="' + this.vars.email_r + '"/>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td align="right">'+
							'<span class="red">*</span>'+
							'<strong>' + __('yourName') + ':</strong>'+
						'</td>'+
						'<td>'+
							'<input id="name_r" name="firstname" type="text" class="txtinp" style="width:154px" value="' + this.vars.firstname + '"/>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td align="right">'+
							'<span class="red">*</span>'+
							'<strong>' + __('yourSurname') + ':</strong>'+
						'</td>'+
						'<td>'+
							'<input id="surname_r" name="surname" type="text" class="txtinp" style="width:154px" value="' + this.vars.surname + '"/>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td align="right">'+
							'<span class="red">*</span>'+
							'<strong>' + __('yourEmail') + ':</strong>'+
						'</td>'+
						'<td>'+
							'<input id="youremail_r" name="email" type="text" class="txtinp" style="width:154px" value="' + this.vars.email + '" />'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td align="right">'+
							'<strong>' + __('yourPhone') +':</strong>'+
						'</td>'+
						'<td>'+
							'<input id="yourphone_r" name="phone" type="text" class="txtinp" style="width:154px" value="' + this.vars.phone + '" />'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td>&#160;</td>'+
						'<td class="txt11">'+
							'<input name="internal_employee" type="checkbox"></input>&#160;' + __('iAmAnEmployeeOf') + ' <span id="firmName">' + this.vars.companyName + '</span>' +
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td colspan="2">&#160;</td>'+
					'</tr>'+
					'<tr>'+
						'<td colspan="2">'+
							'<strong>' + __('message') + ':</strong>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td colspan="2">'+
							'<textarea name="message" rows="5" class="txtinp" style="width:280px"></textarea>'+
						'</td>'+
					'</tr>'+
				'</table>'+
			'</div>'+
			'<div style="float:right">'+
				'<input name="submit" type="submit" class="submit" value="' + __('SEND') + '" />'+
			'</div><br /><br />'+
			'<div class="clear"></div>'+
		'</form>';
	}
}


var positionSentSuccessfulyTemplate = {
  vars : {
	message : '',
    email : ''
	},
  get : function(){
	return '<img class="good_ghost" alt="" src="' + URLManager.getUrl('Jobs_Images2') + 'layout_ghost.gif" align="left">' +
	  '<br/>'+
	  '<strong>' + this.vars.message + '</strong> ' +
	  '<strong id="friendEmaiModal">' + this.vars.email + '</strong><br>' +
	  '<div class="clear">&nbsp;</div>' +
	  '<div style="float: right;">' +
        '<input onclick="Modal.hide();" value=" ' + __('continue') + '" class="submit"  type="submit">'+
      '</div><br /><div class="clear">&nbsp;</div>';
	}
}

var googleMapTemplate = {
		  vars : {
				title: '',
				address: ''
		  },
		  
		  toString: function() {
			  return 'googleMapTemplate';
		  },

		  close: function() {
			  Modal.hide();
		  },
		  
		  showEvent: function() {
			  showAddress("mapModalCanvas", 1);				  				  
			  
		  },
		  
		  
		  get : function(){			  
			return '<div class="modal">' +                   
	  		       '<h2>'+ this.vars.title +'</h2>' +
	               '<h3>' +  this.vars.address + '</h3>' +	               
	               '<div id="mapModalCanvas"></div>' +
	               '<form action="#" method="post" style="font-size:11px; text-align: center;">'+
	               '<input name="button" type="button" class="submit" value="'+ __('modal.global.close') + '" onclick="googleMapTemplate.close();" />'+
	               '</form>'+	                
					'</div>';
		  }
	};
