/* 
	Current Version 0.01
	-- Version 0.01, added getObj(),checkFeedback() function for feedback form, abdul @ 26/06/2008  
	-- Version 0.02, added jumpToQuickLinks(),checkEmail(),checkUrl() abdul @ 19/07/2008
*/

//getObj()
function getObj(name){if (document.getElementById) {this.obj = document.getElementById(name);this.style = document.getElementById(name).style;} else if (document.all) {this.obj = document.all[name];this.style = document.all[name].style;} else if (document.layers) {this.obj = document.layers[name];this.style = document.layers[name]; }}function feedback_toggle(){	var DHTML = (document.getElementById || document.all || document.layers);if (!DHTML) return;	var x = new getObj("feedback");	var vis = x.style.display;if(vis == "none" || vis == ""){x.style.visibility = "visible";x.style.display = "block";}else{x.style.visibility = "hidden";x.style.display = "none";}}
//utility function, trim string both sides
function trimString(theString) {
		while (theString.charAt(0) == " ") {theString = theString.substring(1,theString.length);
		}while (theString.charAt(theString.length - 1) == " ") {theString = theString.substring(0,theString.length - 1);
		}return theString;}
//check for validation for Feedback
function checkFeedback(){if ((document.forms["feedback_form"].feedback_text.value.length == 0) || (trimString(document.forms["feedback_form"].feedback_text.value) == 0 )) {alert("Please enter some feedback or a question");	}else{
		document.forms["feedback_form"].submit();}}
	
function jumpToQuickLinks()
	{	
	var destination = document.searchform.headerQuickLinks.options[document.searchform.headerQuickLinks.selectedIndex].value;
	if (destination) location.href = destination;
}

function checkEmail(email)
 {var reEmail=/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
	if (email.search(reEmail)==-1) //if match failed
 return false; 
	 else
 return true;}
 
 function checkUrl(s) {var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
 return regexp.test(s); }
 
 function checkSearch(){var theForm = document.forms["searchform"];
		if(theForm.q.value.length == 0 || theForm.q.value==theForm.q.defaultValue)
		 {alert("Please enter the words to search for");theForm.q.focus();}else{document.searchform.submit();}}
		 
   
function changePage(whatForm, scrollingInput, val) {
    scrollingInput.value = val;
    var ctnListname = scrollingInput.name.substring(10,scrollingInput.name.length);
    whatForm.elements['ctnlistpagination_' + ctnListname].value='true';
    whatForm.submit();
}

function IsNumeric(strString) //  check for valid numeric strings	
     {
     	if(!/\D/.test(strString)) return true;//IF NUMBER
     	else if(/^\d+\.\d+$/.test(strString)) return true;
     	else return false;
     }
   
//booking form check
function checkBookingForm(theForm) {
    var errorStr = "";
    if (trimString(theForm.fullNameOfAttendee.value) == 0) {
        errorStr += "- Please enter your name \n";
    }
    if (trimString(theForm.emailAddressOfAttendee.value) == 0) {
        errorStr += "- Please enter email address \n";
    }
    if (!checkEmail(trimString(theForm.emailAddressOfAttendee.value)) &&
        trimString(theForm.emailAddressOfAttendee.value) != 0) {
        errorStr += "- Please enter valid email address \n";
    }
    if (trimString(theForm.phoneOfAttendee.value) == 0) {
        errorStr += "- Please enter phone number \n";
    }

    if (trimString(theForm.numberAttending.value) == 0) {
        errorStr += "- Please enter number of persons attending event \n";
    }
    if (!IsNumeric(trimString(theForm.numberAttending.value)) &&
        trimString(theForm.numberAttending.value) != 0) {
        errorStr += "- Number of persons attending should be a valid number. Please enter valid number. \n";
    }


	if (errorStr == "") {
        return true;
    } else {
        alert("Error: \n" + errorStr);
        return false;
    }
}

function resize_iframe()
{

	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	//resize the iframe according to the size of the
	//window (all these should be on the same line)
	document.getElementById("thisIframe").style.height=parseInt(height-document.getElementById("thisIframe").offsetTop-8)+"px";
}

function addIframeElement(replaceObjectID, srcVal, widthVal, heightVal, idVal, frameborderVal, scrollingVal, alignVal, className) {
    if (document.getElementById(idVal)) {
        return;
    }
    var newIframeElement = document.createElement("iframe");
    newIframeElement.setAttribute("width", widthVal);
    newIframeElement.setAttribute("height", heightVal);
    newIframeElement.setAttribute("frameborder", frameborderVal);
    newIframeElement.setAttribute("scrolling", scrollingVal);
    newIframeElement.setAttribute("align", alignVal);
    newIframeElement.setAttribute("id", idVal);
    newIframeElement.setAttribute("name", idVal);
    newIframeElement.className = className;
    var replaceObject = document.getElementById(replaceObjectID);
    if (replaceObject) {
        replaceObject.parentNode.replaceChild(newIframeElement, replaceObject);
        top[idVal].location.href = srcVal;
    }
    top[idVal].name = idVal;
}

function SearchTools() {
}
SearchTools.showHitDetails =  function (frameHtmlElementId, labelHtmlElementId, onMsg, offMsg) {
    var htmlEl = document.getElementById(labelHtmlElementId);
    if (htmlEl) {
        if (!htmlEl.labelMsg) {
            htmlEl.labelMsg = "on";
        }
        if (htmlEl.labelMsg == "on") {
            htmlEl.innerHTML = offMsg;
            htmlEl.labelMsg = "off";
        } else {
            htmlEl.innerHTML = onMsg;
            htmlEl.labelMsg = "on";
        }
    }
    var frameHtmlEl = document.getElementById(frameHtmlElementId);
    if (frameHtmlEl) {
        if (htmlEl.labelMsg == "off") {
            frameHtmlEl.style.display = "block";
        } else {
            frameHtmlEl.style.display = "none";
        }
    }
}
SearchTools.resetSearchRefine = function (formName) {
    var searchForm = document.forms[formName];
    searchForm.elements.searchRefineAttribute.value = "reset";
    searchForm.submit();
}
