/* mcmclass.js */

/* ========================================= */
/* Function for Centering Elements:
/* ========================================= */

function AlignMiddle(Parent,Child) 
{ 
	
   //Generate content dynamically

   document.getElementById(Child).innerHTML="Hello there, I am dynamically align in the middle using a Javascript."
   //Center Vertically

   h = document.getElementById(Child).offsetHeight;
   //var a=Math.round(document.getElementById(Parent).style.pixelHeight/2);

   var a=Math.round(parseInt(document.getElementById(Parent).style.height)/2);
   var b=Math.round(h/2);
   var c=a-b;
   document.getElementById(Child).style.top=c+"px"; 
   //Center Horizontally

   w = document.getElementById(Child).offsetWidth; 
   //var x=Math.round(document.getElementById(Parent).style.pixelWidth/2);

   var x=Math.round(parseInt(document.getElementById(Parent).style.width)/2);
   var y=Math.round(w/2);
   var z=x-y;
   document.getElementById(Child).style.left=z+"px";
}

/* ========================================= */
/* Functions for showing/hiding Elements:
/* ========================================= */

function HideDiv(id)
{
	
	if(document.getElementById) // Safe for DOM3 browsers...
	{
		
		document.getElementById(id).style.display = 'none';
		
	}
	else
	{
		
		if(document.layers) // Safe for Netscape 4...
		{
			
			document.id.display = 'none';
			
		}
		else
		{
			
			// Must be IE4...
			
			document.all.id.style.display = 'none';
			
		}
		
	}
	
}

function ShowDiv(id)
{
	
	if(document.getElementById) // Safe for DOM3 browsers...
	{
		
		document.getElementById(id).style.display = '';
		
	}
	else
	{
		
		if(document.layers) // Safe for Netscape 4...
		{
			
			document.id.display = '';
			
		}
		else
		{
			
			// Must be IE4...
			
			document.all.id.style.display = '';
			
		}
		
	}
	
}

function ShowHide(id)
{
	
	if( document.getElementById(id).style.display = '' )
	{
		
		// Its showing...
		
		HideDiv(id);
		
	}
	else
	{

		if( document.getElementById(id).style.display = 'block' )
		{
		
		// Were not showing...
		
		ShowDiv(id);
		
		}
	}
	
}

function ShowLogin(id)
{
	
	document.getElementById('dimLayer').style.display='';
	document.getElementById('login_box').style.display='';
	
	return false;
	
}

function HideLogin(id)
{
	
	document.getElementById('dimLayer').style.display='none';
	document.getElementById('login_box').style.display='none';
	
	return false;
	
}

/* ========================================= */
/* From Validation Functions:
/* ========================================= */

   var Validator = new Object();
  
   Validator.Initialize = function(formId, fieldNum, submitId, validImage, invalidImage)
   {
    Validator.currentSelector = '';
    Validator.currentForm = formId;
    gebid(Validator.currentForm).reset();
    Validator.fieldNumValidated = 0;
    Validator.fieldNumToValidate = fieldNum;
    Validator.submitId = submitId;
    Validator.validImage = validImage;
    Validator.invalidImage = invalidImage;
   }
   Validator.Validate = function(selector, inputType)
   {
    this.currentSelector = selector;
    this.preload(selector);
    var isEmpty = true;
    switch(selector.type)
    {
     case 'undefined': break;
     case 'radio':
      for(var x=0; x < selector.length; x++)
      {
       if(selector[x].checked == true)
       {
        isEmpty = false;
       }
      }
      break;
     case 'select-multiple':
      for(var x=0; x < selector.length; x++)
      {
       if(selector[x].selected == true)
       {
        isEmpty = false;
       }
      }
      break;
     case 'checkbox':
      if(selector.checked)
      {
       isEmpty = false;
      }
      break;
     default:
      if(selector.value)
      {
       // safari 3.0 = 1024
       // IE 7.0 = 2147483647
       if(selector.maxLength > 0 && !(selector.maxLength == 1024) && !(selector.maxLength == 2147483647))
       {
        if(selector.value.length == selector.maxLength)
        {
         isEmpty = false;
        }
       }
       else
       {
        isEmpty = false;
       }
      }
      switch(inputType)
      {
       case 'email':
        this.validateEmail();
        return;
      }
    }
    if(isEmpty) this.invalid();
    else this.valid();
   }
   Validator.validateEmail = function()
   {
    var str = this.currentSelector.value;
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if (str.indexOf(at)==-1)
    {
     this.invalid();
     return false;
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    {
     this.invalid();
     return false;
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    {
     this.invalid();
     return false;
    }
    if (str.indexOf(at,(lat+1))!=-1)
    {
     this.invalid();
     return false;
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    {
     this.invalid();
     return false;
    }
    if (str.indexOf(dot,(lat+2))==-1)
    {
     this.invalid();
     return false;
    }
    if (str.indexOf(" ")!=-1)
    {
     this.invalid();
     return false;
    }
    this.valid();
   }
   Validator.valid = function()
   {
    rc(this.currentSelector.invalidImage);
    InsertAfter(this.currentSelector.parentNode, this.currentSelector.validImage, this.currentSelector);
    if(!this.currentSelector.isValid)
    {
     this.fieldNumValidated++;
    }
    if(Validator.AllFieldsValidated())
    {
     gebid(this.submitId).disabled = false;
    }
    this.currentSelector.isValid = true;
    this.currentSelector.validated = true;
   }
   Validator.invalid = function()
   {
    rc(this.currentSelector.validImage);
    InsertAfter(this.currentSelector.parentNode, this.currentSelector.invalidImage, this.currentSelector);
    if(this.currentSelector.isValid)
    {
     this.fieldNumValidated--;
    }
    gebid(this.submitId).disabled = true;
    this.currentSelector.isValid = false;
    this.currentSelector.validated = true;
   }
   Validator.preload = function(selector)
   {
    if(selector)
    {
     Validator.currentSelector = selector;  
     if(!Validator.currentSelector.validImage && !Validator.currentSelector.invalidImage)
     {
      Validator.currentSelector.validImage = ce('img', {src: Validator.validImage});
      Validator.currentSelector.invalidImage = ce('img', {src: Validator.invalidImage});
     }
     if(Validator.currentSelector.isValid == undefined)
     {
      Validator.currentSelector.isValid = false;
     }
    }
   }
   Validator.AllFieldsValidated = function(override)
   {
    if(this.fieldNumValidated >= this.fieldNumToValidate || override) return true;
    else return false;
   }