// JavaScript Document
var group=0;
function sndReqAC(i,k)
{   
    j=group;
	if (j==0){
		
	document.getElementById('link0').className='browseactive';
	document.getElementById('link1').className='browse';
	document.getElementById('link2').className='browse';
		}
	if (j==1){
		
	document.getElementById('link0').className='browse';
	document.getElementById('link1').className='browseactive';
	document.getElementById('link2').className='browse';
		}
	if (j==2){
		
	document.getElementById('link0').className='browse';
	document.getElementById('link1').className='browse';
	document.getElementById('link2').className='browseactive';
		}		
	document.getElementById("content").innerHTML="<div id='waitmsg'>انتظر قليلا.......</div>";
    http.open('get', 'pros.php?i='+i+'&j='+j);
   	http.onreadystatechange = handleResponseAC;
    http.send(null);
}
function handleResponseAC() {
	if(http.readyState == 4){
    	var response = http.responseText;
	  	document.getElementById("content").innerHTML=response;
		
    }

}


function sndReqad(action) {
	document.getElementById("content").innerHTML="<div id='waitmsg'>انتظر قليلا.......</div>";
    http.open('get', 'processadd.php?action='+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
//================adv detail========================
function sndreqaddetail(id,cat,i)
 {  
	if (document.getElementById('detail'+i).innerHTML=='')
	{
	document.getElementById('pic'+i).src='../images/blue_uf.gif';
    
	document.getElementById('detail'+i).innerHTML=" <div  ><img src='../images/wait.gif' /></div>";
	
	http.open('get', 'advdetail.php?id='+id+'&cat='+cat+'&i='+i);
    http.onreadystatechange = handleResponseaddetail;
    http.send(null);
	}else
	{
	document.getElementById('detail'+i).innerHTML='';
	document.getElementById('pic'+i).src='../images/blue_f.gif';
	}
	
	
}
function handleResponseaddetail() 
{
	if(http.readyState == 4)
	{	
	    
        var response = http.responseText;
	    var arr = new Array();
		var arr=response.split('||');
			
		document.getElementById(arr[1]).innerHTML=arr[0];
	
		
    }
}
//================area ===================
function sndReqarea(areaid) 
{
	 document.getElementById("areaidDiv").innerHTML='<select><option>تحميل...</option></select>';
	http.open('get','../processarea.php?areaid='+areaid);
    http.onreadystatechange = handleResponsearea;
	http.setRequestHeader('X_REQUESTED_WITH','XMLHttpRequest');
    http.send(null);
}
//=======================end area==========
//==========================for areas======================Tarek===
function handleResponsearea() {
	if(http.readyState == 4){
        var response = http.responseText;
	//	alert(response);
	    document.getElementById("areaidDiv").innerHTML='<select id="areaid" name="areas"><option value="0">اختر واحدة</option>'+response+'</select><div id="aError" class="error"></div>';
		
    }

}
//=================end for area===================================
function  sndReqrpas(cP,pass)
{
http.open('get', 'pass.php?c='+cP+'&p='+pass);
http.onreadystatechange = handleResponsepass;
http.send(null);
}
//==================show kind in list===================tareq
function handleResponsepass()
{
	if(http.readyState == 4){
    var response = http.responseText;
	
		document.getElementById("conpasswordmsg").innerHTML=response;
		
    }
}


function sndold(pass)
{
http.open('get', 'oldpass.php?p='+pass);
http.onreadystatechange = handleResponseoldpass;
http.send(null);
}
//==================show kind in list===================tareq
function handleResponseoldpass()
{
	if(http.readyState == 4){
    var response = http.responseText;
	
		document.getElementById("oldpasswordmsg").innerHTML=response;
		
    }
}
function showaccats()
{
	var catstr=''; 	

    catstr+="<span style='display:inline;color:#c10000'>الفئات الرئيسية :</span>";
	
	for(i in catarr)
	{  
	
	    catstr+="<a href='javascript:sndReqAC("+i+")'>"+catarr[i]+"</a>";
	}
	

	document.getElementById('menu').innerHTML=catstr;
}


function showcatinsel()
	{
		document.getElementById('cat').options.length = 0;
		document.getElementById('cat').options[0] = new Option("الرجاء اختيار الفئة","");
		document.getElementById('cat').options[1] = new Option("العقارات","0");	
		document.getElementById('cat').options[2] = new Option("المحركات","1");
		document.getElementById('cat').options[3] = new Option("فرص عمل","2");
		document.getElementById('cat').options[4] = new Option("تكنولوجيا","3");
		document.getElementById('cat').options[5] = new Option("متفرقات","4");
	}
//===================end
//==================show kind in list===================tareq
	function selectOption(num,s)
{
	var selObj = document.getElementById(s);
	selObj.selectedIndex = num;
}
///=====================
function sndNum(ss,t)
{
    http.open('get','isnum.php?s='+ss);
   if (t=='s'){
   http.onreadystatechange = handleResponsenums;
   http.send(null);
	
}
else if(t=='p')
{
   http.onreadystatechange = handleResponsenump;
    http.send(null);
	
}
}
function handleResponsenums()
{
	if(http.readyState == 4){
    var response = http.responseText;
	document.getElementById('sizemsg').innerHTML=response;
		
    }
}
function handleResponsenump()
{
	if(http.readyState == 4){
    var response = http.responseText;
	document.getElementById('pricmsg').innerHTML=response;
		
    }
}


function showpartsa(index)
{	
	document.getElementById("parts").options.length = 0;
	document.getElementById("parts").options[0] = new Option("الكل","0");
	for(j in partarr[index])
	{
		document.getElementById("parts").options[j] = new Option(partarr[index][j],j);
	}
	
}

function sndDate(bd,bm,by,ed,em,ey)
{
http.open('get','date.php?bd='+bd+'&bm='+bm+'&by='+by+'&ed='+ed+'&em='+em+'&ey='+ey);
http.onreadystatechange = handleResponsedate;
http.send(null);
}

function handleResponsedate()
{
	if(http.readyState == 4){
    var response = http.responseText;
	document.getElementById('expdate').innerHTML=response;
		
    }
}


//=================================notnull
function sndN(s,n,m)
{

http.open('get','checker.php?c='+s+'&type='+n);
if(m=='nan'){
http.onreadystatechange = handleResponsenanotnull;
http.send(null);
}
else if(m=='p'){
http.onreadystatechange = handleResponsepasnn;
http.send(null);
}
else if(m=='adrs'){
http.onreadystatechange = handleResponseadresnotnull;
http.send(null);
}

else if(m=='cont'){
http.onreadystatechange = handleResponsecontenttnull;
http.send(null);
}


}
function handleResponsenanotnull()
{      
         if(http.readyState == 4)
	     {
         var response = http.responseText;
	document.getElementById('nammsg').innerHTML=response;
	     }
	
}


function handleResponsepasnn()
{      
         if(http.readyState == 4)
	     {
         var response = http.responseText;
		 document.getElementById('passwordmsg').innerHTML=response;
	     }
	
}

function handleResponseadresnotnull()
{      
         if(http.readyState == 4)
	     {
         var response = http.responseText;
		 document.getElementById('addressmsg').innerHTML=response;
	     }
	
}

 
function handleResponsecontenttnull()
{      
         if(http.readyState == 4)
	     {
         var response = http.responseText;
		 document.getElementById('contentmsg').innerHTML=response;
	     }
	
}
//===============================

//=============================emailvaledaion		

function sndEmail(s,n)
{
document.getElementById('emailmsg').src='../images/wait.gif';
http.open('get','checker.php?c='+s+'&type='+n);
http.onreadystatechange = handleResponseemail;
http.send(null);

}
function handleResponseemail()
{
	if(http.readyState == 4)
	{
    var response = http.responseText;
	document.getElementById('emailmsg').innerHTML=response;
		
    }
}



///=================valedate


function validate0()
{
var tables; 
 gErrors=0 ;
tables = document.getElementsByTagName( 'td' )
  if(document.getElementById('city').value !="" && document.getElementById('content').value !="" && document.getElementById('size').value !="" && document.getElementById('address').value !="")
  {
	for (i=0; i<tables.length; i++)//loop through all the <td> elements 
	{
		// if the class name of that td element is rules check to see if there are error warnings
		if (tables[i].className == "rules")
		{
			//if there is a thank you or its blank then it passes
			if ( tables[i].innerHTML !="" )
			{
	            gErrors = gErrors + 1; //the error count increases by 1
			}
		}
	}
	
 }else {alert ( 'الرجاء ملئ الحقول');    return false;} 
	if (gErrors > 0)
	{ alert ( 'الرجاء ملئ الحقول');
	
		return false;
	}
	else return true;

}

function validate1()
{
var tables; 
 gErrors=0 ;
tables = document.getElementsByTagName( 'td' )
  if((document.getElementById('content').value != "")&&(document.getElementById('city').value != ""))
  {
	for (i=0; i<tables.length; i++)//loop through all the <td> elements 
	{
		// if the class name of that td element is rules check to see if there are error warnings
		if (tables[i].className == "rules")
		{
			//if there is a thank you or its blank then it passes
		if ( tables[i].innerHTML !="" )
			{
	            gErrors = gErrors + 1; //the error count increases by 1
			}
		}
	}
	
 }else {alert ( 'الرجاء ملئ الحقول');    return false;} 
	if (gErrors > 0)
	{ alert ( 'الرجاالتاكد من ملئ الحقول');
	
		return false;
	}
	else return true;

}



function validateMod0()
{
var tables; 
gErrors=0 ;

tables = document.getElementsByTagName( 'td' );
  if((document.getElementById('size').value == "") &&(document.getElementById('content').value == "") &&(document.getElementById('address').value == "" ))
  { alert ( 'الرجاء ملئ الحقول');    return false;
		}
	
else {  for (i=0; i<tables.length; i++)//loop through all the <td> elements 
	{
		// if the class name of that td element is rules check to see if there are error warnings
		if (tables[i].className == "rules")
		{
			//if there is a thank you or its blank then it passes
			if ( tables[i].innerHTML !="" )
			{
	            gErrors = gErrors + 1; //the error count increases by 1
			}
		} }
} 
	if (gErrors > 0)
	{ alert ( 'الرجاء ملئ الحقول');
	
		return false;
	}
	else return true;

}

function validateMod1()
{
var tables; 
gErrors=0 ;

tables = document.getElementsByTagName( 'td' );
  if((document.getElementById('content').value == ""))
  { alert ( 'الرجاء ملئ الحقول');    return false;
		}
	
else {  for (i=0; i<tables.length; i++)//loop through all the <td> elements 
	{
		// if the class name of that td element is rules check to see if there are error warnings
		if (tables[i].className == "rules")
		{
			//if there is a thank you or its blank then it passes
			if ( tables[i].innerHTML !="" )
			{
	            gErrors = gErrors + 1; //the error count increases by 1
			}
		} }
} 
	if (gErrors > 0)
	{ alert ( 'الرجاء ملئ الحقول');
	
		return false;
	}
	else return true;

}
function validateOldPass()
{
var tables; 
 gErrors=0 ;
tables = document.getElementsByTagName( 'td' )
  if((document.getElementById('oldpass').value != "") && (document.getElementById('password').value != "") && document.getElementById('conpassword').value != "")
  {
	for (i=0; i<tables.length; i++)//loop through all the <td> elements 
	{
		// if the class name of that td element is rules check to see if there are error warnings
		if (tables[i].className == "rules")
		{
			//if there is a thank you or its blank then it passes
			if ( tables[i].innerHTML !=""   )
			{
	            gErrors = gErrors + 1; //the error count increases by 1
			}
		}
	}
	
 }else {alert ( 'الرجاء ملئ الحقول');    return false;} 
	if (gErrors > 0)
	{ alert ( 'الرجاء ملئ الحقول');
	
		return false;
	}
	else return true;

}

