﻿function default_value(obj,v,k){

	var element = document.getElementById(obj);

	if(k==0){

		if(element.value==v){

			element.value = "";

		}

	}else{

		if(element.value==""){

			element.value=v;

		}

	}

}

function checkbox_area(obj){

	var cb = document.getElementById(obj);

	if(cb.checked){

		cb.checked = false;

	}else{

		cb.checked = true;

	}

}



function checkurl(){

	var url = document.getElementById('url');

	var img = document.getElementById('urlcheck');

	if(url.value=="" || url.value=="http://"){

		img.innerHTML = '<img border="0" src="http://www.xebername.com/style/default/images/incorrect.png">';

		return false;

	}else{

   		enurl = encodeURIComponent(url.value);

    	ajax_do('http://www.xebername.com/check_url.php','url='+enurl,'1','');

	}

}

function closecomments(id){

	var cmnt = document.getElementById('tr-comments-'+id);

	cmnt.style.display="none";

}



function ajax_do(url , parametr, no, boxid){

    var xmlhttp=false;

    /*@cc_on @*/

    /*@if (@_jscript_version >= 5)

    try {

        xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');

    } catch (e) {

        try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }

		catch (E)

		{ xmlhttp = false; }

    }

    @end @*/

    if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); }

    xmlhttp.open('POST', url, true);

    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    xmlhttp.onreadystatechange = function() {

	    if(xmlhttp.readyState==4) {

	    	if(no!=''){

	    		eval("response"+no+"(xmlhttp.responseText,'"+boxid+"')");

	    	}

       }else{

       		if(no!=''){

	      		eval("loading"+no+"('"+boxid+"')");

       		}

	   }

	}

	xmlhttp.send(parametr);

}



function trim(text) {

	return text.replace(/^\s+|\s+$/g,"");

}



function submitlink(){

	

	var url = document.getElementById('url');

	var urlimg = document.getElementById('urlcheck');

	var dsc = document.getElementById('description');

	var tags = document.getElementById('tags');

	var acc = document.getElementById('accept');

	var subject = document.getElementById('subject');

	

	var errmsg="";

	var noerror = true;

	

	if(url.value=="" || url.value=="http://" || urlimg.innerHTML=='<img border="0" src="style/default/images/incorrect.png" title="Xəbərin keçidin düzgün yazın">'){

		errmsg += " \* Düzgün keçid yazın\n";

		noerror = false;

	}

	if(urlimg.innerHTML=='<a href="link/\'+trim(text)+\'"><img border="0" src="style/default/images/incorrect.png" title="Bu xəbər artıq mövcuddur">Bu xəbər artıq mövcuddur: Baxın '){

		errmsg += " \* Bu keçid artıq sistemdə mövcuddur\n";

		noerror = false;

	}

	if(trim(subject.value)==""){

		errmsg += " \* Başlıq yazın\n";

		noerror = false;

	}

	if(trim(dsc.value)==""){

		errmsg += " \* İzah yazın\n";

		noerror = false;

	}

	if(trim(tags.value)==""){

		errmsg += " \* Açar sözləri yazın\n";

		noerror = false;

	}

	if(!acc.checked){

		errmsg += " \* Yeni xəbər göndərmək üçün qaydaları qəbul etməlisiniz\n";

		noerror = false;

	}

	if(noerror){

		return true;

	}else{

		alert(errmsg);

		return false;

	}

}



function changepoint(id,aod,reason){

	ajax_do('http://www.xebername.com/changepoint.php','id='+id+'&action='+aod+'&reason='+reason,'1',id);

}



function add2myfav(id,action){

	ajax_do('http://www.xebername.com/add2fav.php','linkid='+id+'&action='+action,'2',id);

}



function showreasons(id,ac){

	var rsn = document.getElementById("reasons"+id);

	if(ac=="1"){

		rsn.style.display = "block";

	}else{

		rsn.style.display = "none";

	}

}



function addclick(id){

	ajax_do('http://www.xebername.com/addclick.php','linkid='+id,'','');

	return false;

}



function showcomments(id){

	ajax_do('http://www.xebername.com/showcomments.php','linkid='+id,'3',id);

}



function sendcomment(id){

	var body = document.getElementById("my-comment-"+id);

	var mess = encodeURIComponent(body.value);

	ajax_do('http://www.xebername.com/sendcomment.php','linkid='+id+'&mess='+mess,'4',id);

}



function votecomment(id,action){

	ajax_do('http://www.xebername.com/votecomment.php','commentid='+id+'&action='+action,'5',id);

}



function editcomment(id){

	var commentbody = document.getElementById('comment-body-'+id);

	var bbcodetext = document.getElementById('bbcode-body-'+id);

	commentbody.innerHTML = '<textarea name="edited-comment-'+id+'" id="edited-comment-'+id+'" class="textbox" style="width: 400px; height: 50px; direction: rtl;" lang="fa">'+bbcodetext.value+'</textarea><br><input type="button" value="Qeyd et" style="font-family:Tahoma; font-size: 11px; width: 120px; height: 20px" onclick="savemsg('+id+')"/> <input type="button" value="Ləğv et" style="font-family:Tahoma; font-size: 11px; width: 120px; height: 20px" onclick="cancelediting('+id+')"/>';

}



function cancelediting(id){

	var commentbody = document.getElementById('comment-body-'+id);

	var htmltext = document.getElementById('html-body-'+id);

	commentbody.innerHTML = htmltext.value;

}

function savemsg(id){

	var newcomment = document.getElementById("edited-comment-"+id);

	var bbcodetext = document.getElementById('bbcode-body-'+id);

    var extratext = document.getElementById('extra-body-'+id);

	extratext.value = bbcodetext.value;

    bbcodetext.value = newcomment.value;

	var mess = newcomment.value;

	ajax_do('http://www.xebername.com/editcomment.php','commentid='+id+"&mess="+mess,'6',id);

}



function displaynewhotsubject(){

	var nhs = document.getElementById("addnewhotsubject");

	if(nhs.style.display=="none"){

		nhs.style.display = "block";

	}else if(nhs.style.display=="block"){

		nhs.style.display = "none";

	}

}



function sendnewhotsubject(){

	var subject = document.getElementById("subject");

	var desc = document.getElementById("hotsubject-des");

	var img = document.getElementById("picture");

	var errmsg="";

	var errexists = false;

	if(subject.value==""){

		errmsg += " - Xahiş olunur başlıq yazın\n";

		errexists = true;

	}

	if(desc.value==""){

		errmsg += " - Xahiş olunur izah yazın\n";

		errexists = true;

	}

	if(img.value=="" || img.value=="http://"){

		errmsg += " - Xahiş olunur şəkil seçin\n";

		errexists = true;

	}

	if(errexists==false){

		subject = encodeURIComponent(subject.value);

		desc = encodeURIComponent(desc.value);

		img = encodeURIComponent(img.value);

		ajax_do('http://www.xebername.com/addhotsubject.php','subj='+subject+"&desc="+desc+"&img="+img,'7','10');

	}else{

		alert(errmsg);

	}

}

function changehs(id){

	var hs = document.getElementById("hotsubjects");

	var selectedhs = encodeURIComponent(hs.value);

	ajax_do('http://www.xebername.com/changehs.php','linkid='+id+"&subject="+selectedhs,'8','-');

}

function send_qr(s){

	var to = document.getElementById("to");

	var subj = document.getElementById("subject");

	

	if(s==0){

		var mess = document.getElementById("message");

	}else{

		var mess = document.getElementById("my-comment-");

	}

	

	to = encodeURIComponent(to.value);

	subj = encodeURIComponent(subj.value);

	mess = encodeURIComponent(mess.value);

	

	ajax_do('http://www.xebername.com/send_quick_reply.php','to='+to+"&subject="+subj+"&body="+mess,'1','-');

}



function suggestedusernames(){

	var to = document.getElementById('to');

	to = encodeURIComponent(to.value);

	ajax_do('http://www.xebername.com/suggestedun.php','to='+to,'2','-');

}



function hider(){

	var rs = document.getElementById("sun");

	rs.style.display = "none";

}



function addun(text){

	var to = document.getElementById('to');

	to.value=text;

}



function deletepm(id){

	id = encodeURIComponent(id);

	ajax_do('http://www.xebername.com/deletepm.php','id='+id,'3',id);

}

function showpage(page,linkid){

	page = encodeURIComponent(page);

	linkid = encodeURIComponent(linkid);

	ajax_do('http://www.xebername.com/updatecomments.php','page='+page+'&linkid='+linkid,'9',linkid);

}



function checkun(){

	var un = document.getElementById("r_username");

	un = encodeURIComponent(un.value);

	ajax_do('http://www.xebername.com/checkun.php','un='+un,'1','');

}



function aorfriend(id,action){

	id = encodeURIComponent(id);

	action = encodeURIComponent(action);

	ajax_do('http://www.xebername.com/aorfriend.php','id='+id+'&do='+action,'1','');

}



function addhyperlink(commentid){

	var link = prompt("Xahiş edirik keçid ünvanını yazın (http:// ilə birgə)","http://");

	bbInsertTag(document.getElementById(commentid),'[link='+link+']','[/link]')

}



function register_check(){

	var un = document.getElementById("r_username");

	var pass1 = document.getElementById("r_password");

	var pass2 = document.getElementById("passwordr");

	var email1 = document.getElementById("email");

	var email2 = document.getElementById("emailr");

	var fname = document.getElementById("firstname");

	var lname = document.getElementById("lastname");

	var accept = document.getElementById("accept");

	

	var errmsg = "";

	var erre = false;

	

	if(un.value==""){

		errmsg += ' - İstifadəçi adınızı yazın<br>';

		erre = true;

	}

	if(pass1.value==""){

		errmsg += ' - Şifrənizi yazın<br>';

		erre = true;

	}

	if(pass2.value==""){

		errmsg += ' - Şifrəni təkrar yazın<br>';

		erre = true;

	}

	if(pass1.value != pass2.value){

		errmsg += ' - Şifrə və onun təkrarı səhvdir<br>';

		erre = true;

	}

	if(email1.value==""){

		errmsg += ' - E-mail ünvanınızı daxil edin<br>';

		erre = true;

	}

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email1.value)){

	}else{

		errmsg += ' - Yazdığınız e-mail ünvanı etibarlı deyil‎<br>';

		erre = true;

	}

	if(email2.value==""){

		errmsg += ' - E-mail ünvanı təkrar yazın<br>';

		erre = true;

	}

	if(email1.value != email2.value){

		errmsg += ' - E-mail ünvanı və təkrarı yanlışdır<br>';

		erre = true;

	}

	if(fname.value==""){

		errmsg += ' - Adınızı yazın<br>';

		erre = true;

	}

	if(lname.value == ""){

		errmsg += ' - Soy adınızı yazın<br>';

		erre = true;

	}

	if(accept.checked==false){

		errmsg += ' - Sayt qaydalarını qəbul etməmisiniz<br>';

		erre = true;	

	}

	if(erre==true){

		var check = document.getElementById("checkinfo");

		check.style.display="block";

		check.innerHTML = errmsg;

		document.location = "#";

		return false;

	}else{

		return true;

	}

}



function forgotpw(){

	var un = document.getElementById('user_name');

	var ue = document.getElementById('user_email');

	un = encodeURIComponent(un.value);

	ue = encodeURIComponent(ue.value);

	ajax_do('http://www.xebername.com/fpw.php','un='+un+'&ue='+ue,'1','');

}



function hsaor(action,hsid){

	action = encodeURIComponent(action);

	hsid = encodeURIComponent(hsid); 

	ajax_do('http://www.xebername.com/hsaction.php','action='+action+'&hsid='+hsid,'1',hsid);

}

function sendreply(topicid){

	topicid = encodeURIComponent(topicid);

	var body = document.getElementById("my-comment-"+topicid);

	var mess = encodeURIComponent(body.value);

	ajax_do('http://www.xebername.com/sendreply.php','topicid='+topicid+'&message='+mess,'1',topicid);

}

function changetopicpage(page,topicid){

	var changepage = document.getElementById("pageno");

	changepage.innerHTML = page;

	page = encodeURIComponent(page);

	topicid = encodeURIComponent(topicid);

	ajax_do('http://www.xebername.com/updatetopics.php','page='+page+'&topicid='+topicid,'2',topicid);

}

function editpost(id){

	var postbody = document.getElementById('post-'+id);

	var bbcodetext = document.getElementById('bbcode-mess-'+id);

	postbody.innerHTML = '<textarea name="edited-post-'+id+'" id="edited-post-'+id+'" class="textbox" style="width: 510px; height: 50px; direction: rtl;" lang="fa">'+bbcodetext.value+'</textarea><br><input type="button" value="Qeyd et" style="font-family:Tahoma; font-size: 11px; width: 120px; height: 20px" onclick="savepost('+id+')"/> <input type="button" value="Ləğv et" style="font-family:Tahoma; font-size: 11px; width: 120px; height: 20px" onclick="canceleditingpost('+id+')"/>';

}



function canceleditingpost(id){

	var postbody = document.getElementById('post-'+id);

	var htmltext = document.getElementById('html-mess-'+id);

	postbody.innerHTML = htmltext.value;

}



function savepost(id){

	var newpost = document.getElementById("edited-post-"+id);

	var bbcodetext = document.getElementById('bbcode-mess-'+id);

    	var extratext = document.getElementById('extra-mess-'+id);

	extratext.value = bbcodetext.value;

   	bbcodetext.value = newpost.value;

	var mess = newpost.value;

	ajax_do('http://www.xebername.com/editpost.php','postid='+id+"&mess="+mess,'3',id);

}