﻿//start base with Hamed Saati <hamed.saati@gmail.com>
function close_windows(){
	//hide_id('windows_1');
	Pos()
	DivDown()

}
function show_in_windows( this_page , this_parametr){
        document.getElementById('windows_1').style.display ='';
        my_div_mover(13 , 0 , 0 , 0 ,'windows_1');
        windows_loader( this_page , this_parametr )
}

function windows_loader(this_windows , this_parametr){
        main_ajax_do(this_windows , this_parametr , 'windows_3' );		
}
function get_value_for_ajax(this_id){
	if(! document.getElementById(this_id) ){
		return '';
	}else if(document.getElementById(this_id).type == 'checkbox'){
                return document.getElementById(this_id).checked;
	}else{
                return encodeURIComponent(replace_for_ajax(document.getElementById(this_id).value));
	}
}
function hide_id(id){
    if( document.getElementById(id) ){
	document.getElementById(id).style.display ='none';
	}
}
function show_id(id){
    if( document.getElementById(id) ){
    document.getElementById(id).style.display ='';
	}
}
function write_in_id(id,note){
 if( document.getElementById(id) ){
  show_id(id);
 document.getElementById(id).innerHTML=note;
 }
}

function loading_effect(k){
	ht = document.getElementsByTagName("html");
	if(k==1){
                ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";	
	        ht[0].style.cursor = 'wait';
	}else{
                ht[0].style.filter = "";
	       ht[0].style.cursor = 'auto';
	}
}
function replace_for_ajax(note){
	note= note.replace(/&/g,"**am**");
	note= note.replace(/=/g,"**mosavi**");
	note= note.replace(/\+/g,"**jam**");
	return note;
}
function main_ajax_do( url , post , thisid){
 var xmlhttp=false;
         show_id(thisid)
        write_in_id(thisid ,'<img src="theme/image/Sloading2.gif" border="0"> لطفا چند لحظه صبر کنيد ... ') ;
       
		loading_effect(1);
         /*@cc_on @*/
        /*@if (@_jscript_version >= 5)
                try {
                        xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
                } 
                catch (e) {
                        try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } 
		catch (E) { 
                        xmlhttp = false; 
                }
    }
    @end @*/
    if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); }
	xmlhttp.open('POST', url, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	post=post+'&my_time='+escape(new Date().getTime());
        xmlhttp.send(post); 
        xmlhttp.onreadystatechange = function() {
                   if(xmlhttp.readyState == 4  && xmlhttp.status == 200){
                        document.getElementById(thisid).innerHTML =xmlhttp.responseText;
                        loading_effect(0);
                }
                    
        }
               
}


var DivY= 500;
var DivY0 = DivY/6;
var PoseActive=0;
var DoDown=0;
var DownTime;

function my_div_mover( my_y , go_down , down_time , move_down  , go_up_id_old ){
go_up_id=go_up_id_old;
newleft=document.body.clientWidth/2 - parseInt(document.getElementById(go_up_id).style.width)/2;
document.getElementById(go_up_id).style.top = "0px";//Py;
document.getElementById(go_up_id).style.left = newleft+"px";
	DivY = document.body.clientHeight+1500;	//Start position of Div
    DivY0 = DivY/my_y;						//end position
	PoseActive = move_down;						//move width scroll
	DoDown = go_down;							//Down after
	DownTime = down_time;					//Down time 
	Pos();
	DivUp();
	document.getElementById(go_up_id).style.display="";
}

function Pos()
{
	if (window.innerHeight)
	{
		  pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		  pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		  pos = document.body.scrollTop
	}
	if (PoseActive)
	{
		document.getElementById(go_up_id).style.top = DivY + pos+"px";
		temp = setTimeout('Pos()',300);
	}
}

function DivUp()
{
	if (Math.abs(DivY- DivY0)>.1){
		DivY = (DivY0 - DivY) * .2  + DivY;
		document.getElementById(go_up_id).style.top = DivY + pos+"px";
		setTimeout("DivUp()", 50);
	}
	else
	{
		if(DoDown) setTimeout("DivDown()", DownTime);	
		else PoseActive = 0;
	}
}
function DivDown()
{
	if ((document.body.clientHeight - DivY)>0){
		DivY = (DivY - DivY0) * .2  + DivY;
		document.getElementById(go_up_id).style.top = DivY + pos+"px";
		setTimeout("DivDown()", 30);
	}
	else
	{
		document.getElementById(go_up_id).style.display="none";
		PoseActive = 0;
	}

}