function showList(obj)
{
 var vobj = document.getElementById(obj);
 if(obj)
 {
  if (vobj.className == 'expanded')
  {
   vobj.style.display = 'none';
   vobj.className = 'collapsed';
  }
  else{
   vobj.style.display = 'block';
   vobj.className = 'expanded';
  }
 }
 else{
  if(document.getElementById('catBox'))
  {
   document.getElementById('catBox').className = 'collapsed';
  }
  else
  {
   return false;
  }
 }
}

var ruki_login, ruki_random, ruki_options, url;

/* Un-trapping page from frameset. */
if (window.top != window) {
	window.top.location = window.location;
}


// redirect to site in value fields;
function sortBySelected(element) {
	window.location = element.options[element.selectedIndex].value;
}

var ie6 = ie7 = false;

function ifIE(){
	var sUserAgent = navigator.userAgent;
	var bIsIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1;
	if (bIsIE) {
		var reIE = new RegExp("MSIE (\\d+\\.\\d+)");
		reIE.test(sUserAgent);
		var fIEVersion = parseFloat(RegExp["$1"]);
		ie6 = fIEVersion >= 6.0 && fIEVersion < 7.0;
		ie7 = fIEVersion >= 7.0;
	}
}

// makes url same as "$context.action" in rewrite.vm
function contextAction(url) {
	url = url.replace(/\?.*$/, '');
	url = url.replace(mainURL, '');
	return url;
}

// boolean get tels that we can use xmlHttpRequest buffer (false for multipart posts and other uncompatible)
function createBuffer (get) {
	var buffer = new Object();
	buffer.xml = false;
	buffer.iframe = false;
	if( get ) {
		buffer.loadData = function(url) {
			var url = URISetParameter(url, 'XMLHttpRequest', 'true');
			buffer.xml.open('GET', url, true);
			buffer.xml.onreadystatechange = function() {
				if (buffer.xml.readyState==4) {
					var action = contextAction(url);
					var content = buffer.xml.responseText;
					if( content.indexOf('<!-- /'+action+' -->')>-1 ) {
						rewrite('/'+action);
					} else {
						content = content.replace(/\n/g, '');
    					content = content.replace(/.*<meta http-equiv="Refresh" content="/i, '');
				    	content = content.replace(/".*/i, '');
				    	var delay = Math.ceil(content);
						if( delay!='NaN' && delay>0 ) { delay = delay*1000; }
						else { delay = 5000; }
						setTimeout(function(){buffer.loadData(url);}, delay);
					}
				}
			}
			if(document.cookie!='') {
				buffer.xml.setRequestHeader('Cookie', document.cookie);
			}
			buffer.xml.send(null);
		}

		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		// JScript gives us Conditional compilation, we can cope with old IE versions.
		// and security blocked creation of the objects.
			try {
				buffer.xml = new ActiveXObject("Msxml2.XMLHTTP");	
			} catch (e) {
				try {
					buffer.xml = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) {
					buffer.xml = false;
				}
			}
		@end @*/
		
		if (!buffer.xml && typeof XMLHttpRequest!='undefined') {
			buffer.xml = new XMLHttpRequest();
		}
	}
	
	if (!buffer.xml) {
		var name = document.getUniqueId ();
	    try {
	        var iframe = document.createElement ("iframe");
	        iframe.style.width = 0;
	        iframe.style.height = 0;
	        iframe.style.border = 0;
	        document.getElementsByTagName ("body").item (0).appendChild (iframe);
	        buffer.iframe = iframe;
	        buffer.iframe.setAttribute ("name", name);
	        buffer.iframe.setAttribute ("id", name);
	        if (typeof buffer.iframe.location == "undefined") {
	            buffer.iframe = frames[frames.length - 1];
	            buffer.iframe.name = name;
	            buffer.iframe.id = name;
	        }
	    } catch (exception) {
	    	// intended to be IE5-only section - the browser that cannot append an iframe
	        var iframeHTML = '<iframe name="'+name+'" id="'+name+'" style="width:0;height:0;border:0"></iframe>';
	        document.getElementsByTagName ("body").item (0).insertAdjacentHTML ("beforeEnd", iframeHTML);
	        buffer.iframe = frames[name];
	    }
	    
	    buffer.loadData = function(url) {
	    	buffer.iframe.location = url;
	    }
	}
	
    return buffer;
}


function flush (buffer) {
    var content = "";
    if(buffer.xml) {
    	content = buffer.xml.responseText;
    } else if (typeof buffer.iframe.contentDocument != "undefined") {
        content = buffer.iframe.contentDocument.body.innerHTML;
        content = content.replace( /\\"/g, "&quot;" )
        buffer.iframe.contentDocument.body.innerHTML = "";
    } else if (typeof buffer.iframe.contentWindow != "undefined") {
        content = buffer.iframe.contentWindow.document.body.innerHTML;
        buffer.iframe.contentWindow.document.body.innerHTML = "";
    } else if (typeof buffer.iframe.document!="undefined") {
    	content = buffer.iframe.document.body.innerHTML;
        buffer.iframe.document.body.innerHTML = "";
    }
    var patern = new RegExp( '<!-- .+ -->', 'g' );
	content = content.replace( patern, '' );
    return content;
}

/* sends query to statistics site */
function sendQueryStats(url) {
	var oImg = new Image();
	oImg.src = url;
	return true;
}


function setFieldsSequence (form) {
    var loop;
    var hidden = document.createElement ("input");
    hidden.type = "hidden";
    hidden.name = "fieldsSequence";
    for (loop = 0; loop < form.elements.length; loop ++) {
        if (form.elements[loop].type != "submit"
         && form.elements[loop].type != "reset"
         && form.elements[loop].type != "button"
         && (form.elements[loop].type != "hidden" || form.elements[loop].name.indexOf('s_')==0) ) {
             hidden.value += form.elements[loop].name + ",";
        }
    }
    hidden.value = hidden.value.replace (/,$/, "");
    for (loop = 0; loop < form.elements.length; loop ++) {
        if (form.elements[loop].name == hidden.name) {
            form.elements[loop].value = hidden.value;
            return;
        }
    }
    form.appendChild (hidden);
}

function allFormsSetFieldsSequence () {
    for (loop = 0; loop < document.forms.length; loop ++) {
        if (document.forms[loop].className.indexOf ("sequence") != -1) {
            setFieldsSequence (document.forms[loop]);
        }
    }
}
// #847
//
//if (w3cDOM) {
//	listenEvent (window, "load", allFormsSetFieldsSequence);
//}

/* Sets clipboard indicator and ads actions to clipboard icons on ad list */
function clipboard() {
	var container;
	var itemsCount=0;

	var clipboardList = getCookie( 'clipboard' );
	if( clipboardList ) {
		clipboardList = clipboardList.replace( /^\*/, '' );
		for( var i=0; i<clipboardList.length; i++ ) {
			if(clipboardList.charAt(i) == '|') itemsCount++;
		}		
		clipboardList = '|' + clipboardList;
	} else {
		clipboardList = '';
	}
	
	if( document.getElementById('clipboardCount') ) {
    	document.getElementById('clipboardCount').innerHTML = "("+itemsCount+")";
	}
	
	if( !(container = document.getElementById('advertsListContainer')) ) {
    	return false;
    }
	
	if( document.getElementById('clipboardCountHeader') ) {
		document.getElementById('clipboardCountHeader').innerHTML = "("+itemsCount+")";
	}
	
	var images = container.getElementsByTagName( 'a' );
	for( var i = 0; i<images.length; i++ ) {
        if( images.item(i).className=='bluePlus' ) {
          var checkbox = images.item(i);
        	checkbox.value = checkbox.id.replace( /clipboard/, '' );
        	if( clipboardList.indexOf( '|' + checkbox.value + '|' )>-1 ) {
        		checkbox.className = 'blueMinus';
				//checkbox.src = checkbox.src.replace(/clipboard_off/g, 'clipboard_on');
				checkbox.innerHTML = delFromClipboard;
				//checkbox.alt = delFromClipboard;
				checkbox.title = delFromClipboard;
			} else {
				checkbox.innerHTML = addToClipboard;
				//checkbox.alt = addToClipboard;
				checkbox.title = addToClipboard;
			}
			checkbox.onclick = function() {
              var list = getCookie( 'clipboard' );
            	if( list==null ) { list = '' }
            	else { list = list.replace( /^\*/, '' ); } // this one removes additional * added as sign that this cookie is from JS
				if( this.className=='bluePlus' ) {
            		if( clipbordMaxSize && itemsCount==clipbordMaxSize ) {
            			var removeElement = list.substr( 0, list.indexOf( '|' ) );
            			var removeSelectionCheckbox = document.getElementById( 'clipboard'+removeElement );
            			if( removeSelectionCheckbox ) {
            				removeSelectionCheckbox.className = 'bluePlus';
            				//removeSelectionCheckbox.src = checkbox.src.replace(/clipboard_on/g, 'clipboard_off');
            				//removeSelectionCheckbox.alt = addToClipboard;
            				removeSelectionCheckbox.innerHTML = addToClipboard;
							removeSelectionCheckbox.title = addToClipboard;
            			}
            			list = list.replace( /^[0-9]+[^0-9]/, '' );
            			itemsCount--;
            		}
            		list += this.value + '|';
            		if( getCookie( 'userName' )!=null ) {
            			var clipboardTmp = new Image();
            			clipboardTmp.src = mainURL + '/addToClipboard.do?aid=' + this.value + '&js=true';
            		}
            		itemsCount++;
            		this.className = 'blueMinus';
            		//this.src = checkbox.src.replace(/clipboard_off/g, 'clipboard_on');
					this.alt = delFromClipboard;
					this.innerHTML = delFromClipboard;
					this.title = delFromClipboard;
            	} else if( list.length>0 ) {
            		list = '|' + list;
            		var patern = new RegExp( '[^0-9]+'+this.value+'[^0-9]+', 'g' );
            		list = list.replace( patern, '|' );
            		list = list.replace( /^[^0-9]+/g, '' );
            		if( getCookie( 'userName' )!=null ) {
            			var clipboardTmp = new Image();
            			clipboardTmp.src = mainURL + '/removeFromClipboard.do?aid=' + this.value + '&js=true';
            		}
	            	itemsCount--;
	            	this.className = 'bluePlus';
	            	//this.src = checkbox.src.replace(/clipboard_on/g, 'clipboard_off');
            		this.alt = addToClipboard;
					this.title = addToClipboard;
					this.innerHTML = addToClipboard;
            	}
            	list = '*' + list; // this adds additional * as sign that this cookie is from JS
            	setCookie( 'clipboard', list, 365 );
            	if( document.getElementById('clipboardCount') ) {
			    	document.getElementById('clipboardCount').innerHTML = "("+itemsCount+")";
				}
				if( document.getElementById('clipboardCountHeader') ) {
					document.getElementById('clipboardCountHeader').innerHTML = "("+itemsCount+")";
				}
        return false;
            };
		}
	}
}


if (w3cDOM) {
	listenEvent (window, "load", clipboard);
}


function decText(what) {
   /* max. single word length */
   var maxWordLength = 40;

   var itemText = what.value;
   var itemLength = itemText.length;
   var errorReport = 0;
   var errorMsg = decText_errorMsg1 + " " + maxWordLength + " " + decText_errorMsg2;
   var wyrReg = /([^\.\,\;\:\-][\.\,\;\:\-])([^\.\,\;\:\-\ ])/g;

   stringArr = new Array();
   stringArr = itemText.split(' ');
   arrLength = stringArr.length;

   for(i=0;i<arrLength;i++) {
      if(stringArr[i].length > maxWordLength) {
         errorReport = 1;
	     stringArr[i] = stringArr[i].substr(0, maxWordLength);
	     stringArr[i] = stringArr[i].replace(wyrReg, "$1 $2");
      }
   }

   if(errorReport == 1) {
      alert(errorMsg);
      what.value = stringArr.join(' ');
   }

   /* Add spaces after some chars (for example - after dot) */
   //what.value =what.value.replace(wyrReg, "$1 $2");
}

function setCaretToEnd (el) {
  if (el.createTextRange) {
    var v = el.value;
    var r = el.createTextRange();
    r.moveStart('character', v.length);
    r.select();
  }
}

function changeCurrency() {
    var p_lo = document.getElementById ("s_lo_price");
    var p_go = document.getElementById ("s_go_price");
    var curr = document.getElementById ("s_eq_currency");
    
	if( p_lo && p_go && curr ) {
		var fieldsSequence = curr.form.elements['fieldsSequence'];
		if( fieldsSequence ) {
			var oldCurrency = document.getElementById( 's_lo_price' ).name.replace( /s_lo_price_/, '' );
			var re = new RegExp('_price_'+oldCurrency, "g");
			fieldsSequence.value = fieldsSequence.value.replace(re, '_price_'+curr.options[curr.selectedIndex].value.toLowerCase())
		}
	    p_lo.name = 's_lo_price_' + curr.options[curr.selectedIndex].value.toLowerCase ();
	    p_go.name = 's_go_price_' + curr.options[curr.selectedIndex].value.toLowerCase ();
	}
    return false;
}



/*****************************************************************************************/
/******************************* DEPENDANT DICTIONARIES **********************************/
/*****************************************************************************************/
/*                                                                                       */
/*    use velocimacro #macro( dependantDictionariesFields $fields )                      */
/*    to set init data for dependant dictionaries                                        */
/*                                                                                       */
/*    call javascript function initDependantDictionaries()                               */
/*    to initiate javascript dependant dictionaries functions                            */
/*                                                                                       */
/*    and                                                                                */
/*                                                                                       */
/*    function rewrite (action) {                                                        */
/*        switch (action) {                                                              */
/*            case dependantDictionaryAction:                                            */
/*                renderDependantDictionary();                                           */
/*                break;                                                                 */
/*        }                                                                              */
/*    }                                                                                  */
/*                                                                                       */
/*****************************************************************************************/

var URIDependantDictionaries;

var dependantDictionaries = new Array();
var dependantDictionariesLoadingIndex = 0;
var dependantDictionaryLoading = false;
var dependantDictionaryLoadingField = null;
var dependantDictionaryOnLoadActionLetancy;
var dependantDictionaryLoadDictionaryActionLetancy;

var dependantDictionaryAction = "/modules/dependantList.do";
var dependantDictionaryBuffer;

function dependantField( id, dictionary, value, parent, child ) {
	this.id = id;
	this.dictionary = dictionary;
	this.value = value;
	this.parent = parent;
	this.child = child;
}

function initDependantDictionaries() {
	dependantDictionaryBuffer = createBuffer(true);
	
	var initCodeNodes = document.getElementsByTagName( 'code' );
	var initCode = '';
	for( var i=0; i<initCodeNodes.length; i++ ) {
		initCode += initCodeNodes[i].innerHTML;
	}
	
	eval( initCode );
	
	function loadDictionary() {
		return( function(){
			var field = dependantDictionaryLoadingField;
			if( field!=null && !dependantDictionaryLoading ) {
				dependantDictionaryLoading = true;
				var node = document.getElementById( field.id );
				if( node.type=='text' ) {
					if( field.parent.value!='' ) {
						if( field.id.indexOf('s_eq_')==0 ) {
							field.id = field.id.replace( /s_eq_/, 's_qu_' );
						}
						
						field.dictionary = field.parent.dictionary + ':' + field.parent.value;
						dependantDictionaryLoadingField = field;
						
						var newNode = document.createElement( 'span' );
						newNode.id = field.id;
						var loadingTextNode = document.createTextNode( loading );
						newNode.appendChild( loadingTextNode );
						
						node.parentNode.replaceChild( newNode, node );
						
						var URI = URISetParameter( URIDependantDictionaries, 'field', encodeToURI(field.id) );
						URI = URISetParameter( URI, 'parentDictionaryName', encodeToURI(field.parent.dictionary) );
						URI = URISetParameter( URI, 'parentDictionaryValue', encodeToURI(field.parent.value) );
						URI = URISetParameter( URI, 'dictionaryValue', encodeToURI(field.value) );
						
						dependantDictionaryBuffer.loadData( URI );
					}
				} else {
					var onChangeAction = dependantDictionary( field );
					listenEvent( node, 'change', onChangeAction );
					
					dependantDictionaryLoadingField = dependantDictionaryLoadingField.child;
					if( dependantDictionaryLoadingField==null ) {
						dependantDictionariesLoadingIndex++;
						if( dependantDictionariesLoadingIndex>=dependantDictionaries.length ) {
							window.clearInterval( dependantDictionaryOnLoadActionLetancy );	
						} else {
							dependantDictionaryLoadingField = dependantDictionaries[dependantDictionariesLoadingIndex];
						}
					}
					dependantDictionaryLoading = false;
				}
			}
		} );
	}
	
	if( dependantDictionaries.length>0 ) {
		dependantDictionaryLoadingField = dependantDictionaries[0];
			
		var loadDictionaryAction = loadDictionary();
		dependantDictionaryLoadDictionaryActionLetancy = window.setInterval( loadDictionaryAction, 200 );
	}
}

function dependantDictionary( field ) {
	return( function() {
		var changedNode = document.getElementById( field.id );
		field.value = changedNode.options[changedNode.selectedIndex].value;
		if( field.child==null ) return true;
		
		var fieldTmp = field.child;
		while( fieldTmp!=null ) {
			var node = document.getElementById( fieldTmp.id );
			if( node && fieldTmp.dictionary!='' ) {
				var newNode = document.createElement( 'input' );
				newNode.type = 'text';
				if( fieldTmp.id.indexOf('s_eq_')==0 ) {
					fieldTmp.id = fieldTmp.id.replace( /s_eq_/, 's_qu_' );
				}
				newNode.id = fieldTmp.id;
				newNode.name = fieldTmp.id;
				newNode.value = '';
				node.parentNode.replaceChild( newNode, node );
			}
			fieldTmp.value = '';
			fieldTmp.dictionary = '';
			fieldTmp = fieldTmp.child;
		}

		
		
		if( field.value=='' ) return true;
		
		dependantDictionaryLoading = true;
		dependantDictionaryLoadingField = field.child;

		var node = document.getElementById( field.child.id );
		var newNode = document.createElement( 'span' );
		newNode.id = field.child.id;
		var loadingTextNode = document.createTextNode( loading );
		newNode.appendChild( loadingTextNode );
		
		node.parentNode.replaceChild( newNode, node );
		
		field.child.dictionary = field.dictionary + ':' + field.value;
		
		var URI = URISetParameter( URIDependantDictionaries, 'field', encodeToURI(field.child.id) );
		URI = URISetParameter( URI, 'parentDictionaryName', encodeToURI(field.dictionary) );
		URI = URISetParameter( URI, 'parentDictionaryValue', encodeToURI(field.value) );
		URI = URISetParameter( URI, 'dictionaryValue', encodeToURI(field.child.value) );
		
		dependantDictionaryBuffer.loadData( URI );
	} );
}

function renderDependantDictionary() {
	var node = document.getElementById( dependantDictionaryLoadingField.id );
	
	if( node ) {
		var parent = node.parentNode;
		
		parent.removeChild( node );
		parent.innerHTML += flush( dependantDictionaryBuffer );
		
		function addOnLoadAction() {
			return( function() {
				var field = dependantDictionaryLoadingField;
				var node = document.getElementById( field.id );
				if( field && node ) {
					if( node.type!='text' ) {
						var onChangeAction = dependantDictionary( field );
						listenEvent( node, 'change', onChangeAction );
					} else if( node.name.indexOf('s_qu_')==0 ) {
						field.id = field.id.replace( /s_qu_/, 's_eq_' );
						node.id = field.id;
						node.name = field.id;
					}
					if(node.id.indexOf('s_')==0 && node.value != ''){
						node.className='sel single';
					}else if( node.id.indexOf('s_')==0 ){
						node.className='single';
					}
					window.clearInterval( dependantDictionaryOnLoadActionLetancy );
				}
				
				dependantDictionaryLoadingField = dependantDictionaryLoadingField.child;
				if( dependantDictionaryLoadingField==null ) {
					dependantDictionariesLoadingIndex++;
					if( dependantDictionariesLoadingIndex>=dependantDictionaries.length ) {
						window.clearInterval( dependantDictionaryOnLoadActionLetancy );	
					} else {
						dependantDictionaryLoadingField = dependantDictionaries[dependantDictionariesLoadingIndex];
					}
				}
				dependantDictionaryLoading = false;
			} );
		}
		var onLoadAction = addOnLoadAction();
		dependantDictionaryOnLoadActionLetancy = window.setInterval( onLoadAction, 100 );
	}
}

function showDD() {
	var text = '';
	for( var i=0; i<dependantDictionaries.length; i++ ) {
		var field = dependantDictionaries[i];
		while( field!=null ) {
			text += "\n"+field.id+" & "+field.value+" & "+field.dictionary
			field = field.child;
		}
	}
	return text;
}

/**************************** END OF DEPENDANT DICTIONARIES ******************************/
/*****************************************************************************************/



function writeBanner (url, width, height) {
	var classNameAppendix = "";
	if (/234_90_\d/.test (url)) {
		classNameAppendix += url.replace (/.*234_90_(\d).*/, "no$1");
	}
document.write ('<iframe src="' + url +
                '" width="' + width +
                '" height="' + height +
                '" class="' + classNameAppendix +
                '" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe>');
}

// script expanding or collapsing additional contact data in placeing and editing ad
function adDetailsContactData() {
	var contactDataContainer = document.getElementById( 'contactDataContainer' );
	if( contactDataContainer ) {
		var expandContactDataLink = document.getElementById( 'expandContactDataLink' );
		if( expandContactDataLink ) {
			expandContactDataLink.onclick = function() {
				var contactDataContainer = document.getElementById( 'contactDataContainer' );
				if( contactDataContainer ) {
					if( this.className=='expanded' ) {
						contactDataContainer.style.display = 'none';
						this.style.background = 'transparent url(\''+imgPath+'icoExpand.gif\') left center no-repeat';
						this.className = 'collapsed';
						return false;
					} else if( this.className=='collapsed' ) {
						contactDataContainer.style.display = 'block';
						this.style.background = 'transparent url(\''+imgPath+'icoCollapse.gif\') left center no-repeat';
						this.className = 'expanded';
						return false;
					}
				}
			}
		}
		
		var elements = contactDataContainer.getElementsByTagName( 'input' );
		for( var i = 0; i<elements.length; i++ ) {
			if( elements.item(i).value && elements.item(i).value!='' ) {
				contactDataContainer.style.display = 'block';
				expandContactDataLink.style.background = 'transparent url(\''+imgPath+'icoCollapse.gif\') left center no-repeat';
				expandContactDataLink.className = 'expanded';
				return false;
			}
		}
	}
}


// only for ie
var ieSelectedOptions = new Array();
var ieSelectedOptionsWait;
function ieSelectedOptionsCheck() {
	var select = document.getElementById( 'regionsMultipleSelect' );

	for( var i = 1; i<select.options.length; i++ ) {

		if(selectedRegions.indexOf(""+select.options[i].value) != -1){
			select.options[i].selected = true;
		}
		window.clearInterval( ieSelectedOptionsWait );
	}
}

function writeRootRegions() {
	
	var select = document.createElement('select');
	select.name = "rootRegion";
	
	
	regionsListsWhere.insertBefore( select, regionsListsWhere.firstChild );
	
	select.options[0] = new Option( filterAll, '' );
	
	var nextOption = 0;
	for( region in regions.childrens ) {
		nextOption = select.options.length;
		select.options[nextOption] = new Option( regions.childrens[region].printableName, regions.childrens[region].id );
		if( regions.childrens[region].id == rootRegion ){
			select.options[nextOption].selected = true;
		}
		
	}
	
	select.onchange = function() {
		var multiple = document.getElementById('regionsMultipleSelect');
		if(multiple){
			multiple.parentNode.removeChild( multiple );
		}
		if( select.value != '' ){
			URIRegionsList  = URISetParameter( URIRegionsList, "rid", select.value );
			regionsBuffer.loadData( URIRegionsList );
			LocalizationIsSet = false;
		}

		if( select.selectedIndex < 1 ) {
			select.className = 'single';
		} else {
			select.className = 'single sel';
		}
	}
	select.onchange();
	
}

function writeSubRegions() {
	//for( var i = 0; i<selectedRegions.length; i++ ) {
	//	regions.childrens[selectedRegions[i]].selected = true;
	//}
	
	var select = document.createElement('select');
	select.name = "s_eq_regions";
	
	select.multiple = true;
	select.id = 'regionsMultipleSelect';
		
	regionsListsWhere.appendChild( select, regionsListsWhere );
	
	select.options[0] = new Option( filterAll, regions.id );
	
	var nextOption = 0;
	for( region in regions.childrens ) {
		nextOption = select.options.length;
		select.options[nextOption] = new Option( regions.childrens[region].printableName, regions.childrens[region].id );
		if(selectedRegions.indexOf(""+regions.childrens[region].id) != -1){
			select.options[nextOption].selected = true;
			ieSelectedOptions[ieSelectedOptions.length] = nextOption;
		}

	}

	if( select.selectedIndex < 1){
		select.className = 'multipleSelect single';
		select.options[0].selected = true;
	}else{
		select.className = 'multipleSelect single sel';
	}
	
	ieSelectedOptionsWait = window.setInterval( "ieSelectedOptionsCheck()", 100 );
}


/* kisokos WebSiteInputCheck */
function addressInput() {
	var adres = document.getElementById( 'website' );
	if(adres.value == "") {
		adres.value = "http://";
	}
}

function onBlurAddressInput() {
	var adres = document.getElementById( 'website' );
	if(adres.value == "http://") {
		adres.value = "";
	}
	if(adres.value.substring(0,7) != "http://") {
		if (adres.value != "") {
			alert("Hibás url formátum");
		}
	}
}
/*end*/

function ShowHideWelcomeBlock(op) {
	document.getElementById('welcomeBlock').style.display = (op) ? "none" : "block";
	document.getElementById('linkAddMoreInfo1').style.display = (op) ? "block" : "none";
	document.getElementById('linkHideMoreInfo1').style.display = (op) ? "none" : "block";
	}	


function changePage(element){
  url = document.URL;
  var gotoPage = element.value.replace(',','%2C');
  var newUrl = '';
    if(url.match(/&page=.*&/)){
      newUrl = url.replace(/&page=.*&/,'&page='+gotoPage+'&');
    }else if(url.match(/&page=.*$/)){
      newUrl = url.replace(/&page=.*$/,'&page='+gotoPage);
    }else if(url.match(/\?page=.*&/)){
      newUrl = url.replace(/&page=.*$/,'?page='+gotoPage+'&');
    }else if(url.match(/\?page=.*$/)){
      newUrl = url.replace(/\?page=.*$/,'?page='+gotoPage);
    }else if(url.match(/\?/)){
      newUrl = url+'&page='+gotoPage;
    }else{
      newUrl = url+'?page='+gotoPage;
    }
  window.location = newUrl;
}

function changePageRev(element){
  url = document.URL;
  var gotoPage = element.value;
  var newUrl = '';
    if(gotoPage == 1){
      if(url.match(/index.*$/)){
	  	newUrl = url.replace(/index.*$/,'');
	  }
    }else{
		if(url.match(/index.*$/)){
			newUrl = url.replace(/index.*$/,'');
		}
		newUrl = newUrl+"index" + gotoPage + ".html";
    }
  window.location = newUrl;
}

//searchbox

searchBoxMultiSelectInit = function() {
	regionListonchange = function(){		
		var checkboxes = regionList.getElementsByTagName('input');
		var regionsId = document.getElementById('regionsId');
		var regionsIdElement = document.getElementById('regionsIdElement');
		var isChecked = false;
		for(var i=0; i<checkboxes.length; i++){
			if(checkboxes[i].checked){
				isChecked = true;
				break;
			}
		}		
		if(isChecked) {
			if(regionsId)
				regionsIdElement.removeChild(regionsId);
		}
		else{
			var input = document.createElement("input");
	        input.type = "hidden";
	        input.name = "s_eq_regions";
	        input.value = currentRegion;
	        input.id = "regionsId";
	        regionsIdElement.appendChild(input);			
		}
	}
  var regionSelect = document.getElementById('searchDistrict');
  var regionList = document.getElementById('searchSubDistrict');	
  var selectAll = document.getElementById('multiselectSelectAll')	
  var deselectAll = document.getElementById('multiselectDeselectAll') 
  if( regionSelect && regionList && multiselectData){
	var regionSelectFill = function(){
		setCookie('regionSelectIndex', regionSelect.selectedIndex, 365);
      regionList.innerHTML = '';
      var subregions = regionSelect.options[regionSelect.selectedIndex].childrens;
	  if(subregions.length==0){
		var regionsId = document.getElementById('regionsId');
		var regionsIdElement = document.getElementById('regionsIdElement');
		var div = document.createElement("div");
        var input = document.createElement("input");
        input.type = "checkbox";   
		input.name = "s_eq_regions";
		input.value = regionSelect.options[regionSelect.selectedIndex].value;
		input.id = "region"+regionSelect.options[regionSelect.selectedIndex].value;
		div.appendChild(input);
		var label = document.createElement("label")
        label.setAttribute('for', "region"+regionSelect.options[regionSelect.selectedIndex].value);
        div.appendChild(label);
        
		var labelText = document.createTextNode("Csak ebben a régióban");
				
		label.appendChild(labelText);
		regionList.appendChild(div);
	  }	  
	  for( var i=0; i < subregions.length; i++ ){         
		var div = document.createElement("div");
        var input = document.createElement("input");
        input.type = "checkbox";
        input.name = "s_eq_regions";
        input.value = subregions[i].id;
        input.id = "region"+subregions[i].id;
		listenEvent(input, 'click', function() { regionListonchange(); });
        div.appendChild(input);
        var label = document.createElement("label")
        label.setAttribute('for', "region"+subregions[i].id);
        div.appendChild(label);
        var labelText = document.createTextNode(subregions[i].name)
        label.appendChild(labelText);
        regionList.appendChild(div);
      }
    }
    //regionSelect.options[0] = new Option("-");
    for( var i=0; i<multiselectData.length; i++ ){
      regionSelect.options[i] = new Option(multiselectData[i].name);
      regionSelect.options[i].value = multiselectData[i].id;
      regionSelect.options[i].childrens = multiselectData[i].childrens;
    }
    
    regionSelect.onchange = regionSelectFill;
    if(!regionSelect.selectedIndex){
      regionSelect.selectedIndex = getCookie('regionSelectIndex');
			if(!regionSelect.selectedIndex || regionSelect.selectedIndex < 0)
				regionSelect.selectedIndex = 0;
    }
    regionSelectFill();	
	
	
    changeAll = function( element, state ){
      var checkboxes = element.getElementsByTagName('input');
      for(var i=0; i<checkboxes.length; i++){
        checkboxes[i].checked = state;
      }
		var regionsId = document.getElementById('regionsId');
		var regionsIdElement = document.getElementById('regionsIdElement');
		if(state) {
			if(regionsId)
				regionsIdElement.removeChild(regionsId);
		}
    }

    selectAll.onclick = function(){
      changeAll( regionList, true );
    //  multiselectSelectAll();      
      return false;
    }

    deselectAll.onclick = function(){
      changeAll( regionList, false );
      return false;
    }
  }
}

if (w3cDOM) {
  listenEvent (window, "load", searchBoxMultiSelectInit );
}


//var picturesGallery = null;
function openPicturesGallery(url,top,left,width,height) {
  var p = "";
  if (top>-1) p=",top="+top;
  if (left>-1) p=p+",left="+left;
  if (width>-1) p=p+",width="+width;
  if (height>-1) p=p+",height="+height;
//  if(!picturesGallery || picturesGallery.closed){
    picturesGallery = window.open(url,'pictureGallery','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0'+p);
//  }else{
//    picturesGallery.location = url;
//  }
//  return false;
}

// below advertisersTypeChanger() function is evoked in submitSearchForm() javaScript function
// and changes 'name' attribute to searching PS or SU adverts in #semiAdvancedSearchFieldAdvertisersType() macro
function advertisersTypeChanger() {
	if( document.getElementById("advertisersType") ) {
		var advertisersHandler = document.getElementById("advertisersType");
		if( advertisersHandler.selectedIndex == 1 ) {
			advertisersHandler.name = "s_eq_pseller_id";
		}
		else if( advertisersHandler.selectedIndex == 2 ) {
			advertisersHandler.name = "s_ne_pseller_id";
		}
		else {
			advertisersHandler.name='all_advertisers';
		}
	}
}

function submitSearchForm(form) {

  	var regionList = document.getElementById('searchSubDistrict');	
	var inputs = form.getElementsByTagName('input');
	var x = [];
	var anychecked=false;
	var allchecked=false;

	/*
		1.) There is any checked field?
		2.) When 1.) true; All of the fields were checked?
		3.) When 2.) false and 1.) true there is some checked fields to join.
		4.) Else there aren't any checked fields or all of the fields were checked, we filtering the county.
	
	*/

	for( var i = 0; i < inputs.length; i++ ) { 
		if (inputs[i].checked==true) {
				anychecked=true;
			} 
	}

	
	if (anychecked==true)
	{
		for( var i = 0; i < inputs.length; i++ ) {
			if (inputs[i].checked==false) {
				allchecked=false;
			}
		}
	}

	if (anychecked==true && allchecked==false)
	{
		for( var i = 0; i < inputs.length; i++ )
		{
				if ( inputs[i].checked )
				{
					x.push( inputs[i].value );
					
					if(x.length>1 && x[0]==1) {x.shift()}
					
					form.elements['s_in_regions'].value = '';
					form.elements['s_in_regions'].value = x.join(',');
					
					
					for( var j = 0; j < inputs.length; j++ ){
						if( inputs[j].name == 's_eq_regions' )
							inputs[j].disabled = true;
						}

				}
				
		}		
				
	}
	else
	{
		var mselectIndex = document.getElementById('searchDistrict').selectedIndex;
		var mselect = document.getElementById('searchDistrict');
		form.elements['s_in_regions'].value = mselect[mselectIndex].value;				
	}
		
	advertisersTypeChanger(); 
	form.submit();
	for( var i = 0; i < inputs.length; i++ ){
		if( inputs[i].name == 's_eq_regions' )
		inputs[i].disabled = false;
	}
	return false;
}

function reloadCaptcha( reloadCaptchaURL ){
	
	$.ajax({
  type: "GET",
  url: reloadCaptchaURL,
  success: function(response){
 	document.getElementById('captchaImage').innerHTML = response; }
})
}
function showHideCaptchaBlock(action){
	if(arguments.length > 1){
		var param = arguments[1];
	}else{
		var param = "false";
	}
	var captcha = document.getElementById('moreContactDataBox');
	var captchaLink = document.getElementById('captchaShowLink');
	if(captcha.style.display == 'none'){
		captchaLink.style.display = 'none';
		captcha.style.display = 'block';
		if (param == 'false') {
			reloadCaptcha(action);
		}
	}else{
		if (param == 'false') {
			captcha.style.display = 'none';
		}
	}
}

function createQueryElement(queryParentId,queryParamsId){
		var queryParent = document.getElementById(queryParentId);
	    var myp = queryParent.getElementsByTagName('p');
	    var query = document.createElement('span');
	    query.className = 'linkQuery showQuery';
	    myp[0].appendChild(query);
	    query.innerHTML=queryTextShow;
	    var queryParams = document.getElementById(queryParamsId);
		query.onclick=function(){
	        if(queryParams.style.display != 'none'){
	            query.innerHTML=queryTextShow;
	            queryParams.style.display = 'none';
	            query.className = 'linkQuery showQuery'
	        }else{
	            query.innerHTML=queryTextHide;
	            queryParams.style.display = 'block';
	            query.className = 'linkQuery hideQuery'
	        }
	    }
}

/* password strength indicator */
function passwordChanged(pwd, userName,maxLength){
    var strength = document.getElementById('strength');
    var strongRegex = new RegExp("^(?=.{9,})((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[-\/\.\*\+\?\|\(\)\{\}\^\$~`\'\":\;!@#%&_=<>,\\\\\\[\\]])).*$", "g");
    var mediumRegex = new RegExp("^(?=.{8,})|(?=.{6,})(((?=.*[A-Z])(?=.*[a-z]))|(((?=.*\\s)|(?=.*[A-Z])|(?=.*[a-z]))(?=.*[0-9]))|(((?=.*\\s)|(?=.*[A-Z])|(?=.*[a-z])|(?=.*[0-9]))(?=.*[-\/\.\*\+\?\|\(\)\{\}\^\$~`\'\":\;!@#%&_=<>,\\\\\\[\\]])))|((?=.*\\s)((?=.*[A-Z])|(?=.*[a-z]))).*$", "g");
    var enoughRegex = new RegExp("^[\\s]*$", "g");
	var weak = document.getElementById('strength-weak');
	var medium = document.getElementById('strength-medium');
	var strong = document.getElementById('strength-strong');
       if (enoughRegex.test(pwd.value) == true || pwd.value.length < 6 || pwd.value == userName ){
        	pwd.className = 'fillError';
			weak.style.display = 'none';
			medium.style.display = 'none';
			strong.style.display = 'none';
        }
		else if (pwd.value.length > maxLength){
            pwd.className = 'fillError';
            pwd.value = pwd.value.substr(0, maxLength);
            alert(maxPasslength);
            pwd.className = '';
        }
        else if (strongRegex.test(pwd.value)) {
            strong.style.display = 'block';
            pwd.className = '';
			medium.style.display = 'block';
			weak.style.display = 'block';
        }
        else if (mediumRegex.test(pwd.value)) {
            medium.style.display = 'block';
			weak.style.display = 'block';
            pwd.className = '';
            strong.style.display = 'none';
        }
        else {
            weak.style.display = 'block';
            pwd.className = '';
            medium.style.display = 'none';
			strong.style.display = 'none';
        }
	}