function formHandler(form) {
  var catList = document.getElementById("category");
  var URL = catList.options[catList.selectedIndex].value;

  if(URL.substring(0,3) == "wk_") {
     URL = "http://m.cnn.com/"+URL;
  } else if(URL == "http://cnnmoney.mobi") {
     URL = "http://m.cnn.com/eaclick?aLink="+URL+"&aTitle=CNNMoneyHomeLink&aId=CNNMoneyHomeLink&aCat=cnnd_money&aSource=web.mw.cnn.com&channel=CNNMoney";
  } else if(URL == "http://m.si.com") {
     URL = "http://m.cnn.com/eaclick?aLink="+URL+"&aTitle=SIHomeLink&aId=CNNSIHomeLink&aCat=cnnd_si&aSource=web.mw.cnn.com&channel=SI";
  }
  window.location.href = URL;
}

function toggleWeather(id){
  if (document.getElementById){
    var el = document.getElementById(id);
    if (el.style.display == 'block') {
      el.style.display = 'none';
    } else {
      el.style.display = 'block';
    }
  }
}

function showProgress(obj){
    obj.setAttribute("selected","progress");
}

function submitSearchForm() {
  var SearchString =document.getElementById("searchString").value.replace(/\s+/g,'');
  if(SearchString!='' && SearchString!='EnterSearchTerm')
  {
    window.location = 'orange-country-search-result.aspx?searchTerm=' + document.getElementById("searchString").value;
    //document.getElementById("searchForm").submit();
  }
  else
  {
   alert("Please enter Search Term");
  }
  return false;
}

function submitWeatherForm() {
  document.getElementById("weatherForm").submit();
  return false;
}

function submitSMSForm() {
  if(validateSMSInput()) {
   document.getElementById("SMSForm").submit();
  }
  
  return false;
}

function validateSMSInput() {
    var nregex = "^[0-9]{10}$";
    var tNum = document.SMSForm.toNum.value;
    if(tNum == '') {
	alert( "Please enter To Phone Number" );
        return false;
    }
    var fNum = document.SMSForm.fromNum.value;
    if(fNum == '') {
        alert( "Please enter Your Phone Number" );
        return false;
    }
    if(!(tNum.match(nregex))) {
        alert( "Please enter a valid 10 digit To Phone Number" );
        return false;
    }
    if(!(fNum.match(nregex))) {
        alert( "Please enter a valid 10 digit Your Phone Number" );
        return false;
    }
    return true;
}

function submitEMailForm() {
  if(validateEMailInput()) {
    document.getElementById("EMailForm").submit();
  }

  return false;
}

function validateEMailInput() {
    var emregex = /^[-+.\w]{1,64}@[-.\w]{1,64}\.[-.\w]{2,6}$/;
    var toMail = document.EMailForm.toEmail.value;
    if(toMail == '') {
        alert( "Please enter To Email Address" );
        return false;
    }
    var fromMail = document.EMailForm.fromEmail.value;
    if(fromMail == '') {
        alert( "Please enter Your Email Address" );
        return false;
    }
    if(!toMail.match(emregex)) {
        alert( "Please enter a valid To Email Address" );
        return false;
    }
    if(!fromMail.match(emregex)) {
        alert( "Please enter a valid Your Email Address" );
        return false;
    }
    return true;
}


function toggleSendNav(id1,id2,id3) {
	var div = $('#'+id1);
	if(div.css('display') == 'none') {
		div.slideDown();
		document.getElementById("sendnav"+id1).className = "on";
	} else {
		div.slideUp();
		document.getElementById("sendnav"+id1).className = "off";
	}
	document.getElementById(id2).style.display = 'none';
	document.getElementById("sendnav"+id2).className = "off";
	document.getElementById(id3).style.display = 'none';
	document.getElementById("sendnav"+id3).className = "off";
}

function CheckSearchEnter(e)
{
	var KeyID =e.keyCode?e.keyCode:e.which;
	var isnumber = false;
	if ((KeyID!=null) && (KeyID==13))
	{
	  return submitSearchForm();
	}
}

