////////////////////////////////////////////////////////////////////////////

// tdGeneral.js

//

// TicketDerby general JavaScript functions.

//



// Retrieve the xmlHTTP object supported by the users browser, which may not exist...

 
function getXmlHttpRequestObject() {

  var xmlReqObject;

  try {

    // Opera 8.0+, Firefox, Safari

    xmlReqObject= new XMLHttpRequest();

  }catch(e) {

    // Internet Explorer Browsers

    try {

      xmlReqObject= new ActiveXObject('Msxml2.XMLHTTP');

    }catch(e) {

      try {

        xmlReqObject= new ActiveXObject('Microsoft.XMLHTTP');

      }catch(e) {

        // Something went wrong...

//        alert( "Your browser does not appear to support a required object (AJAX)!" );

        return false;

      }

    }

  }

  return xmlReqObject;

}



// Rounds the input number to the desired

// precision and returns the rounded number...

function roundToPrecision(inputNum, desiredPrecision) {

  var precisionGuide= Math.pow(10, desiredPrecision);

  return Math.round(inputNum * precisionGuide) / precisionGuide;

}



// Converts the input number into a string and adds zeroes

// until the desired precision is reached and then

// returns the new string...

function addZeroesToPrecision(inputNum, desiredPrecision) {

  var numString= inputNum + "";

  if (numString.search(/\./) == -1) {

    numString += '.0';

  }

  var afterDecimalString= numString.substring(numString.search(/\./) + 1);

  while(afterDecimalString.length < desiredPrecision) {

    afterDecimalString += "0";

    numString += "0";

  }

  return(numString);

}



function checksearch(btnid,txtid) {

  var txtvalue= document.getElementById(txtid).value;

  var emailcheck= document.getElementById(txtid);

  if (txtvalue == "undefined" || txtvalue == null ||

    emailcheck == "undefined" || emailcheck == null)

  {

    return false;

  }

  if (btnid.name=='btn_ticket') {

    if (txtvalue=="" || txtvalue=="Search For Tickets") {

      alert("Please enter an event name.");

      return false;

    }

  }

  

  if (btnid.name=='btn_city') {

    if (txtvalue==0) {

      alert("Please select an event city.");

      return false;

    }

  }

  

  if (btnid.name=='btn_email') {

    if (txtvalue=="" || txtvalue=="email" || emailcheck.value.indexOf ('@',0) == -1 || emailcheck.value.indexOf ('.',0) == -1) {

      alert("Please enter a valid email address.");

      return false;

    }

  }

}



function removeText(idname,txt) {
	

  if (typeof(idname) == "undefined" || idname == null) return;

  if (typeof(txt) == "undefined" || txt == null) return;

  var ele= document.getElementById(idname);

  if (typeof(ele) == "undefined" || ele == null) return;

  if (ele.value == txt) ele.value= "";

}



function resetText(idname,txt) {

  if (typeof(idname) == "undefined" || idname == null) return;

  if (typeof(txt) == "undefined" || txt == null) return;

  var ele= document.getElementById(idname);

  if (typeof(ele) == "undefined" || ele == null) return;

  if (ele.value == "") ele.value= txt;

}



function checkSearch(txtid) {

  if (typeof(txtid) == "undefined" || txtid == null) return false;

  var ele= document.getElementById(txtid);

  if (typeof(ele) == "undefined" || ele == null) return false;

  if (ele.value.length < 3) {

    alert("Please enter at least 3 characters to search for!");

    return false;

  }

  return true;

}



function gotoLink(linkpath) {

  window.location.replace(linkpath);

}

