/*
 Created By: V. Subhash
 Created On: 7 November 2008
 Updated On: 10 November 2008
*/

function IsValidEmail(sEmail) {
  if (sEmail.search(/^[\w\.\-]+\@[\w\.\-]+\.[\w\.\-]+$/ ) == -1) {
    return(false);
  } else {
   return(true);
  }
}

function IE_SwitchMenuOn(ddm, hmo, hmo_bg) {
 /*
	  What cannot be done through CSS needs to be
   done through JavaScript because IE is a moron.
 */
	if (IsIE()) {
   ddm.style.display = "block";
   ddm.style.left = 0;
   ddm.style.top = 26;
   hmo.style.backgroundImage = "url(" + hmo_bg + ")";
 }
}

function IE_SwitchMenuOff(ddm, hmo, hmo_bg) {
 /*
	  What cannot be done through CSS needs to be
   done through JavaScript because IE is a moron.
 */
 if (IsIE()) {
   ddm.style.display = "none";
   hmo.style.backgroundImage = "url(" + hmo_bg + ")";
 }

}

function IsIE() {
  if (window.navigator.userAgent.toLowerCase().indexOf("opera") != -1) {
  	 return(false);
  }
  if (window.navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
	   return(true);
  }
  return(false);
}

function ShowContentForTab(content, tab, num) {
  var i;

  for (i=1; i<=num; i++) {
    document.getElementById("Tab" + i).className = "Tab_Regular";
    document.getElementById("TabContent" + i).style.display = "none";
  }
	 content.style.display = "block";
	 tab.className = "Tab_Highlight";
}

function Update_Price(oCBox, oTBox, sOPrice, sEPrice, sURL, sOURL, sParamValuePair) {
	if (oCBox.checked) {
   oTBox.value = sOPrice + sEPrice;
   sURL.href = sOURL + sParamValuePair;
 } else {
   oTBox.value = sOPrice;
   sURL.href = sOURL;
	}
}

function DisplayIFrame(sFrame, sFile) {
	var objFrame = document.getElementById(sFrame);

	if (objFrame.style.display != "block") {
      objFrame.style.display = "block";
  	  objFrame.src = sFile;
    }
}


function WaitNRenderBox(oBox, oRequest) {
  if (oRequest.readyState == 4) {
    if (IsIE() && (document.getElementById(oBox).tagName.toLowerCase() == "pre")) {
      // 'Cos setting firstChild.nodeValue does not erase innerText 
      // Don't set empty string - IE freaks out.
      document.getElementById(oBox).innerText = " ";
      // Well, stupud mode removes blank lines and consecutive white spaces
      // from pre tags. Thank you, some guy named Jake, on StackOverflow.
      // Setting outerHTML fails in IE6.
      document.getElementById(oBox).firstChild.nodeValue = oRequest.responseText;
    } else {
      document.getElementById(oBox).innerHTML = oRequest.responseText;
    }
  }
}



function RenderHLFBox(oBox, sUrl) {
 var response = null;

 document.getElementById(oBox).style.display = "block";

 if (IsIE()) {
  // IE6 - We we invented it!
  var connection = new ActiveXObject("Microsoft.XMLHTTP");
 } else {
  var connection = new XMLHttpRequest();
 }

 try {
   connection.open("GET", "texts/" + sUrl, true);
   connection.onreadystatechange = function() {
                                     WaitNRenderBox(oBox, connection);
                                   };
   connection.send(null);
 } catch(e) {
   return(null);
 }

}

function AjaxRender(oElement, sUrl) {
 var oAjaxRequest;

 if (IsIE()) {
   oAjaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
 } else {
   oAjaxRequest = new XMLHttpRequest();
 }

 try {
   oAjaxRequest.open("GET", sUrl, true);
   oAjaxRequest.onreadystatechange = function() {
                                       AjaxRender_Helper(oElement, oAjaxRequest);
                                     };
   oAjaxRequest.send(null);
 } catch(e) {
   return(null);
 }

}

function AjaxRender_Helper(oElement, oRequest) {
  if (oRequest.readyState == 4) {
    oElement.innerHTML = oRequest.responseText;
  }
}