//SUSCKER FISH IE FIX
sfHover = function() {
    var mn = document.getElementById("main_nav");
    if(mn != null){
        var sfEls = mn.getElementsByTagName("LI");
        for (var i = 0; i < sfEls.length; i++) {
            sfEls[i].onmouseover = function() {
                this.className += " sfhover";
            }
            sfEls[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }    
    }
//    var sfEls = document.getElementById("main_nav").getElementsByTagName("LI");
//    for (var i = 0; i < sfEls.length; i++) {
//        sfEls[i].onmouseover = function() {
//            this.className += " sfhover";
//        }
//        sfEls[i].onmouseout = function() {
//            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
//        }
//    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//JAVASCRIPT FIX FOR NAV STYLES - OVER & OUT STATES
function parentStyles(ele){
	if(document.getElementById(ele).className=='top active'){
		document.getElementById(ele).className='top active_over';
	}else if(document.getElementById(ele).className=='top'){
		document.getElementById(ele).className='top over';
	}else if(document.getElementById(ele).className=='top active_over'){
		document.getElementById(ele).className='top active';
	}else if(document.getElementById(ele).className=='top over'){
		document.getElementById(ele).className='top';
	}
}

//EMAIL CHECK
function verify_email(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1){return false}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {return false;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {return false;}
	if (str.indexOf(at,(lat+1))!=-1) {return false;}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {return false;}
	if (str.indexOf(dot,(lat+2))==-1) {return false;}
	if (str.indexOf(" ")!=-1) {return false;}
	return true;					
}

function checkForm(){
	var bln_valid=true;
	var str_message='';
	if(!verify_email(document.getElementById('email_address').value)){
		bln_valid=false;
		document.getElementById('email_address').style.backgroundColor='#ED5429';
	}
	if(document.getElementById('first_name').value==""){
		bln_valid=false;
		document.getElementById('first_name').style.backgroundColor='#ED5429';
	}
	if(document.getElementById('second_name').value==""){
		bln_valid=false;
		document.getElementById('second_name').style.backgroundColor='#ED5429';
	}
	if(bln_valid){ 
		document.getElementById("frm_enquiry").submit();
	}else{ 
		document.getElementById("form_error").style.display='block';
		return false;
	}
}

//function filterNav(sector){
//	if(sector!=null){ sector=sector.replace("-", "_");}
//	if(sector==null){document.getElementById("all_sectors").className='active';document.getElementById("all_sectors_footer").className='active';}else if(sector=='hospitality' || sector=='public_sector' || sector=='finance' || sector=='public_sector' || sector=='property' || sector=='e_commerce'){ if(document.getElementById(sector)){document.getElementById(sector).className='active';document.getElementById(sector+'_footer').className='active';} }else{document.getElementById("all_sectors").className='active';document.getElementById("all_sectors_footer").className='active';}
//}

function filterServices() {
    var curUrl = window.location.pathname;
    $('#sector_filter_holder .row .service-block a').each(
        function() {
            if ($(this).attr('href') == curUrl) {
                $(this).attr('class', 'active');
            }
        }
    );
}

//DOCUMENT READY ACTIONS
$(document).ready(function() {
    //init filter services
    filterServices();
    //set rollovers on main nav
    $('ul#main_nav ul').each(function(i) {
        $(this).attr('id', i);
        str_sub = $(this).html();
        if (str_sub == '') { $(this).css('display', 'none'); }
        $(this).hover(function() {
            parentStyles($(this).prev('a').attr("id"));
        }, function() {
            parentStyles($(this).prev('a').attr("id"));
        });
    });
    //check sector filter
    //filterNav(jQuery.url.segment(0));
    //set active state on top level main nav
//    $('ul#main_nav li a.top').each(function(i) {
//        $(this).attr('id', i);
//        str_title = $(this).attr('title').toLowerCase();
//        if (jQuery.url.segment(0) == str_title) { $(this).addClass('active'); } else if (jQuery.url.segment(1) != null && jQuery.url.segment(1) == str_title) { $(this).addClass('active'); } else if (jQuery.url.segment(0) == null && str_title == "home") { $(this).addClass('active'); } else if (jQuery.url.segment(0) == "index.aspx" && str_title == "home") { $(this).addClass('active'); }
//    });

});






