﻿/*----------------------------------------------------
Date Created		20/11/2008
Created By		    Tristan Mcvean
Description		    The following script is part
                    of Hotels4u.com new White Label
----------------------------------------------------*/

function ge(elID) {
    return document.getElementById(elID);
}

function featHotelImg() {
    var i = ge('featured-links').offsetHeight;
    ge('featured-image-1').height = i - 1;
    ge('featured-image-2').height = i - 1;
    ge('featured-image-3').height = i - 1;
}

function Navigate(url) {
    document.location.href = url;
    return false;
}
//  move to SearchPanelValidation.js TM
//function SearchClicked() {
//    if (ge("divSearching")) {
//        ge("divSearching").style.display = "";        
//        var divSearchingBack = ge("divSearchingBack");
//        divSearchingBack.style.display = "";
//        divSearchingBack.style.width = document.body.parentNode.scrollWidth + 'px';
//        divSearchingBack.style.height = document.body.parentNode.scrollHeight + 'px';
//        var ie6SearchingBack = ge("iSearchBack");
//        if (ie6SearchingBack)
//            ie6SearchingBack.style.height = document.body.parentNode.scrollHeight + 'px';
//    }
//}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if (document.layers)	   //NN4+
    {
        document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if (document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = ge(szDivID);
        obj.style.display = iState ? "block" : "none";
    }
    else if (document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "block" : "none";
    }
}

function showSearch() {
    toggleBox('filterTab', 0);
    toggleBox('searchTab', 1);
    toggleBox('searchTab_norm', 1);
    toggleBox('filterTab_norm', 1);
    toggleBox('searchTab_alt', 0);
    toggleBox('filterTab_alt', 0);
}

function showFilter() {
    toggleBox('filterTab', 1);
    toggleBox('searchTab', 0);
    toggleBox('searchTab_norm', 0);
    toggleBox('filterTab_norm', 0);
    toggleBox('searchTab_alt', 1);
    toggleBox('filterTab_alt', 1);
}

function openEmailForm() {

    var pnlEmailForm = ge('pnlEmailForm');

    if (pnlEmailForm.style.display == 'none')
        pnlEmailForm.style.display = '';
    else
        pnlEmailForm.style.display = 'none';

    return false;
}

function validateEmailForm(ucID) {

    var cp = ucID + '_';

    //alert('test');
    var txtEmailTitle = ge(cp + 'txtEmailTitle');
    var txtEmailFirstName = ge(cp + 'txtEmailFirstName');
    var txtEmailLastName = ge(cp + 'txtEmailLastName');
    var txtEmailEmail = ge(cp + 'txtEmailEmail');
    var txtEmailExtraNotes = ge(cp + 'txtEmailExtraNotes');

    if (txtEmailTitle.value == '') {
        alert('Please fill in your Title');
        return false;
    }
    if (txtEmailFirstName.value == '') {
        alert('Please fill in your First Name');
        return false;
    }
    if (txtEmailLastName.value == '') {
        alert('Please fill in your Last Name');
        return false;
    }
    if (txtEmailEmail.value == '') {
        alert('Please fill in your Email Address');
        return false;
    }

    return validateAddress(txtEmailEmail.value);
}
function validateAddress(incoming) {
    var emailstring = incoming;
    var ampIndex = emailstring.indexOf("@");
    var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
    // find a dot in the portion of the string after the ampersand only
    var dotIndex = afterAmp.indexOf(".");
    // determine dot position in entire string (not just after amp portion)
    dotIndex = dotIndex + ampIndex + 1;
    // afterAmp will be portion of string from ampersand to dot
    afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
    // afterDot will be portion of string from dot to end of string
    var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
    var beforeAmp = emailstring.substring(0, (ampIndex));
    //old regex did not allow subdomains and dots in names
    //var email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
    var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/
    // index of -1 means "not found"
    if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.length > 5) &&
		(afterAmp.length > 0) &&
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		(email_regex.test(emailstring))) {
        return true;
    } else {
        alert("Please check your email address!");
        return false;
    }
}