// JavaScript Document
/******************  Function start  *****************/

  function open_url(url)
   {
    New_Window = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=yes,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
    New_Window.focus();
   }

/******************  Function  End   *****************/
/******************  Function start  *****************/

  function open_window(file_name,width,height,timeout)
	{
	 var left = (screen.width/2) - width/2;
     var top = (screen.height/2) - height/2;
     //
	 var win_style="";
     win_style+="channelmode = no";
     win_style+=",directories = yes";
     win_style+=",fullscreen = no";
     //
	 win_style+=",height = "+height;
     win_style+=",left = "+left;
     //
	 win_style+=",location = no";
     win_style+=",menubar = no";
     win_style+=",resizable = no";
     win_style+=",scrollbars = no";
     win_style+=",status = no";
     win_style+=",titlebar = no";
     win_style+=",toolbar = no";
     //
	 win_style+=",top = "+top;
     win_style+=",width = "+width;
     //
	 new_win=window.open(file_name,"_blank",win_style,"true");
	 //
	 new_win.focus();
	 
     if(timeout > 0) setTimeout('new_win.close();',timeout);
	 
	 //clearTimeout();
	 //setTimeout('id_win.close();',timeout);
	 //setTimeout('id_win.close(); window.location.reload();',timeout);
	 //return "" ; 
	}

/******************  Function  End   *****************/
/******************  Function start  *****************/

   function captcha_code()
    {
	 var Alpha_Number =
           new Array ('A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','2','3','4','5','6','7','8','9');
     var code="";
	 for(var i = 1; i <= 5; i++) { code+=Alpha_Number[Math.floor(Math.random()*Alpha_Number.length)]; }
	 document.getElementById('secure_id').src = "/p_d_t/pdt_gnr/captcha.php?code="+code ;
	 document.getElementById('code_str').value = code ;
    }

/******************  Function  End   *****************/
/******************  Function start  *****************/

  function Set_Selected_Index(id,options_text)
   {
    var options_length=document.getElementById(id).length;
    for (var i = 0; i < options_length ; i++) 
     {
      if(document.getElementById(id).options[i].text==options_text)
       {
        document.getElementById(id).selectedIndex = i;
        break ;
       }
     }
   }

/******************  Function  End   *****************/
/******************  Function start  *****************/

  function Set_Selected_Index_value(id,options_value)
   {
    var options_length=document.getElementById(id).length;
    for (var i = 0; i < options_length ; i++) 
     {
      if(document.getElementById(id).options[i].value==options_value)
       {
        document.getElementById(id).selectedIndex = i;
        break ;
       }
     }
   }

/******************  Function  End   *****************/
/******************  Function start  *****************/

function convert_number(id)
 {
  id.value=Merge_String_To_Number(id.value);
  id.value=Make_3_3_Number(id.value);
  return id.value;
 }


/******************  Function  End   *****************/
/******************  Function start  *****************/

function Merge_String_To_Number(value)
 {
  var new_value="";
  for (var i = 0; i < value.length; i++) if ( (value.charAt(i) >= '0') && (value.charAt(i) <= '9') ) new_value+=value.charAt(i);
  return new_value;
 }

/******************  Function  End   *****************/
/******************  Function start  *****************/

function Make_3_3_Number(value)
 {
  value=value.split("").reverse().join("");
  var new_value="";
  for (var i = 0; i < value.length; i++) 
   {
    new_value+=value.charAt(i);
    if ( (i+1)%3 == 0 && i < value.length-1) new_value+=',';
   }
  new_value=new_value.split("").reverse().join("");
  return new_value;
 }


/******************  Function  End   *****************/
/******************  Function start  *****************/

 function Float_Div(id,x_pos,y_pos,start_it)
  {
   //added by M.SH
   // x_pos => left  middle right 
   // y_pos => top  middle bottom 
   var id_width=document.getElementById(id).style.width;
   var id_height=document.getElementById(id).style.height;
   
   id_width=id_width.replace( 'px', '' );
   id_height=id_height.replace( 'px', '' );
   
   var x_p=0;
   var y_p=0;
   //
   var window_width ;
   var window_height ;
   
   if( typeof( window.innerWidth ) == 'number' ) 
   { 
    //Non-IE 
    window_width = window.innerWidth;
    window_height = window.innerHeight; 
   } 
   else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
   { 
    //IE 6+ in 'standards compliant mode' 
    window_width = document.documentElement.clientWidth; 
    window_height = document.documentElement.clientHeight; 
   } 
   else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
   { 
    //IE 4 compatible 
    window_width = document.body.clientWidth; 
    window_height = document.body.clientHeight; 
   }
   //
   if(x_pos=='left') x_p=0 ;
   if(x_pos=='middle') x_p=(window_width/2)-(id_width/2);
   if(x_pos=='right') x_p=(window_width)-(id_width)-10;
   //
   if(y_pos=='top') y_p=0 ;
   if(y_pos=='middle') y_p=(window_height/2)-(id_height/2);
   if(y_pos=='bottom') y_p=(window_height)-(id_height)-10;
   //
   var Scroll_Left_Pos = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ;
   var Scroll_Top_Pos = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ;
   //
   var Div_Left_Pos = document.getElementById(id).offsetLeft;
   var Div_Top_Pos = document.getElementById(id).offsetTop;
   //
   if( Div_Left_Pos > Scroll_Left_Pos+x_p+100 || Div_Left_Pos < Scroll_Left_Pos+x_p-100 
	   || Div_Top_Pos > Scroll_Top_Pos+y_p+100 || Div_Top_Pos < Scroll_Top_Pos+y_p-100
	   || start_it=='0' )
    {
     document.getElementById(id).style.left = x_p+Scroll_Left_Pos + 'px' ;
     document.getElementById(id).style.top = y_p+Scroll_Top_Pos + 'px' ;
	}
   setTimeout("Float_Div('"+id+"','"+x_pos+"','"+y_pos+"','1');",500);
  }

 function Hide_Div(id)
  {
   document.getElementById(id).style.visibility="hidden";
  }

/******************  Function  End   *****************/
/******************  Function start  *****************/

 function show_menu_div_main(id,menu)
  {
   var div_left=(document.getElementById(id).offsetParent.offsetLeft)+(document.getElementById(id).offsetLeft)-
          (document.getElementById(menu).offsetWidth)+document.getElementById(id).offsetWidth;
   var div_top=document.getElementById(id).offsetParent.offsetTop+document.getElementById(id).offsetTop+30;
   //
   div_left+=3; // cellspacing="3"
   div_top+=3; // cellspacing="3"
   //
   document.getElementById(menu).style.left=div_left+'px';
   document.getElementById(menu).style.top=div_top+'px';
   document.getElementById(menu).style.visibility = 'visible';
  }

/******************  Function  End   *****************/
/******************  Function start  *****************/

function check_email(e_mail)
{

 e_mail=e_mail.toLowerCase();
 
 var email_length=e_mail.length ;	
 
 if(email_length < 7  || email_length > 50)
  {
   alert("نشانی ایمیل کوتاه‌تر و یا بلندتر از از حد مجاز است");
   return false;
  }

 // check for www. in given email
 if(e_mail.charAt(0)=='w' && e_mail.charAt(1)=='w' && e_mail.charAt(2)=='w' && e_mail.charAt(3)=='.')
  {
   alert("ابتدای ایمیل نباید \n www. \n داشته باشد \n به نمونه زیر توجه کنید \n aaa@bbb.ccc") ;
   return false ;
  }

 // check for blank spaces in given email
 if(e_mail.indexOf(' ')!=-1)
  {
   alert("فاصله خالی بین نشانی ایمیل وجود دارد") ;
   return false ;
  }

 // check for '@' in email 
 if(e_mail.indexOf('@')==-1)
  {
   alert("ایمیل فاقد نشانه‌های لازم است \n به نمونه زیر توجه کنید \n aaa@bbb.ccc") ;
   return false ;
  }

 // check for '.' in email
 if(e_mail.indexOf('.')==-1)
  {
   alert("ایمیل فاقد نشانه‌های لازم است \n به نمونه زیر توجه کنید \n aaa@bbb.ccc") ;
   return false ;
  }
	
 // check if '@' is used more than one times in given email
 var j=0 ;
 for(var i=0 ; i < email_length ; i++) 
  {
   if(e_mail.charAt(i) == '@') j++;
  }
 
 if(j > 1)
  {  
   alert("نشانی ایمیل اشتباه است \n به نمونه زیر توجه کنید \n aaa@bbb.ccc") ;
   return false ;
  }

}

/******************  Function  End   *****************/
/******************  Function start  *****************/


