/* 
bcs.js: library of javascript for animation / branding effects
    david.kelly@fanore.com (http://www.fanore.com/website_design.htm)
    
    
    
*/


//setup_page: called when page loads
function setup_page(){
    fix_height();
    var el=get_el("contact_us_form");
    if (el){
        eval("setup_focus_tracking(\'form_contact_us\', \'input_element\');")
    }
    var el=get_el("map");
    if (el){
        eval('load_map();');
    }
    var el=get_el("credit");
    if (el){
        eval('intercept_credit();');
    }
    outbound_links();
    
}
//outbound_links: ensure that outbound links open in a new window
function outbound_links(){
    var children=$A($('main_panel').select('a'));
    //alert(children.length);
    var e_click=function(el)
    {   
        if ((!el.href.include('bcs.ie'))&&(!el.href.include('javascript'))){
            el.href='javascript: open_link(\'' + el.href + '\');';
         }
    }     
    children.each(e_click);     
    return void[0];
    
}


function intercept_credit(){
    var url=$('credit').href
    $('credit').href="javascript: open_link('" + url + "');"
    var url=$('credit2').href
    $('credit2').href="javascript: open_link('" + url + "');"
}

function load_map() {
    if (GBrowserIsCompatible()) {
        var map = new GMap(document.getElementById("map"));
        map.addControl(new GLargeMapControl())
        map.addControl(new GMapTypeControl());
              map.setCenter(new GLatLng(52.6706428, -8.5511101), 12);
        	
        	
        var point = new GPoint(parseFloat(-8.5511101), parseFloat(52.6706428));
        var marker = new GMarker(point);
        var icon = new GIcon();
        icon.image = "../images/map_arrow.gif";
        icon.iconSize = new GSize(16,16);
        icon.iconAnchor = new GPoint(4,6);
        icon.infoWindowAnchor = new GPoint(20, 20);
        var marker = new GMarker(point,icon);
        
        map.addOverlay(marker);
        return marker
    }
 }
 

// fix_height; ensure that the main panel and footer fill screen
function fix_height(){
    var el=get_el("credit");
    if (el){
    var h=(document.viewport.getHeight()-225).toString() + 'px';
    }
    else{
    var h=(document.viewport.getHeight()-225).toString() + 'px';
    }
    var b=$('main_panel').getStyle('height')
    if (parseInt(b.toString().replace('px',''))< parseInt(h.replace('px',''))){
        $('main_panel').setStyle({height: h});
    }
    else{
        $('main_panel').setStyle({height: 'auto'});
    }
}



function open_link(url){
 var settings='Height=' + screen.height + ',Width=' + screen.width + ',Top=0,left=0,scrollbars=yes,resizable=1, location=1,status=1'
 var w=window.open(url,'iitdpopup',settings);    
}

//submit_form: utility that will perform client side validation of the passed form id and allow validator to post it 
function submit_form(param_form){
    var el=get_el("cs_validation");
    //alert("here");
    if (el){
        var f=$(param_form)
        var cs_validation=f['cs_validation'];
        //alert(eval($(cs_validation).getValue()));
         return eval($(cs_validation).getValue());
    }
    else{
        $(param_form).submit();
    }
}

// used to validate the "contact us" form
function validate_contact(){
// first ensure that required fields have been completed
    // is this form using presubmission validation ?
    


    //check the name
    var el=get_el("txt_name")
    if (el.value.length==0){
        alert("please enter your name !")
        el.focus();
        return void[0];    
    }
    
    //check the email address
    var el=get_el("txt_email")
    if (el.value.length==0){
        alert("please enter your email address !")
        el.focus();
        return  void[0];    
    }
    var sval=el.value
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		el.focus();
		return  void[0];
	}
        var telephone=fix_telephone($F('txt_telephone'));
        if ((telephone.blank())||(telephone.length<5)){
            alert("Please enter either a telephone or mobile number in numeric format (e.g. ##########)!");
            $('txt_telephone').value='';
            $('txt_telephone').focus();
            return void[0];
        }
	
    //check the comment
    var el=get_el("txt_comment")
    if (el.value.length==0){
        alert("please let us know how we can assist !")
        el.focus();
        return  void[0];    
    }
	else if (el.value.length>1024){
		alert("Your comment is limited to 1024 characters, please shorten your query.")
        el.focus();
        return  void[0];    
	}
     var f=$(form_contact_us)
    f["your_details"].value="";
    $('form_contact_us').submit();
}


function fix_telephone(param_value){
    var ret_value='';
    var wip_value=param_value;
    var a_values='1234567890'
    //alert(wip_value.length);
    for (var i=0;i<=wip_value.length;i++){
    //alert(wip_value.charAt(i))
        for (var x=0;x<=a_values.length;x++){
            
            if (wip_value.charAt(i)==a_values.charAt(x)){
                ret_value+=wip_value.charAt(i)
            }
        }
    } 
    //alert(ret_value);
    return ret_value;   
}


