var global_pageUrl;
var http=global_getHttp();
var whereToShow;
//var rec;
//var for_indicator;
//var user_main_content;
//===========================================================
function global_getHttp(){
	var xmlHttp;
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try {
				xmlHttp = new XMLHttpRequest();
			}
			catch (e) {
				xmlHttp = false;
			}

		}
	}
	return xmlHttp;
}

//===========================================================

function getAnswer_toShow(){
	simulateClick("user_top_link");
	if(http.readyState==0){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==1){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==2){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==3){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==4){
		document.getElementById("for_indicator").style.visibility="hidden";
		rec=http.responseText;
		//alert(rec);
		document.getElementById(whereToShow).innerHTML=rec;
//		user_top_link.click();
	}
	return;
}
//===========================================================

function get_content_toShow(addr,where){
	whereToShow=where;
	http.open("GET","index2.php?"+addr,true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	http.send(null);
	http.onreadystatechange=getAnswer_toShow;
}
//=============================================================
function getSearchAnswer_toShow(){
	simulateClick("user_top_link");
	if(http.readyState==0){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==1){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==2){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==3){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==4){
		document.getElementById("for_indicator").style.visibility="hidden";
		rec=http.responseText;
		//alert(rec);
		document.getElementById("user_main_content").innerHTML=rec;
//		user_top_link.click();
	}
	return;
	
}

function search_get_content(addr,q,where){
	http.open("POST","index2.php?"+addr,true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	params="q="+q;
	http.send(params);
	http.onreadystatechange=getSearchAnswer_toShow;
	
}

//================================================================

//======================= Users Functions Start =========================
//=====================================================================
function users_send_login_form(comp_folder,where){
	//alert(where);
	check=users_check_filledForm();
	if(!check){
		return false;
	}
	//alert(comp_folder);
	whereToShow=where;
	http.open("POST","index2.php?comp=users&act=dologin",true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(check);
	http.onreadystatechange=users_user_getAnswer;
}
//==============================================================
function users_user_getAnswer(){
	if(http.readyState==0){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==1){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==2){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==3){
		document.getElementById("for_indicator").style.visibility="";
	}
	if(http.readyState==4){
		document.getElementById("for_indicator").style.visibility="hidden";
		rec=http.responseText;
		//alert(rec);
		document.getElementById(whereToShow).innerHTML=rec;
		simulateClick("user_top_link");
	}
	return;
}
//=====================================================================
function users_send_reg_form(comp_folder,where){
	//alert(where);
	check=users_checkReg_filledForm();
	if(!check){
		return false;
	}
	//alert(comp_folder);
	whereToShow=where;
	http.open("POST","index2.php?comp=users&act=doregister",true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(check);
	http.onreadystatechange=users_user_getAnswer;
}
//==============================================================
function users_checkReg_filledForm(){
	fn=regform.fname;
	ln=regform.lname;
	tl=regform.tel;
	em=regform.email;
	cn=regform.country;
	st=regform.state;
	ct=regform.city;
	us=regform.username;
	fus=regform.friend_username;
	ps=regform.password;
	cps=regform.cpassword;
	cp=regform.capt;
	dy=regform.year;
	dm=regform.month;
	dd=regform.day;
	
	
if(!us.value || !ps.value || !cps.value || !tl.value || !em.value || !fn.value || !ln.value || cp.value.length<5){
	alert("لطفاً فیلدهای لازم را به درستی پر نمایید");
	return false;
}
if(!email_validator(em.value)){
	alert("ایمیل خود را به درستی وارد نمایید");
	em.focus();
	return false;
}
if(cn.selectedIndex==0){
	alert("کشور خود را انتخاب نمایید");
	cn.focus();
	return false;
}
if(cn.value=='ایران'){
if(st.selectedIndex==0){
	alert("استان خود را انتخاب نمایید");
	st.focus();
	return false;
}

if(ct.selectedIndex==0){
	alert("شهر خود را انتخاب نمایید");
	ct.focus();
	return false;
}
}
if(ps.value.length<4){
	alert("رمز عبور حداقل باید دارای 4 کاراکتر باشد");
	ps.value='';
	cps.value='';
	ps.focus();
	return false;	
}

if(ps.value!=cps.value){
	alert("رمز عبور به درستی تایید نشد");
	ps.value='';
	cps.value='';
	ps.focus();
	return false;	
}

chk="username="+us.value+"&password="+ps.value+"&capt="+cp.value+"&fname="+fn.value+"&lname="+ln.value+"&email="+em.value+"&tel="+tl.value+"&friend_username="+fus.value+"&country="+cn.value+"&state="+st.value+"&city="+ct.value+"&year="+dy.value+"&month="+dm.value+"&day="+dd.value;
return chk;
}
//==============================================================
function users_check_filledForm(){
	us=loginform.username;
	ps=loginform.password;
	cp=loginform.capt;
	fv=loginform.forever;
if(!us.value || !ps.value || cp.value.length<5){
	alert("لطفاً فیلدهای لازم را به درستی پر نمایید");
	return false;
}
if(fv.checked)
	fv="on";
else
	fv="";
chk="username="+us.value+"&password="+ps.value+"&capt="+cp.value+"&fv="+fv;
return chk;
}
//================================================================

//======================= Users Functions End =========================

//================================================================
function users_change_city_getAnswer(){
	if(http.readyState==0){
		document.getElementById("for_state_indicator").style.visibility="";
	}
	if(http.readyState==1){
		document.getElementById("for_state_indicator").style.visibility="";
	}
	if(http.readyState==2){
		document.getElementById("for_state_indicator").style.visibility="";
	}
	if(http.readyState==3){
		document.getElementById("for_state_indicator").style.visibility="";
	}
	if(http.readyState==4){
		document.getElementById("for_state_indicator").style.visibility="hidden";
		rec=http.responseText;
		//alert(rec);
		document.getElementById(whereToShow).innerHTML=rec;
	}
	return;
}
//==============================================================
function change_city_combo(oid,where,city){
	whereToShow=where;
	http.open("GET","change_city.php?oid="+oid+"&city="+city,true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(null);
	http.onreadystatechange=users_change_city_getAnswer;	
}

//================================================================
