//time zone
var now = new Date()
var offset = (-1)*now.getTimezoneOffset();
set_cookie_years("LocalTimeZone",offset);

function MM_findObj(n, d) { //v4.01 
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
if(!x && d.getElementById) x=d.getElementById(n); return x; 
} 
function MM_swapImage() { //v3.0 
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) 
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

} 
function MM_swapImgRestore() { //v3.0 
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; 
} 

function MM_preloadImages() { //v3.0 
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); 
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) 
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} 
} 

function myEmail(emailUser, emailHost, emailDomain, linkText, content) {
    
    var address = emailUser + "@" + emailHost + "." + emailDomain;
    var display = address;
    
    if (linkText != null && linkText != "") { display = linkText; }
    
    if (content != null && content != "") { address = address + content; }
    
    document.write("<a href='mailto:" + address + "'>" + display + "</a>");
}


function clearUsernamePrompt( usernameID,value) 
{
    var username = document.getElementById(usernameID);  
    if (username.value == value) 
    {  
        if(username.value==value)
            username.value = "";    
    } 
}  

// Set the prompt for the username field, if required.  
function setUsernamePrompt(usernameID,value) 
{    
var username = document.getElementById(usernameID);  
if (username.value == "") {      username.value = value;    }  
}  

// Clear prompt from password field, if required.  
function clearPasswordPrompt(passwordID) 
{    
  var password = document.getElementById(passwordID); 
  if(password){   
      password.style.display = "inline";    
      password.focus();    
  }
  var passwordPrompt = document.getElementById("passwordPrompt");    
  if(passwordPrompt)
    passwordPrompt.style.display = "none";  
}  
// Set the prompt for the password field, if required.  
function setPasswordPrompt(passwordID) 
{    
  var password = document.getElementById(passwordID);    
  if(password)
  {
      if (password.value == "") {      
          password.style.display = "none";      
          var passwordPrompt = document.getElementById("passwordPrompt");      
          if(passwordPrompt)
            passwordPrompt.style.display = "inline";    
      }  
  }
}

function IdiomTypeSelected(categorySelID,typeSelID,IdiomSelectIndex)
{
  var typeSel = document.getElementById(typeSelID);    
  if(typeSel==null)
    return;
   
  var categorySel = document.getElementById(categorySelID);    
  if(categorySel)
  {
      if(typeSel.selectedIndex==IdiomSelectIndex)
      {
          if (categorySel.selectedIndex > 0) {      
                categorySel.selectedIndex=0;
          }
      }  
  }
}

function CategorySelected(categorySelID,typeSelID,IdiomSelectIndex)
{
  var typeSel = document.getElementById(typeSelID);    
  if(typeSel==null)
    return;
   
  var categorySel = document.getElementById(categorySelID);    
  if(categorySel)
  {
      if(typeSel.selectedIndex==IdiomSelectIndex)
      {
        typeSel.selectedIndex=0;
      }  
  }
}

// JavaScript Document

function toggle_display(faq_id, e_id, c_id)
{
	faq_id = document.getElementById(faq_id);        /*   topic id    */
	e_id = document.getElementById(e_id);            /*   'expand' id    */
	c_id = document.getElementById(c_id);         /*    'collapes' id     */
	if (faq_id.style.display == 'block')         /*   if the content is displayed    */
	{
		faq_id.style.display = 'none';         /*    hide the content    */
		e_id.style.display = 'inline';       /*   display 'Expand'   */
		c_id.style.display = 'none';		/*   hide 'Collapes'    */
	} else                                   /*   if the content is hidden    */
	{
		faq_id.style.display = 'block';        /*   display the content    */
		e_id.style.display = 'none';           /*   hide 'expand'   */
		c_id.style.display = 'inline';          /*   display 'Collapes'    */
	};
}


function do_other_things(number)
{
	for (i = 1; i < number; i++)
	{
		faq = 'faq' + i;
		expand = 'expand' + i;
		collapes = 'collapes' + i;
		document.getElementById(faq).style.display = 'none';                 //     hide contents of OTHER topics     
		document.getElementById(expand).style.display = 'inline';           //     Display 'Expand' of all OTHER topics
		document.getElementById(collapes).style.display = 'none';        //    hide 'Collaps' of all OTHER topics
	}
	for (i = number + 1; i <= 9; i++)
	{
		faq = 'faq' + i;
		expand = 'expand' + i;
		collapes = 'collapes' + i;
		document.getElementById(faq).style.display = 'none';              //     hide contents of OTHER topics   
		document.getElementById(expand).style.display = 'inline';          //     Display 'Expand' of all OTHER topics
		document.getElementById(collapes).style.display = 'none';        //    hide 'Collaps' of all OTHER topics
	}
}

function toggleChallengeLayer(number) {

    var id = 'challenge' + number;
    var section = document.getElementById(id);
    
    if(section.style.display=="none") {
        section.style.display="block";
    } else {
        section.style.display="none";
    }
    
    var expand = 'expand' + number;
    var expandSpan = document.getElementById(expand);
    
    if(expandSpan.style.display=="none") {
        expandSpan.style.display="inline";
    } else {
        expandSpan.style.display="none";
    }
    
    var collapse = 'collapse' + number;
    var collapseSpan = document.getElementById(collapse);
    
    if(collapseSpan.style.display=="none") {
        collapseSpan.style.display="inline";
    } else {
        collapseSpan.style.display="none";
    }
    
    collapseOtherLayers(number);
}

function collapseOtherLayers(number) {

    for (i = 1; i <= 4; i++)
    {
        layer = 'challenge' + i;
        expand = 'expand' + i;
        collapse = 'collapse' + i;
        
        if (i != number) {
            document.getElementById(layer).style.display = "none";
            document.getElementById(expand).style.display="inline";
            document.getElementById(collapse).style.display="none";
        }
    }
}

/*------- Cookie ----------*/

function set_cookie_years (name, value)
{
    var current_date = new Date ( );  // current date & time
    var cookie_year = current_date.getFullYear ( ) + 5;
    var cookie_month = current_date.getMonth ( );
    var cookie_day = current_date.getDate ( );
    set_cookie ( name, value, cookie_year, cookie_month, cookie_day );	
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
/*------- Cookie ----------*/

/* misc. */

function AdjustMainStoryImage($imageID)
 {
  var img = document.getElementById($imageID);
  var imageWidth = img.width;
  if (imageWidth < 250)
   {
    var div = document.getElementById('divMainStoryImage');
    div.style.width = imageWidth + 'px';
   }
  else
   {
     if (imageWidth > 280)
      {
       img.style.width= 250 + 'px' ;
      }
   }
 }
