//fixed function
var xmlHttp;
var homeurl = 'http://www.arabicmotors.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 ChangeValue(val,element)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
if(val == 0){
document.getElementById(element).value = 1;
}
else{
document.getElementById(element).value = 0;
}

}
 
function getEmail()
{
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 news = document.getElementById('news');
var gallery = document.getElementById('gallery');
var video = document.getElementById('video');
var newcar = document.getElementById('new');
var future = document.getElementById('future');
var used = document.getElementById('used');

var url = homeurl+"email.php";
url=url+"?action=reg";
url=url+"&email="+email.value;
url=url+"&news="+news.value+"&gallery="+gallery.value+"&video="+video.value+"&newcar="+newcar.value+"&future="+future.value+"&used="+used.value;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangede;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChangede() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("emailst").
 innerHTML=xmlHttp.responseText;
 } 
}

//===========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(target) {
   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 + target + '.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, type) {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
   var url = homeurl + 'article.php?action=report&type=' + type + '&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;
}
//=========Last News ajax=============//
var t;
function UpdateLastNews(index) {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
   var tbl = 'uns' + index;
   var tbl2 = 'pnu' + index;
   if(index == 3) {
      var tbl3 = '2su0';
      }
   else {
      index = index + 1;
      var tbl3 = '2su' + index;
      }
   var selectedEffect = '';
   var options = {
      };
   $("#" + tbl).show(selectedEffect, options, 0);
   $("#" + tbl2).show(selectedEffect, options, 0);
   $("#" + tbl3).show(selectedEffect, options, 0);
   if(tbl != 'uns0') {
      document.getElementById('uns0').style.display = 'none';
      document.getElementById('pnu0').style.display = 'none';
      document.getElementById('2su1').style.display = 'none';
      }
   if(tbl != 'uns1') {
      document.getElementById('uns1').style.display = 'none';
      document.getElementById('pnu1').style.display = 'none';
      document.getElementById('2su2').style.display = 'none';
      }
   if(tbl != 'uns2') {
      document.getElementById('uns2').style.display = 'none';
      document.getElementById('pnu2').style.display = 'none';
      document.getElementById('2su3').style.display = 'none';
      }
   if(tbl != 'uns3') {
      document.getElementById('uns3').style.display = 'none';
      document.getElementById('pnu3').style.display = 'none';
      document.getElementById('2su0').style.display = 'none';
      }
}

function AutoPlay(index) {
   if(index == 0) {
      UpdateLastNews(0);
      t = setTimeout ( "AutoPlay(1)", 2000 );
      }
   else if(index == 1) {
      UpdateLastNews(1);
      t = setTimeout ( "AutoPlay(2)", 2000 );
      }
   else if(index == 2) {
      UpdateLastNews(2);
      t = setTimeout ( "AutoPlay(3)", 2000 );
      }
   else if(index == 3) {
      UpdateLastNews(3);
	  t = setTimeout ( "AutoPlay(0)", 2000 );
      }
   }
//================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, target) {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
   document.getElementById('ajax_processing').style.display = 'block';
   var url = homeurl + target + ".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';
      }
   }
//==========Select All=========//
function SelectAll(id) {
   document.getElementById(id).focus();
   document.getElementById(id).select();
   }
//==========Slid Show in new car=========//
function slidshow(element,loop) {
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
      for(var i=0;i<loop;i++){
          document.getElementById('slid_'+i).style.display = 'none';
      }
	  if(element == 'video'){
	    document.getElementById('slid_photo').style.display = 'none';
		document.getElementById('slid_video').style.display = '';
		return;
	  }
      document.getElementById('slid_video').style.display = 'none';
      document.getElementById('slid_photo').style.display = '';
      document.getElementById('slid_'+element).style.display = '';
} 
function moveslide(dir,max,num){
   xmlHttp = GetXmlHttpObject();if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request"); return }
if(dir == 'next'){
document.getElementById("previous").innerHTML = "<p class=next_button onclick=javascript:moveslide('pre',"+max+","+(num-1)+")>السابق&gt;&gt;</p>";
SlidEffectHide('move_'+(num-1),'move_'+num,'next');
if(num+1 >= max){
document.getElementById("next").innerHTML = "<p class=next_button_disable>&lt;&lt;التالي</p>";
}else{
document.getElementById("next").innerHTML = "<p class=next_button onclick=javascript:moveslide('next',"+max+","+(num+1)+")>&lt;&lt;التالي</p>";
}
}
else{
SlidEffectHide('move_'+(num+1),'move_'+num,'pre');
if(num == 0){
document.getElementById("previous").innerHTML = "<p class=next_button_disable>السابق&gt;&gt;</p>";
}else{
document.getElementById("previous").innerHTML = "<p class=next_button onclick=javascript:moveslide('pre',"+max+","+(num-1)+")>السابق&gt;&gt;</p>";
}
document.getElementById("next").innerHTML = "<p class=next_button onclick=javascript:moveslide('next',"+max+","+(num+1)+")>&lt;&lt;التالي</p>";
}


}
function SlidEffectHide(hide,show,direction){
		var selectedEffect = 'slide';
		if(direction == 'pre'){
		var options = {direction: 'right'};}
		else{
		var options = {};}
		
		$("#"+hide).hide(selectedEffect,options,1000,slid_callback(show,direction));
}

function slid_callback(show,direction){
	setTimeout(function(){
	var selectedEffect = 'slide';
	if(direction == 'pre'){
	       var options = {direction: 'left'};}
	else{
	      var options = {direction: 'right'};}
	$("#"+show).show(selectedEffect,options,1000);}, 1500);
};

//==========Change Tab==============//
function ChangeTab(loop,tabid){
for (var x = 1; x <=loop; x++)
   {
document.getElementById("Tab_"+x).style.display = 'none';
document.getElementById("stab_"+x).style.color = '#990000';
   }
document.getElementById("Tab_"+tabid).style.display = '';
document.getElementById("stab_"+tabid).style.color = '#FF7F7F';
}

//==========Change Tab In Compare==============//
function ChangeTabComp(tb,loop,tabid){
for (var x = 1; x <=loop; x++)
   {
document.getElementById("Tab"+tb+"_"+x).style.display = 'none';
document.getElementById("stab"+tb+"_"+x).style.color = '#990000';
   }
document.getElementById("Tab"+tb+"_"+tabid).style.display = '';
document.getElementById("stab"+tb+"_"+tabid).style.color = '#FF7F7F';
}


//==========Search In New Car=========//
function Search()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
  var cname = document.getElementById('model_of_newcar');
  var year = document.searchmm.model_Year.value;

document.getElementById("search_result").innerHTML = "<center><img src='"+homeurl+"images/ajax-loader.gif' alt='processing' /></center>"; 

var url = homeurl+"new-car.php";
url=url+"?action=search";
url=url+"&mname="+cname.value;
url=url+"&year="+year;
xmlHttp.onreadystatechange=Search_update;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function Search_update() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("search_result").
 innerHTML=xmlHttp.responseText;
 } 
}

//==========Open Adver in used=========//
function OpenAdver(id)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 
 if(document.getElementById("tab_"+id).style.display == 'block'){
document.getElementById("tab_"+id).style.display = 'none';
return;
}
else{
document.getElementById("tab_"+id).style.display = 'block';
}
 
document.getElementById("tab_"+id).innerHTML = "<center><img src='"+homeurl+"images/ajax-loader.gif' alt='processing' /></center>";

$.get(homeurl+'used.php?action=open', {id : id}, function(result) {
         document.getElementById("tab_"+id).innerHTML = result;} );

}

//===========Home Tab Change=============//
function show_home(index)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return
 }

if(index == 1){
document.getElementById("tab_v_1").style.display = 'none';
document.getElementById("tab_v_2").style.display = 'block';
document.getElementById("tab_p_1").style.display = 'none';
document.getElementById("tab_p_2").style.display = 'block';
document.getElementById("video_home").style.display = 'none';
document.getElementById("photo_home").style.display = 'block';
}

else if(index == 2){
document.getElementById("tab_v_1").style.display = 'block';
document.getElementById("tab_v_2").style.display = 'none';
document.getElementById("tab_p_1").style.display = 'block';
document.getElementById("tab_p_2").style.display = 'none';
document.getElementById("video_home").style.display = 'block';
document.getElementById("photo_home").style.display = 'none';
}

}

//===========Update Model In Home Page=============//
function GetModelHome(cname)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
document.getElementById("model_new_car").innerHTML = "<img src='"+homeurl+"images/progressbar2.gif' alt='processing' />";

var url = homeurl+"index.php";
url=url+"?action=updatem";
url=url+"&cname="+cname;
xmlHttp.onreadystatechange=model_update_home;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function model_update_home() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("model_new_car").
 innerHTML=xmlHttp.responseText;
 } 
}

//===========Redirect Search=============//
function RedirectSearch(section)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }

var search = document.getElementById('srting_se'); 

window.location = homeurl+'search/'+section+'_'+search.value+'.html';

}

//===========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;
}

//===========DELETE Compare Model=============//
function DelComp(loop){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var elem;
var counteffect = 0;
for(var i=1;i<=loop;i++){
          if(document.getElementById('compdel_'+i).checked == true){
		     document.getElementById('compdel_'+i).checked = false;
			 elem = document.getElementById('compdel_'+i).value;
			 $.get(homeurl+'new-car.php?action=delete', {id : elem});
		     $('#comp_'+elem).hide('highlight',500);
			 counteffect++;
		 }
    }
	if(counteffect == loop){$('#nullchs').show('highlight',500);}
	if(counteffect == 0){alert('يجب على الاقل اختيار عنصر واحد لحذفه من القائمه');}
}

//===========DELETE Compare Model=============//
function loginInput(elm){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
if(elm.value == ''){
if(elm.name == 'user'){elm.value = 'اسم الدخول';}
else{elm.type='text';
elm.value = 'كلمة المرور';}
}
}

function Inputclear(elm){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 
if(elm.value == 'اسم الدخول'){
elm.value = '';}
else if(elm.value == 'كلمة المرور'){
elm.value = '';
elm.type = 'password'}
}

//===========Bookmark=============//
function addBookmark(title,url){
if(window.sidebar){
window.sidebar.addPanel(title,url,'')}
else if(document.all){
window.external.AddFavorite(url,title)}

}

//========Regenerate Captcha=========//
function RegenerateCaptcha(){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 document.getElementById("regenerate_captcha").innerHTML = '<img src="'+homeurl+'/images/progressbar1.gif" width="100px" height="35px" />';
document.getElementById("regenerate_captcha").innerHTML = '<img src="'+homeurl+'/captcha.php?'+Math.random()+'" onclick="RegenerateCaptcha()" style="cursor:pointer" />';
}