function textCounter(field, maxlimit) 
{
  if (field.value.length > maxlimit) // if too long...trim it!
  field.value = field.value.substring(0, maxlimit);
}

function newWin(url_path, win_width, win_height, win_name, win_scroll)
{
  newWindow =
    window.open(url_path,win_name,config="resizable=no,scrollbars="+
    win_scroll+",screenX=50,screenY=50,left=50,top=50,width="+
    win_width+",height="+win_height)
  newWindow.focus();
}

function doLogin()
{

  if (location.hostname == 'www.thinkquest.org'){
    document.login.action = 'https://'+location.hostname+'/pls/html/tq.web_login';
  }
  else{
    document.login.action = 'http://'+location.hostname+':'+location.port+'/pls/html/tq.web_login';
  }
  
  document.login.submit();
}

function newRWin(url_path, win_width, win_height, win_name, win_scroll)
{
  if (win_scroll == ''){
    win_scroll = 'no';
  }
  newWindow =
    window.open(url_path,win_name,config="resizable=yes,scrollbars="+
    win_scroll+",screenX=50,screenY=50,left=50,top=50,width="+
    win_width+",height="+win_height)
  newWindow.focus();
}


function moveFromList(fromList, toList)
{
    for (i=0; i < fromList.length; i++)
    {
        if (fromList.options[i].selected)
        {
            found = false;
            for (j=0; j<toList.length; j++)
            {
                if (toList.options[j].value == fromList.options[i].value)
                    found = true;
            }
            if (found == false)
			{
                toList.options[toList.length] = new Option(fromList.options[i].text,fromList.options[i].value);
				fromList.options[i] = null;
			}
        }
    }
}


function selectAll(fromList)
{
  for ( i = 0; i < fromList.length; i++ )
    fromList.options[i].selected = false;
    for ( i = 1; i < fromList.length; i++ )
      fromList.options[i].selected = true;
 return true;
}

function submitenter(myfield,e)
{
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;

  if (keycode == 13)
  {
    document.wwv_flow.submit();
    return false;
  }
  else
   return true;
}

function submitenter2(myfield,e)
{
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;

  if (keycode == 13)
  {
    doLogin();
    return false;
  }
  else
    return true;
}

function putFocus() 
{
  document.wwv_flow.p_username.focus();
}

function putFocus2()
{
  document.login.p_username.focus();
}

function showSS(type) {
  var ss_num = Math.round(Math.random()*46);
  var ss = new Array(47);
  ss[0] = ['Patent Wars on Aids Drugs','/04apr/00460/en/index.html','Learn how drug patents and politics are hindering AIDS treatment and prevention.'];
  ss[1] = ['Human Genetic Engineering','/04apr/00774/','Discover the science & history of genetic engineering and learn more about cloning.'];
  ss[2] = ['Crocodilians','/04apr/01293/','A great biology site for young audiences introducing all 23 crocodilian species.'];
  ss[3] = ['The Third Reich','/04apr/01058/','Witness the incendiary rise and fall of Adolph Hitler and Germany\'s Nazi party.'];
  ss[4] = ['Basic Elements','/04apr/00215/','Discover and learn about alternative energy sources to fossil fuels.'];
  ss[5] = ['Face the Music','/04apr/00275/','A digital dictionary of musical instruments and instructions to create your own.'];
  ss[6] = ['Aqua Duck','/04apr/00222/','Discover how drinking water is "magically" delivered to the taps in our homes.'];
  ss[7] = ['Gattaga Corporation','/04apr/00217/','This engaging site explores modern biotechnology and its futuristic products.'];
  ss[8] = ['Chinese Martial Arts','/04apr/00389/gindex.html','Explore Wushu, martial arts that combine exercise, artistry, philosophy, and meditation.'];
  ss[9] = ['Jeepers Creepers','/04apr/01309/','Graves above ground? Learn the morbid details of the cemeteries of New Orleans, Louisiana.'];
  ss[10] = ['Space Travel 101','/03oct/01581/SpaceTravelEnglish/main.html','Experience life as an astronaut in your spacecraft and explore the hazards of outer space.'];
  ss[11] = ['Cybercrime','/04oct/00460/','Will you become a victim of cybercrime? Learn to protect your computer & yourself.'];
  ss[12] = ['Look Through My Eyes','/04oct/00880/','See that life for people with mental disabilities is more similar than it is different.'];
  ss[13] = ['Trotting the Globe','/04oct/00450/index1.htm','You\'re going places when you travel to this site. Discover the world of transportation.'];
  ss[14] = ['Killer Waves','/04oct/01797/','Learn about the power of tsunamis, their warning signs, & what to do if faced with one.'];
  ss[15] = ['Get the Message','/04oct/00451/index1.htm','From cave drawings to email, learn about communication and how to improve your message.'];
  ss[16] = ['Flowerhorn Fish','/04oct/01027/','Discover why Singapore is fascinated with this unusual fish.'];
  ss[17] = ['Young MDG','/04oct/01865/','Explores the U.N.\'s Millenium Development Goals and how young people can help.'];
  ss[18] = ['Coffee All Ground Up','/04oct/01639/index.html','Like a good cup of coffee, this multimedia site will stimulate your mind and senses.'];
  ss[19] = ['SARS: An Open Scar','/03oct/00738/','An interactive guide to understanding the SARS epidemic and its impact.'];
  ss[20] = ['All About AIDS','/03oct/01335/en/home.html','Dispel the myths. Uncover the facts about AIDS and HIV.'];
  ss[21] = ['History of Space Travel','/03oct/00181/main-6.html','Fly through aviation history - from hot air balloons to rovers on Mars.'];
  ss[22] = ['Blood, Sweat and Tears','/03oct/01908/1024/whatisit_childlabor.htm','Find out how you can reduce child labor around the world.'];
  ss[23] = ['Natural Disasters','/03oct/01352/','Learn about the awesome power of Mother Nature & how to cope with her calamities.'];
  ss[24] = ['A Feral Feast','/03oct/00128/','Learn about the invasion of exotic species in Australia and their devestating effects.'];
  ss[25] = ['The Chinese Stage','/03oct/01397/','Did you know there are 400+ forms of Chinese opera? Explore this beautiful art.'];
  ss[26] = ['The Immunomatrix','/03oct/00520/','Engaging graphics & detailed facts about disease, the body\'s defenses, vaccines & more.'];
  ss[27] = ['The Dawn & Dusk of Man','/03oct/00875/','Compare myths from many cultures about the beginning and end of humanity.'];
  ss[28] = ['The Inside Scoop on Farms','/TQ0312380/','Whether you\'re writing a report on farms or just happen to love cows, this site will moo-ve you.'];
  ss[29] = ['The German Tutor','/TQ0313222/english/index.php','Sprechen Sie Deutsch? Learn basic German and then test yourself online.'];
  ss[30] = ['Peacemakers & Breakers','/TQ0312702/','Decide who promoted peace and who broke it. Examine the records of 25 world leaders.'];
  ss[31] = ['Physics Master','/TQ0312826/','An excellent description of movement and force for beginning physics students.'];
  ss[32] = ['Presidential Facts Page','/TQ0312172/','Step inside the White House to learn interesting facts about past U.S. presidents.'];
  ss[33] = ['The Deep Sleep','/TQ0312800/','Hibernation is just one of four types of deep sleep. Find out who hibernates and why.'];
  ss[34] = ['Rockets: Soar and Explore','/TQ0313087/main.html','Explore the development & use of rockets, then play the interactive Rocketry Game.'];
  ss[35] = ['The American Revolution','/TQ0312848/home.htm','Travel back in time to learn about the lives of 30 revolutionary figures. '];
  ss[36] = ['Body Language','/04oct/00292/','Our bodies often say more about us than our words. Learn to interpret these messages.'];
  ss[37] = ['Revolutionizing Rails','/04oct/01026/','Take a ride on the trains of the past and explore rail\'s future possibilities.'];
  ss[38] = ['Forensic Science','/04oct/00206/','Learn how modern criminal investigators use science & technology to uncover truth.'];
  ss[39] = ['Tsunami of Terror','/04oct/01724/home.html','Learn about the Indonesian Tsunami of late 2004 and the relief efforts that followed.'];
  ss[40] = ['Logicland!','/04oct/00723/','Test yourself with this library of logic puzzlers and learn useful problem-solving strategies.'];
  ss[41] = ['Future Transportation','/04oct/01249/','Take a ride to the future and explore the latest in transport technology.'];
  ss[42] = ['TB: The Forgotten Killer','/03oct/01787/','Despite being curable, TB remains the world\'s deadliest infectious disease.'];
  ss[43] = ['Discovering Genetics','/03oct/00737/','This animated tutorial explores the science of genes and how it applies to everyday life.'];
  ss[44] = ['Flooding: A Natural Disaster','/03oct/02054/','Learn bout the causes and effects of flooding, and how to prevent calamity.'];
  ss[45] = ['Space Travel Guide','/03oct/02144/home.htm','From space shuttles to space stations, propellants to propulsion, exploration is fun.'];
  ss[46] = ['Hand Over the Loot','/04oct/01737/','A fascinating account of Wild West outlaws and their robberies.'];
  
  if (type == 'library') {
    document.writeln('<a href="http://library.thinkquest.org'+ss[ss_num][1]+'" title="'+ss[ss_num][0]+'">'+ss[ss_num][0]+'</a><p>'+ss[ss_num][2]+'</p>');
  }
  else {
    document.writeln('<a href="http://library.thinkquest.org'+ss[ss_num][1]+'" title="'+ss[ss_num][0]+'" target="_blank">'+ss[ss_num][0]+'</a><p />');
  }
 
}

//------------------------------------------------
//-- G E T   A P P   H O S T   U R L
function GetAppHostUrl(type) {
  var http;
  var domain;
  var url;

  http = 'http://';

  if (location.href.indexOf('www') > 0) {
    domain = location.href.substr(location.href.indexOf('www'), 3);
  }
  else if (location.href.indexOf('dev') > 0) {
    domain = location.href.substr(location.href.indexOf('dev'), 4);
  }
  else if (location.href.indexOf('beta') > 0) {
    domain = location.href.substr(location.href.indexOf('beta'), 4);
  }
  else if (location.href.indexOf('stage') > 0) {
    domain = location.href.substr(location.href.indexOf('stage'), 5);
  }
  else if (location.href.indexOf('alpha') > 0) {
    domain = location.href.substr(location.href.indexOf('alpha'), 5);
  }
  else {
    domain = 'www';
  }
  
  if (type == 'TC') {
    url = http + domain + '.think.com/'
  }
  else if (type == 'TQ') {
    url = http + domain + '.thinkquest.org/'
  }
  else if (type == 'LIB') {
    url = http + domain + '.thinkquest.org/library/'
  }

  return url;

}

//------------------------------------------------
//-- G E T   G R A N T   U R L
function GetGrantUrl() {
  var domain;
  var url;
  var http;
  var dad;
  if (location.href.indexOf('www') > 0) {
    domain = location.href.substr(location.href.indexOf('www'), 3);
    dad    = 'html';
    http   = 'http://';
  }
  else if (location.href.indexOf('dev') > 0) {
    domain = location.href.substr(location.href.indexOf('dev'), 3);
    dad    = 'html';
    http   = 'http://';
  }
  else if (location.href.indexOf('beta') > 0) {
    domain = location.href.substr(location.href.indexOf('beta'), 4);
    dad    = 'html';
    http   = 'http://';
  }
  else if (location.href.indexOf('stage') > 0) {
    domain = location.href.substr(location.href.indexOf('stage'), 5);
    dad    = 'tcs';
    http   = 'https://';
  }
  else if (location.href.indexOf('alpha') > 0) {
    domain = location.href.substr(location.href.indexOf('alpha'), 5);
    dad    = 'html';
    http   = 'http://';
  }
  else {
    domain = 'www';
    dad    = 'html';
    http   = 'http://';
  }
  
  url = http + domain + '.oraclefoundation.org/pls/' + dad + '/f?p=grants:adobe_login::::1:';

  return url;

}

