var xmlHttp=createXMLHttpRequest();
function createXMLHttpRequest(){
	var xmlHttp ; 
	try {
		xmlHttp=new XMLHttpRequest() ;
	}catch(e){
	try{
		xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
		
	}catch(e){}
	}
		if (!xmlHttp)
		alert("Couldn't Create XmlHttpRequest Object") ;    	
		else
		return xmlHttp ; 

}


function insert_comment(fid){
	var alert_area_=document.getElementById('alert_area');
	var name_=document.getElementById('name');
	var email_=document.getElementById('email');
	var comment_title_=document.getElementById('comment_title');
	var comment_=document.getElementById('comment_text');
	var country_=document.getElementById('country');
	var verification_=document.getElementById('verification');
	var params='action=insert_comment&name='+name_.value+'&email='+email_.value+'&comment_title='+comment_title_.value+'&comment='+comment_.value+'&country='+country_.value+'&verification='+verification_+'&fileid='+fid ;
	if (xmlHttp){
	xmlHttp.open("POST","comments.php",true) ; 
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==1){
			alert_area_.innerHTML='<img src="images/loading.gif" alt="loading" align="center" class="icon" style="margin-bottom:10px;"/>';
		}else if (xmlHttp.readyState==4){
			if (xmlHttp.status==200){
			var response_=xmlHttp.responseText; 
			alert_area_.innerHTML=response_;
			if (response_=='تمت إضافة التعليق'){
				document.getElementById('send_button').disabled='disabled';
				name_.disabled='disabled';
				email_.disabled='disabled';
				comment_title_.disabled='disabled';
				comment_.disabled='disabled';
				country_.disabled='disabled';
			}
			}
		
		}
	}
	   
   }

	xmlHttp.send(params);
	
}

function send_file(theid){
	var alert_area_=document.getElementById('alert_area');
	var your_name_=document.getElementById('your_name');
	var your_email_=document.getElementById('your_email');
	var friend_name_=document.getElementById('friend_name');
	var friend_email_=document.getElementById('friend_email');
	var comment_=document.getElementById('comment_text');
	var params='action=send_file&your_name='+your_name_.value+'&your_email='+your_email_.value+'&friend_name='+friend_name_.value+'&friend_email='+friend_email_.value+'&comment='+comment_.value ;
	
	if (xmlHttp){
	xmlHttp.open("POST","send.php?id="+theid,true) ; 
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==1){
			alert_area_.innerHTML='<img src="images/loading.gif" alt="loading" align="center" class="icon" style="margin-bottom:10px;"/>';
		}else if (xmlHttp.readyState==4){
			if (xmlHttp.status==200){
			var response_=xmlHttp.responseText; 
			alert_area_.innerHTML=response_;	
			if (response_=='تم إرسال المقال إلي صديقك'){
				document.getElementById('send_button').disabled='disabled';
				your_name_.disabled='disabled';
				your_email_.disabled='disabled';
				friend_name_.disabled='disabled';
				comment_.disabled='disabled';
			}
			}
		
		}
	}
	   
   }

	xmlHttp.send(params);
	
}

function contact(){
	var alert_area_=document.getElementById('alert_area');
	var name_=document.getElementById('name');
	var email_=document.getElementById('email');
	var subject_=document.getElementById('subject');
	var messege_=document.getElementById('messege');
	var params='action=contact&name='+name_.value+'&email='+email_.value+'&subject='+subject_.value+'&messege='+messege_.value;
	if (xmlHttp){
	xmlHttp.open("POST","contact.php?",true) ; 
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==1){
			alert_area_.innerHTML='<img src="images/loading.gif" alt="loading" align="center" class="icon"  style="margin-bottom:10px;"/>';
		}else if (xmlHttp.readyState==4){
			if (xmlHttp.status==200){
			var response_=xmlHttp.responseText; 
			alert_area_.innerHTML=response_;
			if (response_=='تم الإرسال وسيتم الرد عليك قريبا'){
				document.getElementById('send_button').disabled='disabled';
				name_.disabled='disabled';
				email_.disabled='disabled';
				subject_.disabled='disabled';
				messege_.disabled='disabled';
			}
			}
		
		}
	}
	   
   }

	xmlHttp.send(params);
	
}

function report(){
	var alert_area_=document.getElementById('alert_area');
	var name_=document.getElementById('name');
	var email_=document.getElementById('email');
	var messege_=document.getElementById('messege');
	var params='do=report&name='+name_.value+'&email='+email_.value+'&messege='+messege_.value;
	if (xmlHttp){
	xmlHttp.open("POST","support.php?action=report",true) ; 
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==1){
			alert_area_.innerHTML='<img src="images/loading.gif" alt="loading" align="center" class="icon"  style="margin-bottom:10px;"/>';
		}else if (xmlHttp.readyState==4){
			if (xmlHttp.status==200){
			var response_=xmlHttp.responseText; 
			alert_area_.innerHTML=response_;
			if (response_=='تم التبليغ عن المشكلة وسيتم الرد عليك قريبا'){
				document.getElementById('send_button').disabled='disabled';
				name_.disabled='disabled';
				email_.disabled='disabled';
				messege_.disabled='disabled';
			}
			}
		
		}
	}
	   
   }

	xmlHttp.send(params);
	
}

function send_request(theid){
	var alert_area_=document.getElementById('alert_area');
	var name_=document.getElementById('name');
	var company_=document.getElementById('company');
	var email_=document.getElementById('email');
	var phone_=document.getElementById('phone');
	var request_type_=document.getElementById('request_type');
	var properties_=document.getElementById('properties');
	var notes_=document.getElementById('notes');
	var params='action=send_request&name='+name_.value+'&company='+company_.value+'&email='+email_.value+'&phone='+phone_.value+'&request_type='+request_type_.value+'&notes='+notes_.value+'&properties='+properties_.value ;
	
	if (xmlHttp){
	xmlHttp.open("POST","request.php?id="+theid,true) ; 
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==1){
			alert_area_.innerHTML='<img src="images/loading.gif" alt="loading" align="center" class="icon" style="margin-bottom:10px;"/>';
		}else if (xmlHttp.readyState==4){
			if (xmlHttp.status==200){
			var response_=xmlHttp.responseText; 
			alert_area_.innerHTML=response_;	
			if (response_=='تم إرسال الطلب وسيتم الرد عليك قريباً'){
				document.getElementById('send_button').disabled='disabled';
				name_.disabled='disabled';
				company_.disabled='disabled';
				email_.disabled='disabled';
				phone_.disabled='disabled';
				request_type_.disabled='disabled';
				properties_.disabled='disabled';
				phone_.disabled='disabled';
				notes_.disabled='disabled';
			}
			}
		
		}
	}
	   
   }
	xmlHttp.send(params);
}

function move(dir,theid,prefix,order){
	var params='action=move&dir='+dir+'&id='+theid;
	if (xmlHttp){
	xmlHttp.open("POST","test.php",true) ; 
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==1){
		//	alert_area_.innerHTML='<img src="images/loading.gif" alt="loading" align="center" class="icon" style="margin-bottom:10px;"/>';
		}else if (xmlHttp.readyState==4){
			if (xmlHttp.status==200){
				var response=xmlHttp=responseText;
				alert(response);
				if(dir=="up"){
					moveUp(prefix,order);
				}else{
					moveDown(prefix,order);
				}
			
			}
		
		}
	}
	   
   }
	xmlHttp.send(params);
}

function moveUp(prefix,theid){
	var higherId=prefix+(theid-1);
	var thisId=prefix+theid;
	try{
		higherContents=document.getElementById(higherId).innerHTML;
		thisContents  =document.getElementById(thisId).innerHTML;
		document.getElementById(higherId).innerHTML=thisContents;
		document.getElementById(thisId).innerHTML=higherContents;
	}catch(e){}
}
function moveDown(prefix,theid){
	var lowerId=prefix+(theid+1);
	var thisId=prefix+theid;
	try{
		lowerContents=document.getElementById(lowerId).innerHTML;
		thisContents  =document.getElementById(thisId).innerHTML;
		document.getElementById(lowerId).innerHTML=thisContents;
		document.getElementById(thisId).innerHTML=lowerContents;
	}catch(e){}
}