//fixed function
var xmlHttp;
var homeurl = 'http://blogsrobot.com/';

if (!xmlHttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlHttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlHttp=false
	 }
}

function GetXmlHttpObject() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}

//===========get email list=============//
function getEmail()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
document.getElementById("processem").style.display = 'none';
document.getElementById("fail").style.display = 'none';
document.getElementById("success").style.display = 'none';
document.getElementById("emilinput").style.display = 'none';

document.getElementById("processem").style.display = ''; 
var email = document.getElementById('email');
$.get(homeurl + 'email.php', {action : 'reg', email: email.value}
   , function(result) {
      if (result == 0) {
         alert('خطأ!'); }
	
      else if(result == 1){
		 document.getElementById("processem").style.display = 'none';
		 document.getElementById("success").style.display = '';}
      else if(result == 2){
	     document.getElementById("processem").style.display = 'none';
		 document.getElementById("fail").style.display = '';}
      }
   );
}

//===========delete email list=============//
function delEmail()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return
 }
document.getElementById("emailst").style.display = 'block'; 
var email = document.getElementById('email');
var url = homeurl+"email.php";
url=url+"?action=del";
url=url+"&email="+email.value;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangede;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
//================Poll Ajax Functions=============//
function getidPoll(id) {
   document.getElementById("hidv").innerHTML = '<input id="hid" type="hidden" value="' + id + '">';
   }
function getPoll() {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
   var polls = document.getElementById('hid');
   if(polls.value == 0) {
      alert('الرجاء اختيار احد الاسئله لاكمال العمليه');
      }
   else {
      document.getElementById("ajaxpro").innerHTML = "<img src='"+homeurl+"images/progressbar2.gif' alt='processing' />";
      var url = homeurl + "poll.php";
      url = url + "?action=vote";
      url = url + "&poll=" + polls.value;
      url = url + "&psid=" + Math.random();
      xmlHttp.onreadystatechange = pollviewajax;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }
   }
function pollviewajax() {
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
      document.getElementById("ajaxpro").innerHTML = "";
      document.getElementById("ajaxpoll").innerHTML = xmlHttp.responseText;
      }
   }
   
//===============Ajax send reply=============//
function sendcomment() {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
   var name = document.getElementById('wname');
   var email = document.getElementById('email');
   var content = document.getElementById('message');
   var sid = document.getElementById('sid');
   document.getElementById("ajaxproc").innerHTML = "<br /><img src='"+homeurl+"images/ajax-loader.gif' alt='جاري اضافة الرد من فضلك انتظر....' />";
   $.get(homeurl + 'ajax.php', {
      n : name.value, e : email.value, c : content.value, s : sid.value}
   , function(result) {
      if (result == 0) {
         alert('خطأ!'); }
      else {
         $(result).appendTo('#ajaxcomment');
		 content.value = '';
		 document.getElementById("ajaxproc").innerHTML = ""; }
      }
   );
}
/*------Report bad Reply---------*/
function report_bad(id) {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
   var url = homeurl + 'blog.php?action=report&id=' + id;
   
   xmlHttp.onreadystatechange = report_bad;
   xmlHttp.open("GET", url, true);
   xmlHttp.send(null);
   
   function report_bad() {
      if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
         alert('تم الارسال التبليغ بنجاح ..شكرا لاهتمامكم');
         }
      }
   }
//=========Confirmation user register ajax=============//
function Confirm_User(username)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }

document.getElementById("ajax_confim_user").innerHTML = "<img src='"+homeurl+"images/working.gif' alt='جاري التحقق من توافر اسم المستخدم' />";

var url = homeurl+"register.php"
url=url+"?action=ajax"
url=url+"&do=userconfirm"
url=url+"&username="+username
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=update_confirm 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function update_confirm() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("ajax_confim_user").
 innerHTML=xmlHttp.responseText;
 } 
} 


//=========Confirmation user register ajax=============//
function Confirm_Email(email)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }

document.getElementById("ajax_confim_email").innerHTML = "<img src='"+homeurl+"images/working.gif' alt='جاري التحقق من توافر البريد الالكتروني' />";

var url = homeurl+"register.php"
url=url+"?action=ajax"
url=url+"&do=emailconfirm"
url=url+"&email="+email
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=update_confirm_email
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function update_confirm_email() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("ajax_confim_email").
 innerHTML=xmlHttp.responseText;
 } 
} 

//========Password Generator ===========//
function getRandomNum(lbound, ubound) {
return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar() {
var numberChars = "0123456789";
var lowerChars = "abcdefghijklmnopqrstuvwxyz";
var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
var charSet = 0;

charSet += numberChars;
charSet += lowerChars;
charSet += upperChars;

return charSet.charAt(getRandomNum(0, charSet.length));
}
function getPassword(length) {
var rc = "";
if (length > 0)
rc = rc + getRandomChar();
for (var idx = 1; idx < length; ++idx) {
rc = rc + getRandomChar();
}
document.getElementById("mypassword_text").innerHTML = "<p style='font-size:13px'>"+rc+"</p>";
return rc;
}

//=========Confirmation 2 Email Input=============//
function verify_2Email(email,vemail)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }

if(email != vemail){
document.getElementById("ajax_confim_email2").innerHTML = "<img src='"+homeurl+"images/notvalid.png' alt='غير متطابق' />";
}
else{
document.getElementById("ajax_confim_email2").innerHTML = "<img src='"+homeurl+"images/valid.png' alt='متطابق' />";
}

} 

//=========Confirmation 2 password Input=============//
function verify_two_password(pass,vpass)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }

if(pass != vpass){
document.getElementById("ajax_confim_passowrd2").innerHTML = "<img src='"+homeurl+"images/notvalid.png' alt='غير متطابق' />";
}
else{
document.getElementById("ajax_confim_passowrd2").innerHTML = "<img src='"+homeurl+"images/valid.png' alt='متطابق' />";
}

} //=========Change Style=============//
function ChangeStyle(style_id) {
   window.location = 'login.php?action=changestyle&style_id=' + style_id;
   }

   //================Redirect Url=============//
function RedirectUrl(url, value, url2) {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
   window.location = url + value + url2;
}

/*==========Update Comments Ajax===========*/
function Comment_Paging(paging, article_id) {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
   document.getElementById('ajax_processing').style.display = 'block';
   var url = homeurl + "ajax.php";
   url = url + "?action=comments";
   url = url + "&page=" + paging;
   url = url + "&article_id=" + article_id;
   xmlHttp.onreadystatechange = update_comment_app;
   xmlHttp.open("GET", url, true);
   xmlHttp.send(null);
}
function update_comment_app() {
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
      document.getElementById("Update_comments_ajax").innerHTML = xmlHttp.responseText;
      document.getElementById('ajax_processing').style.display = 'none';
      }
}

//===========Redirect=============//
function Redirect(redirecturl){
var pausefor=10;

setTimeout(postaction(redirecturl),pausefor*1000);
}
function postaction(redirecturl){
if (window.timer){
clearInterval(timer)
clearInterval(timer_2)
}
window.location=redirecturl;
}

//===========Bookmark=============//
function addBookmark(title,url){
if(window.sidebar){
window.sidebar.addPanel(title,url,'')}
else if(document.all){
window.external.AddFavorite(url,title)}

}

//=========Hide and Show==========//
function HideShow(name,action){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 if(action == 'hide'){
document.getElementById(name).style.display = 'none';
}
else if(action == 'show'){
document.getElementById(name).style.display = '';
}
}

//========AdsCounter=========//
function AdsCounter(element){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
   $.get(homeurl + 'index.php', {action : 'adscounter', id : element});

}

//========Update Info Site=========//
function siteinfo(){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 document.getElementById('process').style.display = '';
 var url = document.getElementById('url');
 $.get(homeurl + 'addblog.php', {action : 'update', url: url.value}
   , function(result) {
      if (result == 0) {
         alert('خطأ!'); }
      else {
         $(result).appendTo(document.addblog_form.keyword.value);
		 document.getElementById('process').style.display = 'none';
		  }
      }
   );

}

//========Update Info Site=========//
function RssUpdate(url){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 document.getElementById('process').style.display = '';
 $.get(homeurl + 'blog.php', {action : 'updaterss', id: url}
   , function(result) {
      if (result == 0) {
         alert('خطأ!'); }
      else {
		 var options = {};
		 document.getElementById("rssupdate").innerHTML = result;
		 document.getElementById('process').style.display = 'none';
		 $("#rssupdate").show('blind',options,1000);
		  }
      }
   );

}

//========Favourite Blogs=========//
function UpdateFavour(id){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 $.get(homeurl + 'blog.php', {action : 'bookmark', id: id}
   , function(result) {
      if (result == 0) {
         alert('خطأ!'); }
      else {
		 var options = options = { to: "#MyBookmarkBrd", className: 'ui-effects-transfer' };
		 $("#favoutimg").hide('transfer',options,500);
		 $(result).appendTo("#MyBookmark");
		  }
      }
   );

}

//========Favourite Blogs=========//
function DelBook(id){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 $.get(homeurl + 'blog.php', {action : 'delbook', id: id}
   , function(result) {
      if (result == 0) {
         alert('خطأ!'); }
      else {
		 var options = options = {};
		 $("#favour_"+id).hide('pulsate',options,500);
		  }
      }
   );

}

//========Ajax Dialoge=========//
function ShowDialog(name){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 
 $("#"+name).dialog( 'destroy' );
 
$("#"+name).dialog({
			bgiframe: true,
			modal: true
});

}

//========Ajax Dialoge=========//
function RegenerateCaptcha(location){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
document.getElementById(location+"_regenerate_captcha").innerHTML = '<span width="100px">جاري اعادة توليد الكود</span>';
document.getElementById(location+"_regenerate_captcha").innerHTML = '<img src="'+homeurl+'/captcha.php?loc='+location+'&'+Math.random()+'" onclick="RegenerateCaptcha()" style="cursor:pointer" />';
}

//========Tabs Change=========//
function ShowTabs(index){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
document.getElementById('detailtabs-1').style.display = 'none';
document.getElementById('detailtabs-2').style.display = 'none';
document.getElementById('maintab-1').style.background = 'url('+homeurl+'/images/pat.gif) top center repeat-x #fff';
document.getElementById('maintab-2').style.background = 'url('+homeurl+'/images/pat.gif) top center repeat-x #fff';
document.getElementById('detailtabs-'+index).style.display = '';
document.getElementById('maintab-'+index).style.background = '#F0F0F0';
}