function check_mail( TheForm ) 
 { 
  txt=document.forms[TheForm].email.value; 
  
  if ( txt.indexOf( "." ) == -1 ) 
   { 
     alert("Wrong E-Mail Address"); 
     return false; 
   } 
 
  dog = txt.indexOf( "@" ); 
  if ( dog == -1 ) 
   { 
     alert( "Wrong E-Mail Address" ); 
     return false; 
   } 
 
  if ( ( dog < 1 ) || ( dog > txt.length - 5 ) ) 
   { 
     alert("Wrong E-Mail Address"); 
     return false;  
   } 
 
  if ( ( txt.charAt( dog - 1 ) == '.' ) || ( txt.charAt( dog + 1 ) == '.' ) ) 
   { 
     alert("Wrong E-Mail Address"); 
     return false; 
   } 
 } 

function CheckPassword( flag )
 { 
   if( eval( form + 'password' + attrib ) == '' )
    {
       alert( 'Please enter your password' );
       return false; 
    }
   else if( eval( form + 'password' + attrib ) < 6 )
    {
       alert( 'Password length has to be from 6 to 20 characters' );
       return false; 
    }

   if( flag == 2 )
    {
      if( eval( form + 'c_password' + attrib ) == '' )
       {
         alert( 'Please enter the password confirmation' );
         return false; 
       }
      else if( eval( form + 'c_password' + attrib ) < 6 )
       {
         alert( 'Password length has to be from 6 to 20 characters' );
         return false; 
       }
      else if( eval( form + 'password' + attrib ) != eval( form + 'c_password' + attrib ) )
       {
         alert( 'Password and password confirmation do not match' );
         return false;
       }  
    }
   return true;
 }

function check_data( flag )
 {
   form = "register_user.";
   attrib = ".value.length";

   if( eval( form + 'username' + attrib ) == '' && eval( form + 'password' + attrib ) == '' && eval( form + 'c_password' + attrib ) == '' && eval( form + 'fname' + attrib ) == '' && eval( form + 'lname' + attrib ) == '' && eval( form + 'email' + attrib ) == '' )
    {
       alert( 'Please fill all the required fields' );
       return false; 
    }
   else if( eval( form + 'username' + attrib ) == '' )
    {
       alert( 'Please enter your username' );
       return false; 
    }
   else if( CheckPassword( flag ) == false )
    {
      return false;
    }
   else if( eval( form + 'fname' + attrib ) == '' )
    {
       alert( 'Please enter your Name' );
       return false; 
    }
   else if( eval( form + 'lname' + attrib ) == '' )
    {
       alert( 'Please enter your Last Name' );
       return false; 
    }
  else if( eval( form + 'email' + attrib ) == '' )
    {
       alert( 'Please enter your E-Mail address' );
       return false; 
    }
   else if( check_mail('register_user') == false )
    {
       return false;
    } 
   else if( eval( form + 'country' + attrib ) == '' )
    {
       alert( 'Please select your country' );
       return false; 
    }
   else
    {
       return true;
    }
 }

function checked( the_form, do_check )
 {
		var elts  = document.forms[the_form].elements['item[]'];
		for( var i = 0; i < elts.length; i++ )
		 {
         if( elts[i].disabled != true ) 
					{
						elts[i].checked = do_check;
					}
		 }
 }

function optionMoveUp(select)
{
	(document.getElementById) ? obj = document.getElementById(select) : obj = select;

  if (obj.selectedIndex > 0)
  {
    var arrIndex = new Array(obj.length);
    
    for (var i = 0 ; i < obj.options.length; i++)
    {      
      if (obj.options[i].selected)
      {
        arrIndex[i] = i;
        obj.options[i].selected = false;        
      }
    }
    
    for (i = 1 ; i < obj.options.length; i++)
    {      
      if (arrIndex[i] != null)
      {
        Text = obj.options[i - 1].text;
        Value = obj.options[i - 1].value;
				Class = obj.options[i - 1].className;
        
        obj.options[i - 1].text = obj.options[i].text;
        obj.options[i - 1].value = obj.options[i].value;
        obj.options[i - 1].className = obj.options[i].className;
        obj.options[i - 1].selected = true;
        
        obj.options[i].text = Text;
        obj.options[i].value = Value;        
        obj.options[i].className = Class;        
      }
    }                              
  }
}

function optionMoveDown(select)
{
	(document.getElementById) ? obj = document.getElementById(select) : obj = select;

  if  ((obj.selectedIndex != -1) && (!obj.options[obj.options.length - 1].selected))
  {
    var arrIndex = new Array(obj.length);
    
    for (var i = 0 ; i < obj.options.length; i++)
    {      
      if (obj.options[i].selected)
      {                    
        arrIndex[i] = i;
        obj.options[i].selected = false;        
      }
    }    
      
    for (i = obj.options.length - 2; i >= 0; i--)
    {      
      if (arrIndex[i] != null)
      {
        Text = obj.options[i + 1].text;
        Value = obj.options[i + 1].value;
        Class = obj.options[i + 1].className;
        
        obj.options[i + 1].text = obj.options[i].text;
        obj.options[i + 1].value = obj.options[i].value;
        obj.options[i + 1].selected = true;
        obj.options[i + 1].className = obj.options[i].className;
        
        obj.options[i].text = Text;
        obj.options[i].value = Value;      
        obj.options[i].className = Class;      
      }
    }                                
  }
} 

function optionAllDelete(selectFrom)
{  
	(document.getElementById) ?	obj = document.getElementById(selectFrom) : obj = selectFrom;

  for (var i = obj.length - 1; i >= 0; i--)
   {
     obj.options[i] = null;
   }
}

function selectToString(selectFrom, alignCount)
{  
  for (i = 0; i <= ( document.getElementById(selectFrom).length - 1 ); i++)
	 {    
	    document.set_order.value_order.value += document.getElementById(selectFrom).options[i].value;
	    document.set_order.value_order.value += ";";  
   }          
	for( i = 0; i <= ( alignCount - 1 ); i++ )
	 {
 		  document.set_order.value_align.value += document.getElementById('algn_'+i).value;
   		document.set_order.value_align.value += ";";  
	 }
}