var _before_fade_height;
var main_fade_screen_id='_fade_screen_parent';
function openFadeScreen(contantID)
{
	if(contantID)
	{
		var obj=document.getElementById(contantID)	
	}
	else
	{
		var obj=document.getElementsByTagName('body')
		var obj=obj[0]	
	}

	_before_fade_height=obj.offsetHeight;
	
	obj.style.height=browserH()+'px';
	obj.style.position='relative';
	obj.style.overflow='hidden';
	document.getElementById(main_fade_screen_id).style.display='block';
}

function closeFadeScreen(contantID)
{
	if(contantID)
	{
		var obj=document.getElementById(contantID)	
	}
	else
	{
		var obj=document.getElementsByTagName('body')
		var obj=obj[0]	
	}
	obj.style.height=_before_fade_height+'px';
	obj.style.overflow='visible';
	document.getElementById(main_fade_screen_id).style.display='none';
	document.getElementById(main_fade_screen_id+'_contant').innerHTML='';
}


function createFadeScreen(id,bgcolor)
{
	var obj=document.getElementsByTagName('body')
	var obj=obj[0]	
	var top='<div style="position:absolute;left:0px;top:0px;right:0px;bottom:0px;height:100%;width:100%;z-index:49;background:'+bgcolor+';filter:alpha(opacity=85);-moz-opacity:.85;" align="center"> </div><div style="position:absolute;left:0px;top:100%;right:0px;bottom:0px;height:30%;width:100%;z-index:49;background:#000000;filter:alpha(opacity=85);-moz-opacity:.85;" align="center"></div><div style="position:absolute;left:0px;top:0px;right:0px;bottom:0px;height:100%;width:100%;z-index:50;" align="center"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" ><tr><td width="100%" height="100%" align="center" valign="middle" id="'+id+'_contant">'
	var bottom='</td></tr></table></div>';
	
	var fade_screen=document.createElement('div');
	fade_screen.setAttribute("id",id);
	fade_screen.style.position='absolute';
	fade_screen.style.zIndex='100';
	fade_screen.style.height='100%';
	fade_screen.style.height='100%';
	fade_screen.style.top='0px';
	fade_screen.style.bottom='0px';
	fade_screen.style.left='0px';
	fade_screen.style.right='0px';
	fade_screen.style.display='none';
	fade_screen.innerHTML=top+bottom
	obj.insertBefore(fade_screen,obj.firstChild);
	main_fade_screen_id=id;
}

function browserH() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
function serverSendRecieveInfo(target_url,poststr,return_target_pos,oncom_function)
{
	
	
	var connectionerror='';

	//----------------------------------------------
	//Creating connection request
	//----------------------------------------------
	var xmlhttp = false;
	if (window.XMLHttpRequest) 
	{ 
		xmlhttp = new XMLHttpRequest();if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/html'); 
	} 
	else if (window.ActiveXObject) 
	{ 
		 try 
		 {
			  if (!(xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")))alert(connectionerror)
			  
		 } 
		 catch (e) 
		 {
			 try 
			 {
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			 } catch (e) {alert(connectionerror)}
		 }
	}
	
	//----------------------------------------------
	//Comunicating
	//----------------------------------------------
	
	 
	 xmlhttp.open('POST', target_url, true);
	 xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	 xmlhttp.setRequestHeader("Content-length", poststr.length);
	 xmlhttp.setRequestHeader("Connection", "close");
	 xmlhttp.send(poststr);
	 xmlhttp.onreadystatechange = function()
	 {
		 if (xmlhttp.readyState == 4) 
		 {
				//alert(xmlhttp.status)
				if (xmlhttp.status == 200) 
				{
					result = xmlhttp.responseText; 
					var jscode = "";
					var parts = result.match(/<script[^>]*>(.|\n|\t|\r)*?<\/script>/gi);
					if(parts){
						for(i=0;i<parts.length;i++){
							jscode += parts[i].replace(/<script[^>]*>|<\/script>/gi, "");
							result = result.replace(parts[i], "");
						}
					}						
					if(return_target_pos)
					{
						//alert('POST');
						if(document.getElementById(return_target_pos))
						document.getElementById(return_target_pos).innerHTML=result
						
					}
					if(jscode != "")
					{
						var incomingScript = document.createElement('SCRIPT');
						incomingScript.type = 'text/javascript'; 
						incomingScript.lang = 'javascript';
						incomingScript.defer = true;
						incomingScript.text = jscode;
						document.getElementsByTagName('head')[0].appendChild(incomingScript);
					}	
					//alert(document.getElementsByTagName('head')[0].innerHTML);
					if(oncom_function)
						oncom_function(result);
					
					xmlhttp=false;
				} 
				else
				{
					//alert('An error have been occured while communicating with server, Please try again');
				}
			}
	 };
}

