
var intLanguage = 1;
var objPageText = new Object;
var objEnglish = new Object;
var objSpanish = new Object;
var objFrench = new Object;

addEvent(window, 'load', initLanguage);    // add function to window.onload event

function initLanguage(){
        setLanguage();
        setLanguageText();
}

function setLanguage(){
        
    var objLngField = document.getElementById("Language");

    if(objLngField){
            
        intLanguage = parseInt(objLngField.value);
        
        switch(intLanguage){
            case 1:  objPageText = objEnglish; break;                
            case 2:     objPageText = objSpanish; break;
            case 3:     objPageText = objFrench; break;
            default: objPageText = objEnglish; break;
        }
        
        return objLngField.value;
                
    }
    
}

function setLanguageText(){
    
        objEnglish["1"] = "Email address format is incorrect";
        objEnglish["2"] = "The username contains invalid characters.";
        objEnglish["3"] = "The domain name contains invalid characters.";
        objEnglish["4"] = "The username does not seem to be valid.";
        objEnglish["5"] = "Destination IP address is invalid.";
        objEnglish["6"] = "The domain name does not seem to be valid.";
        objEnglish["7"] = "The address must end in a well-known domain or two letter country.";
        objEnglish["8"] = "This address is missing a hostname!";
        objEnglish["9"] = "Please enter your Username";
        objEnglish["10"] = "Please enter you Password";
        
        objSpanish["1"] = "El formato de dirección electrónico está incorrecto";
        objSpanish["2"] = "El nombre de usuario contiene caracteres no válidos.";
        objSpanish["3"] = "El nombre de usuario contiene caracteres no válidos.";
        objSpanish["4"] = "El nombre de usuario no parece ser válido.";
        objSpanish["5"] = "La destinación de dirección IP no es válida.";
        objSpanish["6"] = "El nombre de usuario no parece ser válido.";
        objSpanish["7"] = "La dirección debe terminar con un dominio conocido o en uno de un país de dos letras.";
        objSpanish["8"] = "A está dirección le falta un nombre de anfitrión.";
        objSpanish["9"] = "Por favor ingrese su nombre de usuario";
        objSpanish["10"] = "Por favor ingrese su contraseña";
        
        objFrench["1"] = "Le format d\'adresse de courriel est incorrect";
        objFrench["2"] = "Le nom d\'utilisateur contient des caractères non valides.";
        objFrench["3"] = "Le nom de domaine contient des caractères non valides.";
        objFrench["4"] = "Le nom d\'utilisateur ne semble pas valide.";
        objFrench["5"] = "L\'adresse IP de destination n\'est pas valide.";
        objFrench["6"] = "Le nom de domaine ne semble pas valide.";
        objFrench["7"] = "L\'adresse doit se terminer par un domaine connu ou un code de pays à deux lettres.";
        objFrench["8"] = "Cette adresse ne contient pas de nom d\'hôte!";
        objFrench["9"] = "Veuillez entrer votre nom d\'utilisateur";
        objFrench["10"] = "Veuillez entrer votre mot de passe";
}

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}



function emailFormatCheck (emailStr1) 
 {
 
  var checkTLD=1; // The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known TLD.  1 means check it, 0 means don't.
  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|travel|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ax|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$/; // The following is the list of known TLDs that an e-mail address must end with.
  var emailPat=/^(.+)@(.+)$/; // The following pattern is used to check if the entered e-mail address fits the user@domain format.  It also is used to separate the username from the domain.
  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; // The following string represents the pattern for matching all special characters.  We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ]
  var validChars="\[^\\s" + specialChars + "\]"; // The following string represents the range of characters allowed in a username or domainname.  It really states which chars aren't allowed.
  var quotedUser="(\"[^\"]*\")"; // The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com is a legal e-mail address.
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; // The following pattern applies for domains that are IP addresses, rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required.
  var atom=validChars + '+'; // The following string represents an atom (basically a series of non-special characters.) 
  var word="(" + atom + "|" + quotedUser + ")"; // The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string.
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); // The following pattern describes the structure of the user
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); // The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above.


  // Finally, let's start trying to figure out if the supplied address is valid. Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze.
  var matchArray=emailStr1.match(emailPat);

  if (matchArray==null) 
   {
    // Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address.
    alert(objPageText["1"]); 
    return false;
   }

  var user=matchArray[1];
  var domain=matchArray[2];

  // Start by checking that only basic ASCII characters are in the strings (0-127).
  for (i=0; i<user.length; i++) 
   {
   
    if (user.charCodeAt(i)>127) 
     {
      alert(objPageText["2"]); 
      return false;
     }
   }

  for (i=0; i<domain.length; i++) 
   {

    if (domain.charCodeAt(i)>127) 
     {
      alert(objPageText["3"]);  
      return false;
     }
   }

  // See if "user" is valid 
  if (user.match(userPat)==null) 
   {
    // user is not valid
    alert(objPageText["4"]);
    return false;
   }

  // if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid.
  var IPArray=domain.match(ipDomainPat);
  if (IPArray!=null) 
   {
    // this is an IP address
    for (var i=1;i<=4;i++) 
     {
     
      if (IPArray[i]>255) 
       {
        alert(objPageText["5"]); 
        return false;
       }
     }
    return true;
   }

  // Domain is symbolic name.  Check if it's valid.
  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;

  for (i=0;i<len;i++) 
   {
    
    if (domArr[i].search(atomPat)==-1) 
     {
      alert(objPageText["6"]); 
      return false;
     }
   }

  // domain name seems valid, but now make sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding  the domain or country.
  if (checkTLD && domArr[domArr.length-1].search(knownDomsPat)==-1) 
   {
    alert(objPageText["7"]); 
    return false;
   }

  // Make sure there's a host name preceding the domain.

  if (len<2) 
   {
    alert(objPageText["8"]); 
    return false;
   }

  // If we've gotten this far, everything's valid!
  return true;
 }

function NewWindow(vstrURL, vstrWindowName, vintWidth, vintHeight) 
 {
  var intLeft = (screen.width - vintWidth) / 2;
  var intTop = (screen.height - vintHeight) / 2;

  strWinProps = 'height=' + vintHeight + ',width=' + vintWidth + ',top=' + intTop + ',left=' + intLeft + ',scrollbars=yes,resizable'

  objWindow = window.open(vstrURL, vstrWindowName, strWinProps);
  objWindow.focus();

  return false;
 }

function ToggleBox(vobjCheckBox, vstrOther)
 {
  if (vstrOther.length == 0)
   {
    document.all[vobjCheckBox].checked = false;
   }
  else
   {
    document.all[vobjCheckBox].checked = true;
   }
 }

function ClearCBOS(vobjOSBox, vblnChecked)
 {
  if (vblnChecked == false)
   {
    if (eval(document.all[vobjOSBox]))
     {
      document.all[vobjOSBox].value = "";
     } 
   }
 }

function ToggleRadio(vobjRadio, vintRadioIndex, vstrOther)
 {
  var element
  
  element = document.getElementById(vobjRadio + '_A' + vintRadioIndex);

  if (vstrOther.length == 0)
   {
    element.checked = false;
   }
  else
   {
    element.checked = true;
   }
 }

function ClearRadioOS(vobjOSBox)
 {
  if (eval(document.all[vobjOSBox]))
   {
    document.all[vobjOSBox].value = "";
   } 
 }

function OpenPage(vstrPageURL)
 {
  document.getElementById('PageForm').action = vstrPageURL;
  document.getElementById('PageForm').submit();
 }

function OpenPage_Parent(vstrPageURL)
 {
  window.parent.document.getElementById('PageForm').action = vstrPageURL;
  window.parent.document.getElementById('PageForm').submit();
 }

function OpenContentPage(vstrPageURL)
 {
  document.getElementById('ContentForm').action = vstrPageURL;
  document.getElementById('ContentForm').submit();
 }


function ValidNumber(vstrValue)
 {

  if (isNaN(vstrValue) == true)
   {
    return false;
   }
  else
   {
       
    if (vstrValue.indexOf('.') > -1)
     {
      return false;
     }
    else
     {
      return true;
     } 
   } 
 }


function NumbersOnly()
{
   var key;
   key = window.event.keyCode;
   
   if (key < 48 || key > 57)
   {
      return false;
   }
   
   return true;
}


function SubmitLogin(vstrURL)
 {
  if (document.getElementById('Username').value.length == 0)
   {
    alert(objPageText["9"]);
   }
  else
   {
    if (document.getElementById('Password').value.length == 0)
     {
      alert(objPageText["10"]);
     }
    else
     {
      document.getElementById('PageForm').action = vstrURL;
      document.getElementById('PageForm').submit();
     }
   }   
 }

function SetField(vstrFieldID, vstrValue)
 {

  if ((document.getElementById(vstrFieldID).value.length == 0) || (vstrValue == ''))
   {
    document.getElementById(vstrFieldID).value = vstrValue;
   } 
 }
 
function FlashSurveys()
 {
   if (document.getElementById('Surveys'))
    {
     setInterval('StartFlash()', 500);
    }
   
   InitTicker();
   
 }
 
function StartFlash()
 {
    if (document.getElementById('Surveys').className == "FlashBox")
     {
      document.getElementById('Surveys').className = "PageBack";
     } 
    else
     {
      document.getElementById('Surveys').className = "FlashBox";
     } 
 }


/***************************************************************************

    Ticker that displays a string scrolling from right to left
    Aug 2005 Copyright Common Knowledge Inc
    
***************************************************************************/


 var ticker = new Object() 

function InitTicker()
 {

  ticker.obj = document.getElementById("ticker")  
  if(ticker.obj == null || ticker.obj == "undefined"){ return }    //   
  //ticker.content = "You have 100,000 surveys to take! Click here to get started!"
  ticker.speed = 1;    // pixels
  ticker.interval_time = 30; // milliseconds
  ticker.content_obj = document.getElementById("ticker_content")
  //ticker.content_obj.innerHTML = "<table cellpadding=0 cellspacing=0><tr><td nowrap>" + ticker.content + "</td></tr></table>"
  ticker.content_obj.width = ticker.content_obj.offsetWidth
  ticker.width = parseInt(ticker.obj.style.width)
  ticker.content_obj.style.left = ticker.width + "px"
  ticker.play = true
  PlayTicker()
    
 }

function PlayTicker()
 {

  if(ticker.play){
    
   var new_ticker_pos = parseInt(ticker.content_obj.style.left) - ticker.speed

   if(new_ticker_pos < (-1)*ticker.content_obj.width){    // end of content reached the left side

    ticker.content_obj.style.left = ticker.width + "px"    // loop ticker

   }else{

    ticker.content_obj.style.left = new_ticker_pos + "px"    // scroll ticker to the left

   }

   ticker.content_obj.style.visibility = "visible"

  }

  setTimeout(PlayTicker,ticker.interval_time)
    
 }

function StartTicker()
 {

  ticker.play=true

 }

function StopTicker()
 {

  ticker.play=false

 }
 