// JavaScript Document
function test(val) {
	document.getElementById('test').innerHTML = val;
}
function loadcities(val,page,subarr) {
	document.getElementById('city').innerHTML = '<select id="cty" name="'+page+subarr+'[city]"><option value="0">Град</option></select>';
	var val, cities_all, cities_arr, cOut = '';
	cities_all = val.split('|');
	cities_arr = cities_all[1].split(';');
	for (a=0;a<cities_arr.length-1;a++) {
		cVals = cities_arr[a].split('=');
		var elOptNew = document.createElement('option');
		elOptNew.text = cVals[1];
		elOptNew.value = cVals[0];
		  var elSel = document.getElementById('cty');
		
		  try {
			elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		  }
		  catch(ex) {
			elSel.add(elOptNew); // IE only
		  }
		  //cOut += '<option value="'+cVals[0]+'">'+cVals[1]+'</option>';
	}
	//test('<select>'+cities+'</select>');
	//document.getElementById('cty').innerHTML = cOut;
}
function loadHomecities(val,page,subarr) {
	document.getElementById('city').innerHTML = '<select id="qCity" name="query[city]" multiple="multiple" size="5" style="width:310px; height:52px;" onchange="addsel(this.id,\'selCity\');"></select>'; //'<select id="cty" name="'+page+subarr+'[city]"><option value="0">Град</option></select>';
	var val, cities_all, cities_arr, cOut = '';
	cities_all = val.split('|');
	cities_arr = cities_all[1].split(';');
	for (a=0;a<cities_arr.length-1;a++) {
		cVals = cities_arr[a].split('=');
		var elOptNew = document.createElement('option');
		elOptNew.text = cVals[1];
		elOptNew.value = cVals[0];
		  var elSel = document.getElementById('qCity');
		
		  try {
			elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		  }
		  catch(ex) {
			elSel.add(elOptNew); // IE only
		  }
		  //cOut += '<option value="'+cVals[0]+'">'+cVals[1]+'</option>';
	}
	//test('<select>'+cities+'</select>');
	//document.getElementById('cty').innerHTML = cOut;
}
function addChosen(val,text,id) {
	if (id == 'chose') {
		var elOptNew = document.createElement('option');
		elOptNew.text = text;
		elOptNew.value = val;
		var elSel = document.getElementById('chosen');
	  
		try {
		  elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		  elSel.add(elOptNew); // IE only
		}
		document.getElementById('chose').options[document.getElementById('chose').selectedIndex].style.color = '#f00';
		document.getElementById('chose').options[document.getElementById('chose').selectedIndex].style.backgroundColor = '#fff';
		document.getElementById('chose').options[document.getElementById('chose').selectedIndex].selected = ' false';
	}
	if (id == 'chosen') {
		document.getElementById('chosen').remove(document.getElementById('chosen').selectedIndex);
	}
}
function addsel(id,tid) {
	var id,tid,vals = '';
	selRef = document.getElementById(id);
	for (var i=selRef.options.length-1; i>=0; i--) {
		if (selRef.options[i].selected) {
			//alert(selRef.options[i].value);
			// do something
			regexp = '/\|'+selRef.options[i].value+'/';
			/*if (vals.match(regexp)) { vals = vals.replace(regexp,''); }
			else { */ 
			vals += '|'+selRef.options[i].value; //}
			//test(vals);
		}
	}
	document.getElementById(tid).value = vals;
	//test(document.getElementById(tid).value);
	/*regexp = '/\|'+val+'/';
	test(regexp);
	vals = document.getElementById('selJobs').value;
	if (vals.match(regexp)) { vals = vals.replace(regexp,''); }
	else { vals += '|'.val; }
	document.getElementById('selJobs').value = vals;*/
}
function showBox() {
	if (navigator.userAgent.indexOf('MSIE 6') > -1) { showBoxIE6(); return; }
	var width = document.documentElement.clientWidth + document.documentElement.scrollLeft; 
	
	var layer = document.createElement('div');
	layer.style.zIndex = 2;
	layer.id = 'layer';
	layer.style.position = 'absolute';
	layer.style.top = '0px';
	layer.style.left = '0px';
	layer.style.height = document.documentElement.scrollHeight + 'px';
	layer.style.width = width + 'px';
	layer.style.backgroundColor = 'black';
	layer.style.opacity = '.6';
	layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
	document.body.appendChild(layer);  
	
	var div = document.createElement('div');
	div.id = 'box';
	div.style.zIndex = 3;
	div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
	div.style.top = '200px';
	div.style.left = (width / 2) - (400 / 2) + 'px'; 
	div.style.height = '100px';
	div.style.width = '400px';
	div.style.backgroundColor = 'white';
	div.style.border = '2px solid silver';
	div.style.padding = '20px';
	document.body.appendChild(div);  
	
	var divH = document.createElement('div');
	divH.id = 'popupHeader';
	divH.style.position = 'relative';
	divH.style.top = '-22px';
	divH.style.left = '-25px';
	divH.style.textIndent = '20px';
	divH.style.fontSize = '24px';
	divH.style.color = '#fff';
	divH.style.width = '450px';
	divH.style.height = '37px';
	divH.style.background = '#1f74b7 url(../../images/search/searchHead_motiv.jpg) repeat-x';
	divH.style.lineHeight = '33px';
	divH.innerHTML = 'Регистрация';
	div.appendChild(divH);
	
	var divC = document.createElement('div');
	divC.style.lineHeight = '50px';
	divC.style.textAlign = 'center';
	divC.innerHTML = '<a href="?main=register&type=employer" title="Регистрация на работодател" style="font-size:20px;">Работодател</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?main=register&type=employee" title="Регистрация на кандидат" style="font-size:20px;">Кандидат</a>';
	
	div.appendChild(divC);
	
	var aClose = document.createElement('a');
	aClose.style.position = 'relative';
	aClose.style.top = '-108px';
	aClose.style.left = '390px';
	aClose.innerHTML = '<img src="../../images/close.gif" alt="Close Window" title="Close" />';
	aClose.href = 'javascript:void(0)';
	aClose.onclick = function() {
		document.body.removeChild(document.getElementById('layer'));
		document.body.removeChild(document.getElementById('box'));
	};
	div.appendChild(aClose);
}
function showBoxIE6() {
	var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	
	var layer = document.createElement('div');
	layer.style.zIndex = 2;
	layer.id = 'layer';
	layer.style.position = 'absolute';
	layer.style.top = '0px';
	layer.style.left = '0px';
	layer.style.height = document.documentElement.scrollHeight + 'px';
	layer.style.width = width + 'px';
	layer.style.backgroundColor = 'black';
	layer.style.opacity = '.6';
	layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
	document.body.appendChild(layer);  
	
	var div = document.createElement('div');
	div.style.zIndex = 3;
	div.id = 'box';
	div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
	div.style.top = '100px';
	div.style.left = (width / 2) - (400 / 2) + 'px'; 
	div.style.height = '100px';
	div.style.width = '400px';
	div.style.backgroundColor = 'white';
	div.style.border = '2px solid silver';
	div.style.padding = '20px';
	div.style.overflow = 'hidden';
	document.body.appendChild(div);  
	
	var divH = document.createElement('div');
	divH.id = 'popupHeader';
	divH.style.position = 'relative';
	divH.style.top = '-22px';
	divH.style.left = '-25px';
	divH.style.textIndent = '20px';
	divH.style.fontSize = '24px';
	divH.style.color = '#fff';
	divH.style.width = '450px';
	divH.style.height = '37px';
	divH.style.background = '#1f74b7 url(../../images/search/searchHead_motiv.jpg) repeat-x';
	divH.style.lineHeight = '33px';
	divH.innerHTML = 'Регистрация';
	div.appendChild(divH);
	
	var divC = document.createElement('div');
	divC.style.lineHeight = '50px';
	divC.style.textAlign = 'center';
	divC.innerHTML = '<a href="?main=register&type=employer" title="Регистрация на работодател" style="font-size:20px;">Работодател</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?main=register&type=employee" title="Регистрация на кандидат" style="font-size:20px;">Кандидат</a>';
	
	div.appendChild(divC);
	
	var aClose = document.createElement('a');
	aClose.style.position = 'relative';
	aClose.style.top = '-105px';
	aClose.style.left = '388px';
	aClose.innerHTML = '<img src="../../images/close.gif" alt="Close Window" title="Close" />';
	aClose.href = 'javascript:void(0)';
	aClose.onclick = function() {
		document.body.removeChild(document.getElementById('layer'));
		document.body.removeChild(document.getElementById('box'));
	};
	div.appendChild(aClose);
}
function test(val) {
	document.getElementById('test').innerHTML = val;
}