var root_path='';
var reply_obj=new Object;
var temp_form_data=new Object;
var return_by_ajax="";
var change_height_dir="";




//---- display server reply
function show_server_reply(msg,height){
	if(height=="small") h =100;
	else if(height=="big") h=550;
	else h=height;
	Shadowbox.open({
        player:     'html',
        title:      '<p style="width:100%;text-align:center;" ><b> نتيجة الطلب </b></p> ',
        content:	'<p style="width:100%;text-align:center;" >'+msg+'</p> ',
        height:     h,
        width:      700,
		options:   {modal: false,viewportPadding:5,handleOversize:'none'}
    }
	);
}

//---- show shadow box loading 
function show_loading(msg){
	Shadowbox.open({
        player:     'html',
        title:      '<p style="width:100%;text-align:center;" ><b> الاتصال مع السرفر </b></p> ',
        content:	'<p style="width:400px;height:30px;text-align:center; margin:20px;" >'+msg+'</p><p style="width:400px;height:30px;text-align:center; margin:20px;" > <br/><img src="'+root_path+'/images/ajax-loader.gif" /></p>',
        height:     140,
        width:      440,
		options:   {modal: false,viewportPadding:5,handleOversize:'none'}
    });
}



function check_browser(){
	if(/firefox/.test( navigator.userAgent.toLowerCase() )) return "firefox";
	else if(/msie 6.0/.test( navigator.userAgent.toLowerCase() )) return "ie6";
	else if(/msie 7.0/.test( navigator.userAgent.toLowerCase() )) return "ie7";
	else if(/msie 8.0/.test( navigator.userAgent.toLowerCase() )) return "ie8";
	else if(/msie/.test( navigator.userAgent.toLowerCase() )) return "ie";
	else if(/chrome/.test( navigator.userAgent.toLowerCase() )) return "chrome";
	else if(/safari/.test( navigator.userAgent.toLowerCase() )) return "safari";
	else return  "unknown";
}
var _browser=check_browser();
//alert(_browser);

function shadowboxclose(){
	setTimeout("Shadowbox.close()", 1000)
}

function freeze(s){
	if(s==0)document.getElementById("fog").style.display="none";
	else{
		document.getElementById("fog").style.display="block";
		document.getElementById("fog").style.height=parseInt(document.getElementById("main_body").scrollHeight);
	}
}

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }




function status_msg(msg,color,load_img)	{
	var bar=document.getElementById("status_bar");
	var this_msg='<div style="width:744px;text-align:right;';
	if(load_img)this_msg+='background-position:left;background-repeat:no-repeat;background-image:url('+root_path+'images/ajax-loader.gif)';
	this_msg+='">'+msg+' </div>';
	bar.innerHTML=this_msg;
	bar.style.color=color;
}

function hide_form_div(){
	hide_items_div('forms_items');
	setTimeout(function(){document.getElementById('forms_items_body').innerHTML="";}, 200);
}

// hide items div  of its parent div 
function hide_items_div(divid)	{
	var div_id=document.getElementById(divid);
	var div_id_body=document.getElementById(divid+"_body");
	if(div_id.style.display!="none"){
		div_id=document.getElementById(divid);
		div_id_body=document.getElementById(divid+"_body");
		var divh= parseInt(div_id_body.scrollHeight);
		div_id.style.height=divh;
		div_id_body.style.display="none";
		change_height_dir="hide";
		change_height(divid,divh,1,"hide");
		//setTimeout("change_height('"+divid+"',"+divh+",1,'hide')", 66);
	}
}

// show items div  of its parent div 
function show_items_div(divid){
	var div_id=document.getElementById(divid);
	var div_id_body=document.getElementById(divid+"_body");
	if(div_id.style.display=="none"){
		div_id.style.display="block";
		div_id_body.style.display="block";
		var divh= parseInt(div_id_body.scrollHeight);
		div_id_body.style.display="none";
		change_height_dir="show";
		change_height(divid,1,divh,"show");		
		//setTimeout("change_height('"+divid+"',1,"+divh+",'show')", 66);
	}
}

// change div height smoothly 
function change_height(id,hfrom,hto,show_hide){
	//var c_time= new Date;
	//last_change_height_time=c_time.getTime();
	var div_id=document.getElementById(id);
	var curr=hfrom;
	if(show_hide == "show"){
		if(curr == hto ||change_height_dir=="hide"){ 
			div_id.style.height="";//hto;
			document.getElementById(id+"_body").style.display="block";
			change_height_dir="";
			return;
		}
		else{
			//curr=curr+10;
			//if(curr<1)curr=1;
			curr=Math.ceil(curr*1.1)+1;
			if(curr>hto)curr=hto;
			div_id.style.height = curr +"px";
			setTimeout("change_height('"+id+"',"+curr+","+hto+",'"+show_hide+"')", 33);
		}
	}
	else if(show_hide == "hide"){
		if(curr  == hto || change_height_dir=="show"){ 
			div_id.style.height="";//hto;
			document.getElementById(id).style.display="none";
			change_height_dir="";
			return;
		}
		else{
			//curr=curr-10;
			curr=Math.round(curr/1.1)-1;
			if(curr<hto)curr=hto;
			div_id.style.height = curr +"px";
			setTimeout("change_height('"+id+"',"+curr+","+hto+",'"+show_hide+"')", 33);
		}
	}
}

function body_width(scale){
	if(scale == "bigger"&& body_size == "small" )	change_body_width(529,780,scale);
	else if(scale == "smaller" && body_size == "big")	change_body_width(780,529,scale);
}

// change main_body div width smoothly 
function change_body_width(wfrom,wto,scale){
	div_id=document.getElementById("body_menu");
	curr=wfrom;
	if(scale == "bigger" ){
		if(curr == wto){ 
			div_id.style.width=wto+"px";
			body_size = "big";
			return;
		}
		else{
			curr=curr+10;
			if(curr>wto)curr=wto;
			div_id.style.width = curr +"px";
			setTimeout("change_body_width("+curr+","+wto+",'"+scale+"')", 3);
		}
	}
	else if(scale == "smaller" ){
		if(curr  == wto){ 
			div_id.style.width=wto+"px";
			body_size = "small";
			return;

		}
		else{
			curr=curr-10;
			if(curr<wto)curr=wto;
			div_id.style.width = curr+"px";
			setTimeout("change_body_width("+curr+","+wto+",'"+scale+"')", 3);
		}
	}
}

function div_fade(obj_id,i){
	if(!i)i=100;
	i=i-5;
	if(i<1) i=0;
	var o = document.getElementById(obj_id);
	o.style.filter = "Alpha(Opacity=" + i + ")"; //for IE   
	o.style.opacity = i/100; //for FF
	if(i > 1) setTimeout("div_fade('"+obj_id+"',"+i+")",10);
	else document.body.removeChild(document.getElementById("loading-mask"));
	//window.setInterval(change,10);
}

function hide_form_show_page(){
	show_items_div("main_area");
	hide_items_div("forms_items");
	run_order_page();
	//msg="اضغط على اى من الطلبات التالية لعرض تفاصيله او استخدم التصفح بين الطلبات لاستعراض باقى الطلبات";
	//status_msg(msg,"green");
}


function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end function var_dump

// get_java by php
function get_java(){
	var headID = document.getElementsByTagName("head")[0];         
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = 'ajax_java.php';
	headID.appendChild(newScript);
}

// logout
function log_out(){
	window.location="?task=logout";	
}

function IncludeJavaScript(jsFile)
	{
	document.write('<script type="text/javascript" src="'+ jsFile + '"></scr' + 'ipt>'); 
}

//IncludeJavaScript('secondJS.js');


