String.prototype.trim = function()
 {
  return this.replace(/^\s+|\s+$/g, "");
 }

function addInputText(obj, text)
 {
  if (obj.value == "")
   {
    obj.value = text;
   }
 }

function removeInputText(obj, text)
 {
  if (obj.value == text)
   {
    obj.value = "";
   }
 }

function switchTab(type)
 {
  if (type == "findyourteacher")
   {
    document.getElementById("findyourschool").style.display = "none";
    document.getElementById("findyourteacher").style.display = "block";
    
    document.getElementById("findyourschool_tab").style.backgroundPosition = "0px 34px";
    document.getElementById("findyourteacher_tab").style.backgroundPosition = "0px 0px";
   }
   
  else if (type == "findyourschool")
   {
    document.getElementById("findyourteacher").style.display = "none";
    document.getElementById("findyourschool").style.display = "block";
    
    document.getElementById("findyourteacher_tab").style.backgroundPosition = "0px 34px";
    document.getElementById("findyourschool_tab").style.backgroundPosition = "0px 0px";
   }
 }

function openCountry(selectId)
 {
  if (selectId == "selectcountry_teacher")
   {
    if (document.getElementById("selectcountry_teacher").style.display == "" || document.getElementById("selectcountry_teacher").style.display == null || document.getElementById("selectcountry_teacher").style.display == "none")
     {
      document.getElementById("findbtn_teacher").style.display = "none";
      document.getElementById("selectelement_teacher").style.background = "url(/design/rmt-us/images/selectcountry-drop.gif) no-repeat";
      document.getElementById("selectelement_teacher").style.height = "150px";
      document.getElementById("selectcountry_teacher").style.display = "block";
     }

    else
     {
      document.getElementById("findbtn_teacher").style.display = "block";
      document.getElementById("selectelement_teacher").style.background = "url(/design/rmt-us/images/selectcountry.png) no-repeat";
      document.getElementById("selectelement_teacher").style.height = "32px";
      document.getElementById("selectcountry_teacher").style.display = "none";
     }
   }
  
  else if (selectId == "selectcountry_school")
   {
    if (document.getElementById("selectcountry_school").style.display == "" || document.getElementById("selectcountry_school").style.display == null || document.getElementById("selectcountry_school").style.display == "none")
     {
      document.getElementById("findbtn_school").style.display = "none";
      document.getElementById("selectelement_school").style.background = "url(/design/rmt-us/images/selectcountry-drop.gif) no-repeat";
      document.getElementById("selectelement_school").style.height = "150px";
      document.getElementById("selectcountry_school").style.display = "block";
     }

    else
     {
      document.getElementById("findbtn_school").style.display = "block";
      document.getElementById("selectelement_school").style.background = "url(/design/rmt-us/images/selectcountry.png) no-repeat";
      document.getElementById("selectelement_school").style.height = "32px";
      document.getElementById("selectcountry_school").style.display = "none";
     }
   }
 }
 
function openUserType()
 {
  var validOptions = {"Student": "Student", "Parent": "Parent", "Teacher": "Teacher"};
  var selectBox = 1;
  var holdId = "";
 
  document.getElementById("selectdropcurrent").innerHTML = document.getElementById("selectcurrent").innerHTML.trim(); 
  validOptions[document.getElementById("selectcurrent").innerHTML.trim()] = null;

  for (enumOptions in validOptions)
   {
    if (validOptions[enumOptions] != null)
     {
      holdId = "selectdrop" + selectBox;
      
      document.getElementById("selectdrop" + selectBox).innerHTML = validOptions[enumOptions];
      document.getElementById("selectdrop" + selectBox).onclick = function() { selectUserType(document.getElementById(this.id).innerHTML); };
      selectBox++;
     }
   }

  document.getElementById("continuebtn").style.display = "none";
  document.getElementById("selectnormal").style.display = "none";
  document.getElementById("selectdrop").style.display = "block";
 }
 
function closeUserType()
 {
  document.getElementById("selectdrop").style.display = "none";
  document.getElementById("continuebtn").style.display = "block";
  document.getElementById("selectnormal").style.display = "block";
 }
 
function selectUserType(type)
 {
  var validOptions = {"Student": 0, "Parent": 1, "Teacher": 2};
 
  document.getElementById("selectcurrent").innerHTML = type;
  document.getElementById("usertype").value = validOptions[type];
  closeUserType();
 }
 
function switchCountry(obj)
 {
  var country = null;
  var formUrl = null;
  
  country = obj.options[obj.selectedIndex].value.replace("rmt-", "");
  
  if (country != "")
   {
    if (country == "ie")
     {
      document.getElementById("zipcode_container").style.display = "none";
     }

    else
     {
      document.getElementById("zipcode_container").style.display = "block";
      document.getElementById("zipcode_container").focus();
     }

    formUrl = document.getElementById("indexjoinform").action.substring(document.getElementById("indexjoinform").action.lastIndexOf("/"));
    
    if (document.location.href.substring(0, 12).indexOf("stage") == -1)
     {
      if (country == "us")
       {
        document.getElementById("indexjoinform").action = "http://www.ratemyteachers.com" + formUrl;
       }
       
      else
       {
        document.getElementById("indexjoinform").action = "http://" + country + ".ratemyteachers.com" + formUrl;
       }
     }
     
    else
     {
      document.getElementById("indexjoinform").action = "http://stage" + country + ".ratemyteachers.com" + formUrl;
     }

    document.getElementById("hiddencountry").value = country;
    /*window.alert(document.getElementById("indexjoinform").action);*/
   }
 }
 
	function advancedSearch(searchtype)
	{
		if(searchtype == "teacher")
		{
			objS = document.getElementById('teacher_search_input');
			if(objS)
			{
				if(objS.value != "teacher name")
					window.location = '/advancedsearch.php?lname=' + objS.value;
				else
					window.location = '/advancedsearch.php';
			}
			else
				window.location = '/advancedsearch.php';
		}
		else if(searchtype == "school")
		{
			objS = document.getElementById('school_search_input');

			if(objS)
			{
				if(objS.value != "school name")
					window.location = '/advancedsearch.php?schoolname=' + objS.value;
				else
					window.location = '/advancedsearch.php';
			}
			else
				window.location = '/advancedsearch.php';
		}
	}