// ----------------------------------------------------------------------------------------------------
//	© 2006-2011 [hex494D49@hotmail.com]
//
//	file path:			includes/std.js 
//	file descriptoin: 
//	
// ----------------------------------------------------------------------------------------------------

var ajax = new xhr();

sfHover = function() {
	if(document.getElementById("nav")){
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function on_enter(evt,frm){var keyCode=null;if(evt.which){keyCode=evt.which;}else if(evt.keyCode){keyCode=evt.keyCode;}if(keyCode==13){authorize_user();return false;}return true;};

// ------------------------------
// authorize user
// ------------------------------
function authorize_user(){
	var username = document.getElementById('authorization').username.value;
	var password = document.getElementById('authorization').password.value;
	ajax.setVar('username', username);
	ajax.setVar('password', password);
	ajax.requestFile = 'includes/admin.php?function=001';
	ajax.onCompletion = function(){ show_navigator(); };
	ajax.runAJAX();
}

// ------------------------------
// unauthorize user
// ------------------------------
function unauthorize_user(){
	ajax.requestFile = 'includes/admin.php?function=002';
	ajax.onCompletion = function(){ window.location.href = '/' };
	ajax.runAJAX();
}

// ------------------------------
// update navigator content
// ------------------------------
function show_navigator(){
	//alert(ajax.response);
	var arr = ajax.response.split('|');
	if(parseInt(arr[0])){
		document.getElementById('navigator').innerHTML = arr[1];
		window.location.href = '/';
		return true;
	}else{
		buffer = document.getElementById('navigator').innerHTML;
		document.getElementById('navigator').innerHTML = arr[1];
		setTimeout("document.getElementById('navigator').innerHTML = buffer", 3000);
	}
}

var days_in_month=[31,28,31,30,31,30,31,31,30,31,30,31];var one_day=1000*60*60*24;var date_format='d-m-y';
function ooCalendar(box,beginning_date,ending_date){if(document.getElementById('calendar'))return false;var obj=this;var pattern_dmy=new RegExp('\\d{1,2}-\\d{1,2}-\\d{4}');var pattern_ymd=new RegExp('\\d{4}-\\d{1,2}-\\d{1,2}');this.i_int=null;this.d_int=null;this.box=box;if(beginning_date!=null||ending_date!=null){if(beginning_date!=null){this.beginning_date=beginning_date.replace(/-/g,'');}else{this.beginning_date=new Date();this.beginning_date=this.beginning_date.format('ymd');}if(ending_date!=null){this.ending_date=ending_date.replace(/-/g,'');}else{this.ending_date=new Date(this.beginning_date.substr(0,4),(this.beginning_date.substr(4,2)-1),this.beginning_date.substr(6,2));this.ending_date.setTime(Math.ceil(this.ending_date.getTime()+(one_day*180)));this.ending_date=this.ending_date.format('ymd');}}else{this.beginning_date=0;this.ending_date=99999999;}if((this.box.value!='')&&pattern_dmy.test(this.box.value)){var box_date=this.box.value.split('-');this.current_date=new Date(box_date[2],(box_date[1]-1),box_date[0]);}else if((this.box.value!='')&&pattern_ymd.test(this.box.value)){var box_date=this.box.value.split('-');this.current_date=new Date(box_date[0],(box_date[1]-1),box_date[2]);}else{this.current_date=new Date();}this.current_year=this.current_date.getFullYear();this.current_month=this.current_date.getMonth();this.current_day=this.current_date.getDate();this.initialize_calendar=function(){this.the_first_of_current_month=new Date(this.current_year,this.current_month,1);this.first_day_index=((this.the_first_of_current_month.getDay()-1)== -1)?6:(this.the_first_of_current_month.getDay()-1);this.length_of_current_month=(days_in_month[this.current_month]==28)?((this.current_year%400==0||(this.current_year%4==0&&this.current_year%100!=0))?29:28):days_in_month[this.current_month];this.needed_rows=Math.ceil((this.length_of_current_month+this.first_day_index)/7);};this.rebuild_calendar_body=function(o,month,year,e){if(!e)var e=window.event;e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();if(month){this.current_month=parseInt(o.id.substr(o.id.indexOf('_')+1));this.month_chooser.innerHTML=the_months[this.current_month];this.month_chooser.id='c'+o.id;this.months.parentNode.removeChild(this.months);}if(year){this.current_year=parseInt(o.id.substr(o.id.indexOf('_')+1));this.year_chooser.innerHTML=this.current_year;this.year_chooser.id='c'+o.id;this.years.parentNode.removeChild(this.years);}this.cal_body.parentNode.removeChild(this.cal_body);this.initialize_calendar();this.build_calendar_body();};this.toggle_months=function(){if(!this.month_wraper.getElementsByTagName('UL')[0]){this.months=document.createElement('UL');this.months.id='months';for(var i=0;i<12;i++){var month=document.createElement('LI');month.id='m_'+i;month.innerHTML=the_months[i];(i==this.current_month)?month.style.color='#ff0000':"";month.onclick=this.rebuild_calendar_body.bind(this,month,true,false);this.months.appendChild(month);}this.month_wraper.appendChild(this.months);}else{this.month_wraper.removeChild(this.month_wraper.getElementsByTagName('UL')[0]);}if(this.year_wraper.getElementsByTagName('UL')[0]){this.year_wraper.removeChild(this.year_wraper.getElementsByTagName('UL')[0]);}};this.toggle_years=function(){if(!this.year_wraper.getElementsByTagName('UL')[0]){this.years=document.createElement('UL');this.years.id='years';this.minus=document.createElement('LI');this.minus.innerHTML='&nbsp;-&nbsp;';this.minus.onmouseover=this.decrease_years.bind(this);this.minus.onmouseout=function(){clearInterval(obj.d_int);};this.years.appendChild(this.minus);for(var i=(parseInt(this.current_year)-5);i<(parseInt(this.current_year)+5);i++){var year=document.createElement('LI');year.id='y_'+i;year.innerHTML=i;(i==this.current_year)?year.style.color='#ff0000':"";year.onclick=this.rebuild_calendar_body.bind(this,year,false,true);this.years.appendChild(year);}this.plus=document.createElement('LI');this.plus.innerHTML='&nbsp;+&nbsp;';this.plus.onmouseover=this.increase_years.bind(this);this.plus.onmouseout=function(){clearInterval(obj.i_int);};this.years.appendChild(this.plus);this.year_wraper.appendChild(this.years);}else{this.year_wraper.removeChild(this.year_wraper.getElementsByTagName('UL')[0]);}if(this.month_wraper.getElementsByTagName('UL')[0]){this.month_wraper.removeChild(this.month_wraper.getElementsByTagName('UL')[0]);}};this.increase_years=function(){var lis=this.years.getElementsByTagName('LI');for(var i=1;i<lis.length-1;i++){lis[i].innerHTML=parseInt(lis[i].innerHTML)+1;lis[i].id='y_'+lis[i].innerHTML;(parseInt(lis[i].innerHTML)==this.current_year)?lis[i].style.color='#ff0000':lis[i].style.color='#000000';}this.i_int=setTimeout(function(){obj.increase_years()},200);};this.decrease_years=function(){var lis=this.years.getElementsByTagName('LI');for(var i=1;i<lis.length-1;i++){lis[i].innerHTML=parseInt(lis[i].innerHTML)-1;lis[i].id='y_'+lis[i].innerHTML;(parseInt(lis[i].innerHTML)==this.current_year)?lis[i].style.color='#ff0000':lis[i].style.color='#000000';}this.d_int=setTimeout(function(){obj.decrease_years()},200);};this.doc_body=document.body;this.cal_tbl=document.createElement('TABLE');this.cal_tbl.style.position='absolute';this.cal_tbl.style.backgroundColor='#ffffff';this.cal_tbl.id='calendar';this.cal_head=document.createElement('THEAD');this.cal_head_row=document.createElement('TR');this.cal_head_cell=document.createElement('TD');this.cal_head_cell.setAttribute('colSpan','7');this.month_wraper=document.createElement('DIV');this.month_wraper.id='month_wraper';this.month_chooser=document.createElement('DIV');this.month_chooser.className='month_chooser';this.month_chooser.id='cm_'+this.current_month;this.month_chooser.innerHTML=the_months[this.current_month];this.month_chooser.onclick=this.toggle_months.bind(this);this.month_wraper.appendChild(this.month_chooser);this.cal_head_cell.appendChild(this.month_wraper);this.year_wraper=document.createElement('DIV');this.year_wraper.id='year_wraper';this.year_chooser=document.createElement('DIV');this.year_chooser.className='year_chooser';this.year_chooser.id='cy_'+this.current_year;this.year_chooser.innerHTML=this.current_year;this.year_chooser.onclick=this.toggle_years.bind(this);this.year_wraper.appendChild(this.year_chooser);this.cal_head_cell.appendChild(this.year_wraper);this.cal_head_row.appendChild(this.cal_head_cell);this.cal_head.appendChild(this.cal_head_row);this.week_days=document.createElement('TR');for(var i=0;i<7;i++){this.week_day=document.createElement('TD');this.week_day.innerHTML=the_days[i];this.week_days.appendChild(this.week_day);}this.cal_head.appendChild(this.week_days);this.cal_tbl.appendChild(this.cal_head);this.cal_tbl.className='calendar';this.cal_tbl.setAttribute('border','1');this.cal_tbl.style.left=get_left_pos(this.box)+'px';this.cal_tbl.style.top=get_top_pos(this.box)+'px';this.doc_body.appendChild(this.cal_tbl);this.build_calendar_body=function(){this.cal_body=document.createElement('TBODY');var counter=1;for(var i=0;i<this.needed_rows;i++){this.week_row=document.createElement('TR');for(var j=0;j<7;j++){this.week_day=document.createElement('TD');if(!i&&(j<this.first_day_index)||(counter>this.length_of_current_month)){this.week_day.innerHTML='';}else{(counter==this.current_day)?this.week_day.style.fontWeight='bold':"";this.week_day.innerHTML=counter++;var this_date=this.current_year+(((this.current_month+1)<10)?'0'+(this.current_month+1):(this.current_month+1).toString())+((this.week_day.innerHTML<10)?'0'+this.week_day.innerHTML:this.week_day.innerHTML).toString();if((this_date<this.beginning_date)||(this_date>this.ending_date)){this.week_day.style.color='#cccccc';}else{this.week_day.style.cursor='pointer';this.week_day.onclick=this.deinitialize_calendar.bind(this,(counter-1),true);}}this.week_row.appendChild(this.week_day);}this.cal_body.appendChild(this.week_row);}this.cal_tbl.appendChild(this.cal_body);};this.deinitialize_calendar=function(day,flag){if(flag){this.box.focus();if(date_format=='d-m-y'){this.box.value=((day<10)?'0'+day:day).toString()+'-'+(((this.current_month+1)<10)?'0'+(this.current_month+1):(this.current_month+1).toString())+'-'+this.current_year;}else if(date_format=='y-m-d'){this.box.value=this.current_year+'-'+(((this.current_month+1)<10)?'0'+(this.current_month+1):(this.current_month+1).toString())+'-'+((day<10)?'0'+day:day).toString();}this.box.blur();}this.destroy();};this.destroy=function(){this.cal_tbl.parentNode.removeChild(this.cal_tbl);document.onclick=null;obj=null;};this.catch_click=function(e){var targ;if(!e)var e=window.event;if(e.target)targ=e.target;else if(e.srcElement)targ=e.srcElement;if(targ.nodeType==3)targ=targ.parentNode;var parent=targ;while(parent){parent=parent.parentNode;if(parent==this.cal_tbl){return;}}if(this.flag){this.destroy();}this.flag=true;};this.initialize_calendar();this.build_calendar_body();document.onclick=this.catch_click.bind(this);return true;};

function getOffset(el) {
    var _x = 0;
    var _y = 0;
    while(el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)){
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.offsetParent;
    }
    return {top:_y, left:_x};
}

function get_top_pos(el){
	/*
	var value=elm.offsetTop+elm.offsetHeight;
	while((elm=elm.offsetParent)!=null)
		value+=elm.offsetTop;
	return value+0;
	*/
    var _x = 0;
    var _y = 0;
    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.offsetParent;
    }
    return _y;
};

function get_left_pos(el){
	/*
	var value=elm.offsetLeft;
	while((elm=elm.offsetParent)!=null)
		value+=elm.offsetLeft;
	return value+0;
	*/
    var _x = 0;
    var _y = 0;
    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.offsetParent;
    }
    return _x;
};

Array.prototype.in_array=function(obj){var len=this.length;for(var i=0;i<=len;i++){if(this[i]==obj)return true;}return false;};
Array.prototype.index_array=function(obj){var len=this.length;for(var i=0;i<=len;i++){if(this[i]==obj)return i;}};
function to_array(pseudo_array){var result=[];for(var i=0;i<pseudo_array.length;i++)result.push(pseudo_array[i]);return result;};
Function.prototype.bind=function(object){var method=this;var old_arguments=to_array(arguments).slice(1);return function(){var new_arguments=to_array(arguments);return method.apply(object,old_arguments.concat(new_arguments));};};
Function.prototype.bind_event_listener=function(object){var method=this;var old_arguments=to_array(arguments).slice(1);return function(event){return method.apply(object,event||window.event,old_arguments);};};Date.prototype.format=function(mask){var date=mask.replace(/y/,this.getFullYear()).replace(/m/,((this.getMonth()+1)<10)?'0'+(this.getMonth()+1):(this.getMonth()+1)).replace(/d/,(this.getDate()<10)?'0'+this.getDate():this.getDate()).replace(/h/,(this.getHours()<10)?'0'+this.getHours():this.getHours()).replace(/i/,(this.getMinutes()<10)?'0'+this.getMinutes():this.getMinutes()).replace(/s/,(this.getSeconds()<10)?'0'+this.getSeconds():this.getSeconds());return date;};

var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

// --------------------------------------------------
//
function get_locations_from_server(location,lang,field){
	if(field!=0){
		document.getElementById(field).value=location;
		ajax.requestFile='includes/admin.php?function=009&id='+location+'&lang='+lang+'&field='+field;
		ajax.onLoading=function(){document.getElementById(field.replace(/a/,'ac')).innerHTML='<img src=\'images/indicator.gif\' border=\'0\' alt=\'0\' />';};
	}else{
		(location<=2)?document.getElementById('property_searcher').location.value='':document.getElementById('property_searcher').location.value=location;
		ajax.requestFile='includes/admin.php?function=009&id='+location+'&lang='+lang+'&field='+field;
		ajax.onLoading=function(){document.getElementById('location_wraper').innerHTML='<img src=\'images/indicator.gif\' border=\'0\' alt=\'0\' />';};
	}
	ajax.onCompletion=function(){set_locations_on_client(field)};
	ajax.runAJAX();
}

// --------------------------------------------------
//
function set_locations_on_client(field){
	if(field!=0){
		target=document.getElementById(field.replace(/a/,'ac'));
		target.innerHTML=ajax.response;
	}else{
		toolTip();
		document.getElementById('location_wraper').innerHTML=ajax.response;
	}
}

// --------------------------------------------------
//
function get_categories_from_server(category,lang,field){
	document.getElementById(field).value=category;
	ajax.requestFile='includes/admin.php?function=010&id='+category+'&lang='+lang+'&field='+field;
	ajax.onLoading=function(){document.getElementById(field.replace(/a/,'ac')).innerHTML='<img src=\'images/indicator.gif\' border=\'0\' alt=\'0\' />';};
	ajax.onCompletion=function(){set_categories_on_client(field)};
	ajax.runAJAX();
}

// --------------------------------------------------
//
function set_categories_on_client(field){
	target=document.getElementById(field.replace(/a/,'ac'));
	target.innerHTML=ajax.response;
}

/*
// ------------------------------
// get (sub)locations from server
// ------------------------------
function get_locations_from_server(location, lang, field){
	if(field != 0){		
		document.getElementById(field).value = location;
	}
	ajax.requestFile = 'includes/admin.php?function=009&id=' + location + '&lang=' + lang + '&field=' + field;
	ajax.onCompletion = function(){ set_locations_on_client(field) };
	ajax.runAJAX();
}

// ------------------------------
// set (sub)locations on client
// ------------------------------
function set_locations_on_client(field){
	if(field != 0){
		target = document.getElementById(field.replace(/a/, 'ac'));
		target.innerHTML = ajax.response;
	}else{
		var arg = ajax.response.split('||');
		document.getElementById('path').innerHTML = arg[0];
		document.getElementById('sublocations').innerHTML = arg[1];
		document.getElementById('map').innerHTML = arg[2];
	}
}
*/

// ------------------------------
// toggle (sub)location on client
// ------------------------------
function toggle_sublocation(obj){
	alert('now i should check or uncheck selected location: ' + obj);
}

// ------------------------------
// show password indicator
// ------------------------------
function password_changed(){
	var strong_pwd = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
	var medium_pwd = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
	var weak_pwd = new RegExp("(?=.{6,}).*", "g");
	var frm = document.getElementById('entryform');
	var pwd = frm.password.value;
	if(false == weak_pwd.test(pwd)){
		var weak_obj = document.getElementById('weak');
		var medium_obj = document.getElementById('medium');
		var strong_obj = document.getElementById('strong');
		weak_obj.className = medium_obj.className = strong_obj.className = "default"; 
	}else if(strong_pwd.test(pwd)){
		var weak_obj = document.getElementById('weak');
		weak_obj.className = "strong"; 
		var medium_obj = document.getElementById('medium');
		medium_obj.className = "strong"; 
		var strong_obj = document.getElementById('strong');
		strong_obj.className = "strong"; 
	}else if(medium_pwd.test(pwd)){
		var weak_obj = document.getElementById('weak');
		weak_obj.className = "medium"; 
		var medium_obj = document.getElementById('medium');
		medium_obj.className = "medium"; 
		var strong_obj = document.getElementById('strong');
		strong_obj.className = "default"; 
	}else{
		var weak_obj = document.getElementById('weak');
		weak_obj.className = "weak";
		var medium_obj = document.getElementById('medium');
		medium_obj.className = "default"; 
		var strong_obj = document.getElementById('strong');
		strong_obj.className = "default"; 
	}
}

// -----------------------------------
// it will return content of some html element
function get_container_content(){
	var container = prompt('enter the \'id\' of container i should explore', 'node_content');
	if(!container)return;
	var d_body = document.body;
	var target = document.getElementById(container);
	if(target != null){
		var e_wraper = document.createElement('DIV');
		e_wraper.id = 'explorer';
		e_wraper.className = 'explorer';
		var e_killer = document.createElement('SPAN');
		e_killer.innerHTML = 'close';
		e_killer.onclick = function () { d_body.removeChild(e_wraper); };
		var e_break = document.createElement('BR');
		var e_container = document.createElement('TEXTAREA');
		e_container.setAttribute('cols', '100');
		e_container.setAttribute('rows', '20');
		e_container.value = target.innerHTML;
		e_wraper.appendChild(e_killer);
		e_wraper.appendChild(e_break);
		e_wraper.appendChild(e_container)
		d_body.appendChild(e_wraper);
		var theExplorer = document.getElementById('explorer');
		Drag.init(theExplorer);			
	}else{
		alert('there\'s no such an element');
	}
}

// -----------------------------------
// toggle display and visibility value of an element
function toggle_obj(id){
	var target = document.getElementById(id);
	if(target.style.display == 'none'){
		target.style.display = 'block';
		target.style.visibility = 'visible';
	}else{
		target.style.display = 'none';
		target.style.visibility = 'hidden';
	}
}

function toggle_branch(obj){
	var cb = document.getElementsByClassName("company_location");
	for(var i=0; i<cb.length; i++){
		var parent = cb[i].parentNode;
		if(i == obj.selectedIndex){
			parent.style.display = 'block';
			parent.style.visibility = 'visible';
		}else{
			parent.style.display = 'none';
			parent.style.visibility = 'hidden';
		}
		document.getElementById('enquiry').dump.value = obj.value;
	}
}

function switch_tab(tab,flag,type){
	if(flag!=null){
		var header=tab.parentNode.getElementsByTagName('LI');
		for(var i=0;i<header.length;i++){
			if(header[i].className==('tab_h_active_'+type)){
				header[i].className=('tab_h_inactive_'+type);
			}
			if(header[i]==tab){
				header[i].className=('tab_h_active_'+type);
				var handler=i;
			}
		}
		var index=0;
		var content=tab.parentNode.parentNode.childNodes;
		for(var i=0;i<content.length;i++){
			if(content[i].nodeName=='DIV'){
				if(content[i].className==('tab_c_active_'+type)){
					content[i].className=('tab_c_inactive_'+type)
				}
				if(index==handler){
					content[i].className=('tab_c_active_'+type)
				}
				index++
			}
		}
	}else{
		var tabs=document.getElementById(tab).parentNode.getElementsByTagName('LI');
		for(var i=0;i<tabs.length;i++){
			if(tabs[i].className=='tab_h_active_a'){
				tabs[i].className='tab_h_inactive_a';
				document.getElementById(tabs[i].id.replace(/h/,'c')).className='tab_c_inactive_a';
			}
			if(tabs[i].id==tab){tabs[i].className='tab_h_active_a';
				document.getElementById(tabs[i].id.replace(/h/,'c')).className='tab_c_active_a';
			}
		}
	}
};

function newsletter(frm,mode){
	var dump=mode + '|';
	for(var i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type=='text'||frm.elements[i].type=='textarea'||frm.elements[i].type=='hidden'){
			if(!frm.elements[i].value.length){
				alert('Niste upisali email adresu');
				return false;
			}
			switch(frm.elements[i].name){
				case 'email':
					var pattern=new RegExp("^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$");
					if(!pattern.test(frm.elements[i].value)){
						alert('Format e-mail adrese nije ispravan');
						return false;
					}
					dump+=frm.elements[i].value+'|';
					break;
			}
		}
	}
	frm.reset();
	ajax.setVar('dump',dump.substr(0,dump.length-1));
	ajax.requestFile='includes/admin.php?function=1005';
	ajax.onLoading=function(){};
	ajax.onCompletion=function(){alert(ajax.response);};
	ajax.runAJAX();
	return true;
};

function send_enquiry(frm,id){
	var dump='';
	var ids=id.split('_');
	dump+=ids[0]+'|'+ids[1]+'|'+ids[2]+'|'+ids[3]+'|';
	for(var i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type=='text'||frm.elements[i].type=='textarea'||frm.elements[i].type=='hidden'){
			if(!frm.elements[i].value.length){
				alert('Nisu ispunjena sva potrebna polja');
				return false;
			}
			switch(frm.elements[i].name){
				case 'name':
					var pattern=new RegExp("^([ \\u00c0-\\u01ffa-zA-Z'])+$");
					if(!pattern.test(frm.elements[i].value)){
						alert('U imenu ima nedozvoljenih znakova');
						return false;
					}
					dump+=frm.elements[i].value+'|';
					break;
				case 'email':
					var pattern=new RegExp("^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$");
					if(!pattern.test(frm.elements[i].value)){
						alert('Format e-mail adrese nije ispravan');
						return false;
					}
					dump+=frm.elements[i].value+'|';
					break;
				case 'phone':
					dump+=frm.elements[i].value+'|';
					break;
				case 'message':
					var pattern=new RegExp("[|]");
					if(pattern.test(frm.elements[i].value)==true){
						alert('U poruci ima nedozvoljenih znakova');
						return false;
					}
					dump+=frm.elements[i].value+'|';
					break;
			}
		}
	}
	frm.reset();
	//p.kill();
	//alert(dump);
	ajax.setVar('dump',dump.substr(0,dump.length-1));
	ajax.requestFile='includes/admin.php?function=1000&mode=send&lang=hr';
	ajax.onLoading=function(){};
	ajax.onCompletion=function(){alert(ajax.response);};
	ajax.runAJAX();
	return true;
};

function show_enquiry(dump){
	ajax.requestFile='includes/admin.php?function=1000&mode=init&dump=' + dump + '&lang=hr';
	ajax.onLoading=function(){};
	ajax.onCompletion=function(){ p = new popup("div", 550, 300, "KONTAKT OBRAZAC", ajax.response, ""); };
	ajax.runAJAX();
};

function send_feedback(frm){
	var dump='';
	for(var i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type=='text'||frm.elements[i].type=='textarea'||frm.elements[i].type=='hidden'){
			if(!frm.elements[i].value.length){
				alert('Nisu ispunjena sva potrebna polja');
				return false;
			}
			switch(frm.elements[i].name){
				case 'email':
					var pattern=new RegExp("^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$");
					if(!pattern.test(frm.elements[i].value)){
						alert('Format e-mail adrese nije ispravan');
						return false;
					}
					dump+=frm.elements[i].value+'|';
					break;
				case 'phone':
					dump+=frm.elements[i].value+'|';
					break;
				case 'message':
					var pattern=new RegExp("[|]");
					if(pattern.test(frm.elements[i].value)==true){
						alert('U poruci ima nedozvoljenih znakova');
						return false;
					}
					dump+=frm.elements[i].value+'|';
					break;
			}
		}
	}
	frm.reset();
	p.kill();
	//alert(dump);
	ajax.setVar('dump',dump.substr(0,dump.length-1));
	ajax.requestFile='includes/admin.php?function=2010&mode=send&lang=hr';
	ajax.onLoading=function(){};
	ajax.onCompletion=function(){alert(ajax.response);};
	ajax.runAJAX();
	return true;
};

function show_feedback(){
	ajax.requestFile='includes/admin.php?function=2010&mode=init&lang=hr';
	ajax.onLoading=function(){};
	ajax.onCompletion=function(){ p = new popup("div", 550, 300, FEEDBACK_TITLE, ajax.response, ""); };
	ajax.runAJAX();
}

var g = new gallery();
function gallery(){

	var obj = this;
	var img = null;
	this.container = document.getElementById("gallery-container");
	this.wrapper = null;
	this.client = new Array();
	this.distance = new Array();

	this.init = function(o){
		this.wrapper = document.createElement("DIV");
		this.wrapper.id = "blob_wrapper";
		this.wrapper.style.position = "absolute";
		this.wrapper.style.zIndex = 99999;
		var ul = document.createElement("UL");
		ul.id = "blob_header";
		this.header = ul;
		
		var imgs = o.parentNode.parentNode.getElementsByTagName("IMG");
		//var imgs = this.container.getElementsByTagName("IMG");
		for(i=0; i<imgs.length; i++){
			var li = document.createElement("LI");
			li.innerHTML = (i+1);
			li.id = imgs[i].src.replace(/thumbnails\//, "");
			li.onclick = function(){ obj.swap(this); };
			ul.appendChild(li);
		}
		
		var li = document.createElement("LI");
		li.className = "blob_killer";
		li.innerHTML = "x";
		li.title = "Zatvori me"
		li.onclick = function() { obj.kill(); };
		ul.appendChild(li);
	
		this.wrapper.appendChild(ul);
	};

	this.swap = function(o){
		if(!document.getElementById("blob_wrapper")){ this.init(o);}
		img = new Image();
		img.id = "blob";		
		img.src = (o.nodeName == "IMG") ? o.src.replace(/thumbnails\//, "") : o.id; //(this.flag) ? o.src.replace(/thumbnails\//, "") : o.id;
		this.wait();
	};

	this.wait = function(){
		if(img.complete){
			if(document.getElementById("blob")){ document.getElementById("blob").parentNode.removeChild(document.getElementById("blob")); }
			point = window.center({width:img.width,height:img.height})
			
			this.wrapper.style.top = point.y + "px";
			this.wrapper.style.left = point.x + "px";

			this.wrapper.appendChild(img);
			document.body.appendChild(this.wrapper);

			Drag.init(this.wrapper);
		
		}else{
			window.setTimeout('g.wait()', 500);
		}
	};

	this.kill = function(){
		if(document.getElementById("blob_wrapper")){ document.getElementById("blob_wrapper").parentNode.removeChild(document.getElementById("blob_wrapper")); }
	};

	return true;
}

function get_content_size(){

    var size = new Array();
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        size[0] = window.innerWidth;
        size[1] = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        size[0] = document.documentElement.clientWidth;
        size[1] = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        size[0] = document.body.clientWidth;
        size[1] = document.body.clientHeight;
    }
    return size;

/*
	var viewportwidth;
	var viewportheight;
  
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined'){
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return [viewportwidth, viewportheight];
*/
}

function get_scroll_xy() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant 
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant 
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode 
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //return [scrOfX, scrOfY];
    return scrOfY;
}

window.size = function(){
	var w = 0;
	var h = 0;
	if(!window.innerWidth){ //IE
		if(!(document.documentElement.clientWidth == 0)){ //strict mode
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}else{ //quirks mode
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}else{ //w3c
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}

window.center = function(){
	var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
	var _x = 0;
	var _y = 0;
	var offsetX = 0;
	var offsetY = 0;

	if(!window.pageYOffset){ //IE
		if(!(document.documentElement.scrollTop == 0)){ //strict mode
			offsetY = document.documentElement.scrollTop;
			offsetX = document.documentElement.scrollLeft;
		}else{ //quirks mode
			offsetY = document.body.scrollTop;
			offsetX = document.body.scrollLeft;
		}
	}else{ //w3c
		offsetX = window.pageXOffset;
		offsetY = window.pageYOffset;
	}
	_x = ((this.size().width - hWnd.width) / 2) + offsetX;
	_y = ((this.size().height - hWnd.height) / 2) + offsetY;
	return{x:_x, y:_y};
}

function popup(m, w, h, t, c, s) {

    var obj = this;
    this.width = w;
    this.height = h;
    this.shield = null;
    this.popup = null;
    this.handler = null;
    this.content = null;
    this.iframe = null;
    this.client = get_content_size();

    this.init = function() {
        var shield = document.createElement("DIV");
        shield.id = "shield";
	 shield.style.zIndex = 99990;
        this.shield = shield;
        var popup = document.createElement("DIV");
        popup.id = "popup";
        //shield.appendChild(popup);
        popup.style.top = ((this.client[1] - (h + 44)) / 2) + "px";
        popup.style.left = ((this.client[0] - w) / 2) + "px";
        popup.style.width = w + "px";
        popup.style.height = (h + 44) + "px";
	 popup.style.zIndex = 99999;

        this.popup = popup;
        var handler = document.createElement("DIV");
        handler.id = "p_handler";
        handler.innerHTML = t;
        // uncomment the next line if you wonna have a title
        //handler.appendChild(document.createTextNode(t));

        if (m != "div") {
            var print = document.createElement("INPUT");
            print.type = "button";
            print.value = ""; // "Otisni"
            print.className = "print_btn";
            print.onclick = this.print.bind(this);
            handler.appendChild(print);
        }
        var close = document.createElement("INPUT");
        close.type = "button";
        close.value = ""; // "Zatvori"
        close.className = "close_btn";
        close.onclick = this.kill.bind(this);
        handler.appendChild(close);

        popup.appendChild(handler);
        this.handler = handler;

        if (m == "div") {
            var content = document.createElement("DIV");
            content.id = "p_content";
            content.style.width = w + "px";
            content.style.height = h + "px";
            content.style.marginTop = 1 + "px";
            popup.appendChild(content);
            this.content = content;
        } else {
            var iframe = document.createElement("IFRAME");
            iframe.id = "i_frame";
            iframe.style.border = 0 + "px";
            iframe.frameBorder = 0;
            iframe.width = w + "px";
            iframe.height = h + "px";
            iframe.style.marginTop = 1 + "px";
            iframe.style.marginBottom = 0 + "px";
            iframe.style.backgroundColor = "#fff";
            popup.appendChild(iframe);
            iframe.src = s;
        }

        document.body.appendChild(shield);
        document.body.appendChild(popup);

        if (m == "div") {
            this.content.innerHTML = c;
        } else {
            ifrm = document.getElementById("i_frame");
            ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
            ifrm.document.open();
            ifrm.document.write(c);
            ifrm.document.close();
        }

        if (navigator.appVersion.match("MSIE 6.0")) {
            shield.id = "shield_IE6";
            popup.id = "popup_IE6";
            popup.style.top = ((this.client[1] - (h + 44)) / 2) + get_scroll_xy() + "px";
            shield.style.top = 0 + get_scroll_xy() + "px";
            document.getElementsByTagName("HTML")[0].style.overflow = "hidden";
        }
    };

    this.kill = function() {
        this.popup.parentNode.removeChild(this.popup);
        this.shield.parentNode.removeChild(this.shield);

        if (navigator.appVersion.match("MSIE 6.0")) {
            document.getElementsByTagName("HTML")[0].style.overflow = "";
        }
        obj = null;
    };

    this.print = function() {
        if ((navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') == true) {
            document.frames[0].focus();
            document.frames[0].print();
        } else {
            window.frames[0].focus();
            window.frames[0].print();
        }
    }

    this.init();

    return true;
}

var Drag={obj:null,init:function(o,oRoot,minX,maxX,minY,maxY,bSwapHorzRef,bSwapVertRef,fXMapper,fYMapper){o.onmousedown=Drag.start;o.hmode=bSwapHorzRef?false:true;o.vmode=bSwapVertRef?false:true;o.root=oRoot&&oRoot!=null?oRoot:o;if(o.hmode&&isNaN(parseInt(o.root.style.left)))o.root.style.left="0px";if(o.vmode&&isNaN(parseInt(o.root.style.top)))o.root.style.top="0px";if(!o.hmode&&isNaN(parseInt(o.root.style.right)))o.root.style.right="0px";if(!o.vmode&&isNaN(parseInt(o.root.style.bottom)))o.root.style.bottom="0px";o.minX=typeof minX!='undefined'?minX:null;o.minY=typeof minY!='undefined'?minY:null;o.maxX=typeof maxX!='undefined'?maxX:null;o.maxY=typeof maxY!='undefined'?maxY:null;o.xMapper=fXMapper?fXMapper:null;o.yMapper=fYMapper?fYMapper:null;o.root.onDragStart=new Function();o.root.onDragEnd=new Function();o.root.onDrag=new Function();},start:function(e){var o=Drag.obj=this;e=Drag.fixE(e);var y=parseInt(o.vmode?o.root.style.top:o.root.style.bottom);var x=parseInt(o.hmode?o.root.style.left:o.root.style.right);o.root.onDragStart(x,y);o.lastMouseX=e.clientX;o.lastMouseY=e.clientY;if(o.hmode){if(o.minX!=null)o.minMouseX=e.clientX-x+o.minX;if(o.maxX!=null)o.maxMouseX=o.minMouseX+o.maxX-o.minX;}else{if(o.minX!=null)o.maxMouseX= -o.minX+e.clientX+x;if(o.maxX!=null)o.minMouseX= -o.maxX+e.clientX+x;}if(o.vmode){if(o.minY!=null)o.minMouseY=e.clientY-y+o.minY;if(o.maxY!=null)o.maxMouseY=o.minMouseY+o.maxY-o.minY;}else{if(o.minY!=null)o.maxMouseY= -o.minY+e.clientY+y;if(o.maxY!=null)o.minMouseY= -o.maxY+e.clientY+y;}document.onmousemove=Drag.drag;document.onmouseup=Drag.end;return false;},drag:function(e){e=Drag.fixE(e);var o=Drag.obj;var ey=e.clientY;var ex=e.clientX;var y=parseInt(o.vmode?o.root.style.top:o.root.style.bottom);var x=parseInt(o.hmode?o.root.style.left:o.root.style.right);var nx,ny;if(o.minX!=null)ex=o.hmode?Math.max(ex,o.minMouseX):Math.min(ex,o.maxMouseX);if(o.maxX!=null)ex=o.hmode?Math.min(ex,o.maxMouseX):Math.max(ex,o.minMouseX);if(o.minY!=null)ey=o.vmode?Math.max(ey,o.minMouseY):Math.min(ey,o.maxMouseY);if(o.maxY!=null)ey=o.vmode?Math.min(ey,o.maxMouseY):Math.max(ey,o.minMouseY);nx=x+((ex-o.lastMouseX)*(o.hmode?1: -1));ny=y+((ey-o.lastMouseY)*(o.vmode?1: -1));if(o.xMapper)nx=o.xMapper(y);else if(o.yMapper)ny=o.yMapper(x);Drag.obj.root.style[o.hmode?"left":"right"]=nx+"px";Drag.obj.root.style[o.vmode?"top":"bottom"]=ny+"px";Drag.obj.lastMouseX=ex;Drag.obj.lastMouseY=ey;Drag.obj.root.onDrag(nx,ny);return false;},end:function(){document.onmousemove=null;document.onmouseup=null;Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode?"left":"right"]),parseInt(Drag.obj.root.style[Drag.obj.vmode?"top":"bottom"]));Drag.obj=null;},fixE:function(e){if(typeof e=='undefined')e=window.event;if(typeof e.layerX=='undefined')e.layerX=e.offsetX;if(typeof e.layerY=='undefined')e.layerY=e.offsetY;return e;}}; 
