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)
var createOrigoIframe = "false";
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!='') {
				try{
					buffer.xml.setRequestHeader('Cookie', document.cookie);
				}
				catch (exception) {
				}
			}
			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;
			if(createOrigoIframe == "false"){
				document.getElementsByTagName ("body").item (0).appendChild (iframe);
			}
			else
			{
				document.getElementsByTagName ("div").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>';
			if(createOrigoIframe == "false")
			{
	        	document.getElementsByTagName ("body").item (0).insertAdjacentHTML ("beforeEnd", iframeHTML);
			}
			else
			{
				document.getElementsByTagName ("div").item (0).appendChild (iframe);
			}
	        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, '' );
	patern = new RegExp( '<script(.|\n)*</script>', 'g' );
	if(content.match(patern)) {
		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);
//}

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.toString().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 = 'selLong single';
		} else {
			select.className = 'selLong 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.toString().indexOf(regions.childrens[region].id) != -1){
			select.options[nextOption].selected = true;
			ieSelectedOptions[ieSelectedOptions.length] = nextOption;
		}

	}

	if( select.selectedIndex < 1){
		select.className = 'multipleSelect selLong single';
		select.options[0].selected = true;
	}else{
		select.className = 'multipleSelect selLong 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";
	}	

	
	/* birth date should be selectable (TT1682) */
var oBirthDate, oBirthDateDay, oBirthDateMonth, oBirthDateYear;
function initBirthDate() {
	oBirthDate = document.getElementById('birth-date');
	
	if( oBirthDate ) {
		
		var aBirthDate = new Array();
		aBirthDate = oBirthDate.value.split('-');
		
		oBirthDate.style.display = 'none';
		
		oBirthDateDay = document.createElement('input');
		oBirthDateDay.id = 'birthDateDay';
		oBirthDateDay.size = 2;
		oBirthDateDay.maxLength = 2;
		if( aBirthDate.length>=1 ) {
			oBirthDateDay.value = aBirthDate[0];
		}
		oBirthDateDay.onchange = function() {
			birthDate();
		}
		oBirthDate.parentNode.insertBefore(oBirthDateDay, oBirthDate);
		
		var aMonthNames = new Array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
		var iSelectedIndex = 0;
		oBirthDateMonth = document.createElement('select');
		oBirthDateMonth.id = 'birthDateMonth';
		oBirthDateMonth.onchange = function() {
			birthDate();
		}
		oBirthDate.parentNode.insertBefore(oBirthDateMonth, oBirthDate);
		/* It does not work in IE 5.0. Corrected below.
		oBirthDateMonth.options[0] = new Option('', '');
		for(var i=0; i<aMonthNames.length; i++) {
			var sValue = zeroFill((i+1).toString(), 2);
			oBirthDateMonth.options[oBirthDateMonth.options.length] = new Option(aMonthNames[i], sValue);
			if( aBirthDate.length>=2 && aBirthDate[1]==sValue ) {
				iSelectedIndex = i+1;
			}			
		}*/
		var oDocument = oBirthDateMonth.ownerDocument;
		if(!oDocument) {
			oDocument = oBirthDateMonth.document;
		}
		var oOption = oDocument.createElement('option');
		oOption.value = '';
		oOption.text = '';
		oBirthDateMonth.options.add(oOption, 0);
		for(var i=0; i<aMonthNames.length; i++) {
			var sValue = zeroFill((i+1).toString(), 2);
			
			var oOption = oDocument.createElement('option');
			oOption.value = sValue;
			oOption.text = aMonthNames[i];
			oBirthDateMonth.options.add(oOption, i+1);
			
			if( aBirthDate.length>=2 && aBirthDate[1]==sValue ) {
				iSelectedIndex = i+1;
			}
		}			
		oBirthDateMonth.options[iSelectedIndex].selected = true;
		
		oBirthDateYear = document.createElement('input');
		oBirthDateYear.id = 'birthDateYear';
		oBirthDateYear.size = 4;
		oBirthDateYear.maxLength = 4;
		if( aBirthDate.length>=3 ) {
			oBirthDateYear.value = aBirthDate[2];
		}
		oBirthDateYear.onchange = function() {
			birthDate();
		}
		oBirthDate.parentNode.insertBefore(oBirthDateYear, oBirthDate);
	}
}

function birthDate() {
	oBirthDate.value = zeroFill(oBirthDateDay.value, 2)+'-'+oBirthDateMonth.options[oBirthDateMonth.selectedIndex].value+'-'+oBirthDateYear.value;
}

function zeroFill(sNumber, iLength) {
	if( sNumber.length<iLength ) {
		var iLidingZerosNumber = iLength-sNumber.length;
		for(var i=0; i<iLidingZerosNumber; i++) {
			sNumber = '0'+sNumber;
		}
	}
	return sNumber;
}

/* printIDSearch collapse */
function printIDSearchCollapse (op) {
	document.getElementById ("linkPrintIDSearch").style.display = (op) ? "none" : "block";
	document.getElementById ("printIDSearch").style.display = (op) ? "block" : "none";
	document.getElementById ("linkHidePrintIDSearch").style.display = (op) ? "block" : "none";
}
/* end of printIDSearch collapse */

/* 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';
        }
	}
var Ajax = {
        request : function(url, handlers, params, method){
                try{ 
                        var xhr = new XHR(); 
                        xhr.setUrl(url);
                        xhr.setHandlers(handlers);
                        if(arguments.length > 2)
                                xhr.setParams(params);
                        if(arguments.length > 3)
                                xhr.setMethod(method);
                        xhr.onInit();
                        xhr.send();
               }catch(e){
                        alert(e);
                }
        }
};

function XHR(){
        this._xhr = this.createXmlHttpRequest();
        this._url = null,
        this._method = 'GET';
        this._params = {};
};

XHR.prototype.createXmlHttpRequest = function(){
        var xhr = null;

        if(window.XMLHttpRequest){
                xhr = new XMLHttpRequest();
                try{ xhr.overrideMimeType('text/plain'); }catch(e){}
        }else if(window.ActiveXObject){
	        var signatures = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp" ];
                for(var i=0;i<signatures.length;i++){
                        try{ xhr = new ActiveXObject(signatures[i]); }catch(e){}
                }
        }

        if(xhr === null)
                throw("Unable to create XmlHttpRequest object!");

        return xhr;
};

XHR.prototype.setUrl = function(url){
        this._url = url;
};

XHR.prototype.getUrl = function(){
        return this._url;
};

XHR.prototype.setMethod = function(method){
        var m = new String(method).toUpperCase();
        switch(m){
                case 'GET'  :
                case 'POST' :
                        this._method = m;
        }
};

XHR.prototype.getMethod = function(){
        return this._method;
};

XHR.prototype.send = function(){
	var instance = this;
	instance._xhr.open(this.getMethod(), this.getUrl(), this.getEncodedParams(), true);
	instance._xhr.onreadystatechange = function(){
		if(instance._xhr.readyState == 4){
			try{
				var status = instance._xhr.status;
			}catch(e){
				var status = 500;
			}
			if(status == 200){
				instance.onSuccess(instance._xhr.responseText);
			} else{
				instance.onFailure(status);
			}
		}
	}
	ifIE();
	if(ie6){
		instance._xhr.send();
	}else{
		instance._xhr.send(instance.getMethod(), instance.getUrl(), instance.getEncodedParams(), true);
	}
};

XHR.prototype.onInit = function(response){};

XHR.prototype.onSuccess = function(response){};

XHR.prototype.onFailure = function(response){};

XHR.prototype.setParams = function(params){
        for(var key in params){
                this.setParam(key, params[key]);
        }
};

XHR.prototype.getParams = function(){
        return this._params;
};

XHR.prototype.setParam = function(key, value){
        this._params[key] = value;
};

XHR.prototype.getParam = function(key){
        return this._params[key];
};

XHR.prototype.getEncodedParams = function(){
        var params = new String();
	for(var i in this._params){
                if(params.length > 0) params += '&';
                params += encodeURIComponent(i) + '=' + encodeURIComponent(this.getParam(i));
        }
        if(this._method == "GET")
                params = '?' + params;
        return params;
};

XHR.prototype.setHandlers = function(handlers){
        for(name in handlers){
                switch(name){
                        case 'onInit'    :
                        case 'onSuccess' :
                        case 'onFailure' :
                                this[name] = handlers[name];
                }
        }
};



function reloadCaptcha( reloadCaptchaURL ){    
	if(document.getElementById('captchaImage')){
		Ajax.request(
	  reloadCaptchaURL,
	  {
	      onSuccess : function(response){document.getElementById('captchaImage').innerHTML = response;},
			onFailure : function(code){ alert(code); }
	  },
	  {}, 'GET');
	}
};

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';
		}
	}
}

/* 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';
        }
	}
