function cc_globalOnload() {
    cc_addListener("cc-btn-left","click",cc_submitForm);
    cc_addListener("cc-btn-left-narrow","click",cc_submitForm);
    cc_addListener("cc-search-submit","click",cc_submitForm);
    cc_addListener("cc-popup-link","click",cc_popLink);
    cc_addListener("cc-popup-link2","click",cc_popLink2);
    cc_addListener("cc-text-popup","click",cc_headerInfo);
    cc_addListener("cc-html-popup","click",cc_headerHTML);
}
function cc_submitForm(e) {
    if(!e) e = window.event;
    var o = (e.srcElement) ? e.srcElement : this;
    // for IE, handle existing input click
//    if(o.nodeName == "INPUT") return false;

    // find containing form
    var objForm = cc_getAncestor(o,"nodeName","FORM");
    if(objForm) {
        // submit if valid
        if (!cc_validateForm(objForm))
        {
            if(e.preventDefault) e.preventDefault();
            return false;
        }
        else { objForm.submit(); }
    }
    if(e.preventDefault) e.preventDefault();
    return false;
}
// generic popup function
function cc_popup( strURL, intW, intH, strName )
{
    var obwindow = window.open( strURL, strName, 'width='+intW+',height='+intH+',resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1' )
   
    obwindow.focus();
    //obwindow.moveTo(50,50);
}
function cc_popup3( strURL, intW, intH, strName )
{
    var obwindow = window.open( strURL, strName, 'width='+intW+',height='+intH+',resizable=yes,toolbar=yes,location=yes,directories=no,status=no,menubar=no,scrollbars=1' )
   
    obwindow.focus();
    //obwindow.moveTo(50,50);
}
// calls header info popup
function cc_headerInfo(e) {
    if(!e) e = window.event;
    var o = (e.srcElement) ? e.srcElement : this;
//    var strText = (o.id && o.id != "") ? cc_getText("cc-"+o.id+"-popup") : cc_getText(o);
    if(o.href) {
        cc_popup( o.href, 350, 100, 'HeaderPopup' );
    }
    else {
        var strText = cc_getText(cc_getChild(o));
        cc_popup( 'ws_popup.asp?info='+escape(trim(strText)), 350, 100, 'HeaderPopup' );
    }

    if(e.preventDefault) e.preventDefault();
    return false;
}
function cc_headerHTML(e) {
    if(!e) e = window.event;
    var o = (e.srcElement) ? e.srcElement : this;

    if(o.href) {
        cc_popup( o.href, 350, 100, 'HeaderPopup' );
    }
    else {
        var strText = (o.id != "undefined" && o.id != "") ? cc_getText("cc-"+o.id+"-popup") : cc_getText(o);
        cc_popup( 'ws_popup.asp?text='+escape(trim(strText)), 350, 100, 'HeaderPopup' );
    }
    //if(e.preventDefault) e.preventDefault();
    return false;
}

function cc_popLink(e) {
    if(!e) e = window.event;
    var o = (e.srcElement) ? e.srcElement : this;
    var strURL = o.href;
    var iWidth = (strURL.match(/[?&;]w=(\d+)/)) ? strURL.match(/[?&;]w=(\d+)/)[1] : 780;
    var iHeight = (strURL.match(/[?&;]h=(\d+)/)) ? strURL.match(/[?&;]h=(\d+)/)[1] : 500;
    cc_popup(o.href, iWidth, iHeight, o.id);
    if(e.preventDefault) e.preventDefault();
    return false;
}

function cc_popLink2(e) {
    if(!e) e = window.event;
    var o = (e.srcElement) ? e.srcElement : this;
    var strURL = o.href;
    var iWidth = (strURL.match(/[?&;]w=(\d+)/)) ? strURL.match(/[?&;]w=(\d+)/)[1] : 780;
    var iHeight = (strURL.match(/[?&;]h=(\d+)/)) ? strURL.match(/[?&;]h=(\d+)/)[1] : 500;
    cc_popup3(o.href, iWidth, iHeight, o.id);
    if(e.preventDefault) e.preventDefault();
    return false;
}

/* not currently used */
function readHTMLFile(strURL) {
    var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP"); 
    xmlhttp.open("GET", strURL, 0); 
    xmlhttp.send(""); 
    Response.Write(xmlhttp.responseText); 
    var xmlhttp = null; 
}

function popup( strURL, intW, intH, strName ) 
{var obwindow = window.open( strURL, strName, 'width='+intW+',height='+intH+',resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1' );obwindow.focus();obwindow.moveTo(50,50);}

function popup2( strMsg, strURL, intW, intH, strName ) 
{if (confirm(strMsg)) {var obwindow = window.open( strURL, strName, 'width='+intW+',height='+intH+',resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1' );obwindow.focus();obwindow.moveTo(50,50);}}

function ValidateForm(TheForm){
	var msg="-----------------------------------------------\n     * Email address validation error\n-----------------------------------------------\n";
	var msg2="\nYou must include an accurate email address for a response.\n\nPlease verify that your email address is valid.";
	var msg3="\n\nEmail address should be in the following format: \nexample@example.com"
	if (EmailCheck(trimString(TheForm.email.value))){
		if ( TheForm.PostCode ) {if ( trimString(TheForm.PostCode.value).length > 0 ) {if ( validPostcode(TheForm.PostCode) ) {return true;} else {return false;}}} else {return true;}
		}else{alert(msg + msg2 + msg3);TheForm.email.value="";TheForm.email.focus();return false;}
 }

function EmailCheck(src) {
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(src);
  }

function trimString(strString){
	//trim trailing spaces
	
	while (strString.charAt(strString.length-1)==' ')
	{strString=strString.substring(0,strString.length-1);}
	//trim leading spaces
	while (strString.charAt(0)==' ')
	{strString=strString.substring(1,strString.length);}
	return strString;
}

function borders ()
{//Temp Fix //Len is too long
var d=document.all;var l=d.length;for ( var i=0; i < l ; i++)if(d[i].tagName=='DIV'){s=d[i].style;if(s.p){void(s.border=s.p);void(s.p=null)}else{void(s.border='0px');}}
}

function validateCheck(formval){
if (!validPostcode(formval.postcode))
	{return false;}
else
{
formval.btn_submit.disabled=true; 
formval.btn_submit.value='wait...';
return true;}
}
function validateBB2 ( Obj )
{if (Obj.value == 0){alert('Please select a bestbuy from the list.');return false;} document.frmLanding.submit();return true;}

function validateBB3 ( Obj )
{if (Obj.value == 0){alert('Please select a provider from the list.');return false;} document.frmLanding.submit();return true;}

function validateBestBuys ( frm )
{if (frm.typeid.value == 0){alert('Please select a bestbuy from the list.');return false;}return true;}

function validateBestBuys2 ( frm )
{if (frm.ProviderID.value == 0){alert('Please select a provider from the list.');return false;}return true;}

function validateCheckCalc( frm ){
	if (!validPostcode(frm.postcode)) {return false;}else{
		//check for valid radio selection
		var go = false;
		if (frm.PTID) {	
			var i = 0;
			for (i = 0; i < frm.PTID.length; i++){if (frm.PTID[i].checked) {go = true;}}
		}else{go = true;}
		if (go) {frm.btn_submit.disabled=true; frm.btn_submit.value='wait...';return true;
		}else{alert('Please select an option');return false;}
	}
}

function validateEmailFriend(form) {
	var error = "";

			if (form.email1) {
				if (trimString(form.email1.value) == "") {error += "* Please enter an email address in E-mail One. \n";} else {
					if ( EmailCheck( trimString(form.email1.value) ) == false ) {error += "* Please enter a valid email address in E-mail One. \n";}
				}
			}

			if (form.email2) {
				if (trimString(form.email2.value) != "") {
					if ( EmailCheck( trimString(form.email2.value) ) == false ) {error += "* Please enter a valid email address in E-mail Two. \n";}
				}
			}
			
			if (form.email3) {
				if (trimString(form.email3.value) != "") {
					if ( EmailCheck( trimString(form.email3.value) ) == false ) {error += "* Please enter a valid email address in E-mail Three. \n";}
				}
			}

			if (form.yourname) {
				if ( trimString(form.yourname.value) == "" ) {error += "* Please enter your name. \n";} else {
					if ( trimString(form.yourname.value) < 2 ) {error += "* Your name must be at least 2 characters long. \n";} else {
					if ( trimString(form.yourname.value) > 50 ) {error += "* Your name must be no more than 50 characters long. \n";}
				}
				}
			}
			
			if (form.youremail) {
				if (trimString(form.youremail.value) == "") {error += "* Please enter your email address. \n";} else {
					if ( EmailCheck( trimString(form.youremail.value) ) == false ) {error += "* Please enter a valid email address in Your E-mail. \n";}
				}
			}
			
			if (form.yourmessage) {
				if ( trimString(form.yourmessage.value) != "" ) {
					if ( trimString(form.yourmessage.value).length < 10 ) {error += "* Your message must be at least 10 characters long. \n";} else {
					if ( trimString(form.yourmessage.value).length > 300 ) {error += "* Your message must be no more than 300 characters long. \n";}
				}
				}
			}
			

			if (error != "")
			{
				var msg="-------------------------------------------------------------------\n                      Form validation error\n-------------------------------------------------------------------\n";
				alert(msg + error);
				return (false);
			} else {
				return confirm('Are you sure?');
			}

}

function validateHF(form) {

	var error = "";
	if (form.LinkText) {
		if (trimString(form.LinkText.value) == "") {error += "* Please enter a Link Text. \n";}
	}
	if (form.LinkAlt) {
		if (trimString(form.LinkAlt.value) == "") {error += "* Please enter a LinkAlt. \n";}
	}
	if (form.NonRewriteURL) {
		if (trimString(form.NonRewriteURL.value) == "") {error += "* Please enter a NonRewriteURL. \n";}
	}
	if (form.RewriteURL) {
		if (trimString(form.RewriteURL.value) == "") {error += "* Please enter a RewriteURL. \n";}
	}

	if (error != "")
	{
		var msg="-------------------------------------------------------------------\n                      Form validation error\n-------------------------------------------------------------------\n";
		alert(msg + error);
		return (false);
	} else {
		return confirm('Are you sure?');
	}
}

function validateSpeedTester (form)
{
    var error = "";
    
    if (form.ProviderID) {
	if (form.ProviderID.value == "0" )  {error += "* Please select your Internet Service Provider \n"}
    }
    
    if (form.DownLimitID) {
	if (form.DownLimitID.value == "0")  {error += "* Please select the speed your package is MEANT to be. \n"}
    }
    
    if (form.Email) {
        if (form.Email.value.length != 0 ) {
	    var checkEM = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	    if ( !form.Email.value.match(checkEM) ) {error += "* Please enter a valid email address\n"}
        }
    }
    
    if (form.PostCode) { if (form.PostCode.value != "") { if (validPostcodeST(form.PostCode) == false){error += "* Please enter a valid postcode \n";}}}
    
    if (error != "")
    {
	    var msg="-------------------------------------------------------------------\n                      Form validation error\n-------------------------------------------------------------------\n";
	    alert(msg + error);
	    return (false);
    } else {
	    return (true);
    }	
}
 
function dtlEventTracking(eventCategory, eventAction, eventLabel, eventValue){
	  
	try {

		var lclEventValue = parseInt(eventValue);
		pageTracker._trackEvent(eventCategory, eventAction, eventLabel, lclEventValue);
	} 

	catch(err) 

	{
		pageTracker._trackEvent(eventCategory, eventAction, eventLabel) 

	} 
	
}