
var req = null;

function InitXMLHttpRequest() {
	// Make a new XMLHttp object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
//	if (typeof window.ActiveXObject != 'undefined' ) req = new ActiveXObject("Microsoft.XMLHTTP");
//	else req = new XMLHttpRequest();
}

function SelectCountry(section, destination) {
	InitXMLHttpRequest();
	// Load the result from the response page
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				destination.innerHTML = req.responseText;
			} else {
				if (section == 'rp') {
					destination.innerHTML = "<select style=\"width:150px\"><option>Loading data...</option></select>";
				} else {
					destination.innerHTML = "<select style=\"width:150px\" class=\"index_select\"><option>Loading data...</option></select>";
				}

			}
		}
		req.open("GET", SEO_SITE_ROOT+"/location.php?ajax=1&sec=" + section + "&sel=country", true);
		req.send(null);
	} else {
		destination.innerHTML = 'Browser unable to create XMLHttp Object';
	}
}

function SelectRegion(section, id_country, destination, destination2) {
	if (id_country != '') {
		InitXMLHttpRequest();
		// Load the result from the response page
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					destination.innerHTML = req.responseText;
				} else {
					switch(section){
						case 'rp':destination.innerHTML = "<select style=\"width:150px\"><option>Loading data...</option></select>";break;
						case '':destination.innerHTML = "<select style=\"width:150px\"><option>Loading data...</option></select>";break;
						default:destination.innerHTML = "<select style=\"width:150px\" class=\"index_select\"><option>Loading data...</option></select>";
					}
				}
			}
			req.open("GET", SEO_SITE_ROOT+"/location.php?ajax=1&sec=" + section + "&sel=region&id_country=" + id_country, true);
			req.send(null);
		} else {
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	} else {
		destination.innerHTML = "Country is not selected";
	}
	switch(section){
		case 'as':destination2.innerHTML = "<select style=\"width:150px\" class=\"index_select\"><option>All</option></select>";break;
		case 'rp':destination2.innerHTML = "<select style=\"width:150px\"><option>Please select...</option></select>";break;
		case '':destination2.innerHTML = "<select style=\"width:150px\"><option>Please select...</option></select>";break;
		default:destination2.innerHTML = "<select style=\"width:150px\" class=\"index_select\"><option>Please select...</option></select>";
	}
}

function SelectCity(section, id_region, destination) {
	if (id_region != '') {
		InitXMLHttpRequest();
		// Load the result from the response page
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					destination.innerHTML = req.responseText;
				} else {
					switch(section){
						case 'rp':destination.innerHTML = "<select style=\"width:150px\"><option>Loading data...</option></select>";break;
						case '':destination.innerHTML = "<select style=\"width:150px\"><option>Loading data...</option></select>";break;
						default:destination.innerHTML = "<select style=\"width:150px\" class=\"index_select\"><option>Loading data...</option></select>";
					}
				}
			}
			req.open("GET", SEO_SITE_ROOT+"/location.php?ajax=1&sec=" + section + "&sel=city&id_region=" + id_region, true);
			req.send(null);
		} else {
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	} else {
		destination.innerHTML = "Region is not selected";
	}
}

function CheckLogin(section, login, destination) {
	if (login != '') {
		InitXMLHttpRequest();
		// Load the result from the response page
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					destination.innerHTML = req.responseText;
				}
			}
			req.open("GET", SEO_SITE_ROOT+"/location.php?sec=" + section + "&sel=login&login=" + login, true);
			req.send(null);
		} else {
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	} else {
		destination.innerHTML = "Nick is empty";
	}
}

function ShowTab(sel, mlink, sub, sec_par) {

	str = '';
	destination = $('#tab_div');

	if (sel > 6 && sub != 0) {
	//multimedia
//		if (sec_par == 2) {
//		//viewprofile
//		} else {
//		//myprofile
//		}
		$('#sub_menu7,#sub_menu8,#sub_menu9,#sub_menu10').removeClass().addClass('sub_tab');
		$("#sub_menu"+sel).removeClass().addClass('sub_tab_active');
		$("sub_link7,sub_link8,sub_link9,sub_link10").removeClass().addClass('link');
		$("sub_link"+sel).removeClass().addClass('text');

		file = mlink + "&ajax=1&sub=" + sel + "&act=ajax&action="+ sub;
	} else {
	//main tabs
		$('#menu1,#menu2,#menu3,#menu4,#menu5,#menu6').removeClass().addClass('tab');
		$('#link1,#link2,#link3,#link4,#link5,#link6').removeClass().addClass('tlink');
		$("#menu"+sel).removeClass().addClass('tab_active');
		$("#link"+sel).removeClass().addClass('tlink_active');

		file = mlink + "&ajax=1&act=ajax";
	}

	$.post(file,str,function(data){
		destination.html(data);
	});
}

function RunJS(dest, response){

	if (response.search(/<script/) == -1){
		dest.innerHTML = response;
		return false;
	}
	//Check user browser
	var agent=(window.navigator.appName=='Netscape')?'Firefox':'IE';
	if(agent=='IE'){
		///place &nbsp; before <scrript> tag
		dest.innerHTML=response;
		var arr_scripts = dest.getElementsByTagName("script");
		for(i in arr_scripts){
			var src = arr_scripts[i].src;
			if(null!=src){
				var has_question = (src.indexOf('?', 1)>0 ? true : false);
				if(0==src.length)
					arr_scripts[i].setAttribute('src', '');
				else
					arr_scripts[i].setAttribute('src', arr_scripts[i].src + (has_question==true ? '&' : '?') + '1=1');
			}
		}
	}else{
		//Mozilla
		var d=dest.parentNode;
		var d_new=document.createElement('div');

		//Set same attributes as original
		var attributes=dest.attributes;
		var len=attributes.length;

		d_new.innerHTML=response;
		for(var i=0; i<len; i++){
			d_new.setAttribute(attributes[i].name, attributes[i].value);
		}

		d.replaceChild(d_new, dest);
	}
}

function ajaxRequest(file_name, str, destination_odj, tmp_text, anisochronous){
	if (str != '') {
		str = str+'&ajax=1';
		InitXMLHttpRequest();
		// Load the result from the response page
		if (req) {
			if (anisochronous){
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						//destination_odj.innerHTML = req.responseText;
						RunJS(destination_odj,req.responseText);
					} else {
						destination_odj.innerHTML = tmp_text;
					}
				}
			}
			req.open("POST", file_name+'?rnd='+Math.random(), anisochronous);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8 ');
			req.setRequestHeader("Content-length", str.length);
      		req.setRequestHeader("Connection", "close");
			req.send(str);
			if (!anisochronous) RunJS(destination_odj,req.responseText);
		} else {
			destination_odj.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	} else {
		destination_odj.innerHTML = "no string";
	}
}
opacity = 0;
i1 = 0;
i2 = 0;
t1 = 0;
function noticeCode(code){
	//if(code == '') return false;
	addNoticeDiv(code);
	divTag = document.getElementById('notice_div');
	opacity = 0;
	i1 = setInterval('increaseOpacity(divTag);',2);
}

function increaseOpacity(divTag){
	opacity++;
	if (opacity >= 100){
		clearInterval(i1);
		setTimeout("i2 = setInterval('decreaseOpacity(divTag)',5)",3000);
		return false;
	}
	setOpacity(divTag,opacity);
}

function decreaseOpacity(divTag){
	opacity = opacity-10;
	if (opacity <= 1){
		clearInterval(i2);
		clearTimeout(t1);
		document.body.removeChild(divTag);
		return false;
	}
	setOpacity(divTag,opacity);
}
function setOpacity(divTag,i){
	divTag.style.filter = 'alpha(opacity='+i+')';
	divTag.style.opacity = i/100;
}
function addNoticeDiv(code){
	if (document.getElementById('notice_div')){
		clearInterval(i1);
		clearInterval(i2);
		clearTimeout(t1);
		divTag = document.getElementById('notice_div');
		if (divTag) document.body.removeChild(divTag);
	}

	var divTag = document.createElement("div");

	divTag.id = 'notice_div';
	divTag.setAttribute('align','center');
	divTag.style.margin = '0px auto';
	divTag.style.border = '1px solid #000000';
	divTag.style.background = '#ffffff';
	divTag.style.padding = '15px'

	if (navigator.appName == 'Microsoft Internet Explorer'){
		divTag.style.position = 'absolute';
		divTag.style.top = document.body.scrollTop+10;
	}else{
		divTag.style.position = 'fixed';
		divTag.style.top = '10px';
	}
	divTag.style.left = '10px';

	divTag.style.filter = 'alpha(opacity=1)';
	divTag.style.opacity = '0.01';

	divTag.className ="dynamicDiv";
	divTag.innerHTML = code;
	document.body.appendChild(divTag);
}
