//template functions - do not remove
//----------------------------------
/*
function checkSearchString(f){
        var r, re;
        re = new RegExp("[#&£$]");
        r = f.match(re);
        if(r=="#" || r == "&" || r == "£" || r == "$"){
                alert("Please do not include the character " + r + " within your search");
                return false;
        }
        else
        {
                return true;
        }
}
*/

function checkIncidentSearchCallRef(f){
        var r, re;
        re = new RegExp("[^0-9]");
        r = f.match(re);
        if(r!=null){
                alert("Please only include numbers in the Call Reference field");
                return false;
        }
        else
        {
                return true;
        }
}

function checkSearchString(f){
        if (f.length == 1){
                alert("Please ensure that your search is for more than one character")
                f.value = "";
        }
        else
        {
                var r, re;
                re = new RegExp("[^a-zA-Z0-9' .]");
                r = f.match(re);
                if(r!=null){
                        alert("Please only include the characters 0-9 and a-z in your search");
                        return false;
                }
                else
                {
                        return true;
                }
        }
}

function checkQuickSearch(f){
    if (f.txtQuickSearch.value == "" || f.txtQuickSearch.value == "Enter search text:"){
        alert("You cannot submit a blank search");
        }
    else{
    if(checkSearchString(f.txtQuickSearch.value) == true){
                var searchString;
                if(f.txtQuickSearch.value.indexOf(".") > -1){
                        if(f.txtQuickSearch.value.charAt(0) != "0"){
                                searchString = "0" + f.txtQuickSearch.value;
                        }
                        else
                        {
                                searchString = f.txtQuickSearch.value;
                        }
                }
                else
                {
                        searchString = f.txtQuickSearch.value;
                }
                if (f.cboSearch.value == "all"){
                    window.location.href="/search.asp?submit=search&stype=1&pterm=" + searchString + "&last=11&Term=" + searchString + "&qlink=" + f.allCols.value + "~dt=an~qt=" + searchString + "~rf=0";
                    }
                else{
                    window.location.href="/search.asp?submit=search&pterm=" + searchString + "&last=11&Term=" + searchString + "&qlink=~col=" + f.cboSearch.value + "~dt=an~qt=" + searchString + "~rf=0";
                }
        }
    }
}

function checkSearch(f){
    if (f.txtSearch.value == "" || f.txtSearch.value == "Enter search text:"){
        alert("You cannot submit a blank search");
        }
    else{
    if(checkSearchString(f.txtSearch.value) == true){
                var searchString;
                if(f.txtSearch.value.indexOf(".") > -1){
                        if(f.txtSearch.value.charAt(0) != "0"){
                                searchString = "0" + f.txtSearch.value;
                        }
                        else
                        {
                                searchString = f.txtSearch.value;
                        }
                }
                else
                {
                        searchString = f.txtSearch.value;
                }
                if (f.cboSearch.value == "all"){
                    window.location.href="/search.asp?submit=search&stype=1&pterm=" + searchString + "&last=11&Term=" + searchString + "&qlink=" + f.allCols.value + "~dt=an~qt=" + searchString + "~rf=0";
                    }
                else{
                    window.location.href="/search.asp?submit=search&pterm=" + searchString + "&last=11&Term=" + searchString + "&qlink=~col=" + f.cboSearch.value + "~dt=an~qt=" + searchString + "~rf=0";
                }
        }
    }
}

function checkCorpSearch(f){
        f = document.getElementById(f);
        if (f.txtSearch.value == ""){
                alert("You cannot submit a blank search");
        }
        else
        {
                if(checkSearchString(f.txtSearch.value) == true){
                        var searchString;
                        searchString = f.txtSearch.value;
                        window.location.href = "/search.asp?submit=search&last=11&Term=" + searchString + "&page=search.asp";
                }

        }
}

function checkPostcodeSearch(f){
    if (f.text_postcode.value != "" && f.text_postcode.value.length > 1){
        return true;
        }
    else{
        alert("You cannot submit a blank search.\nPlease enter your postcode.");
        return false;
    }
}

function Navigate2(f){
    if (f.txtEmail.value != ""){
        return true;
        }
    else{
        alert("You cannot submit a blank E-mail address");
        return false;
    }
}

function MM_swapImgRestore(){
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d){
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage(){
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//corporate template functions
//--------------------------

// Sets 'I need Solutions for' form action to the selected solution and submits the form
function selectSolution(obj){
        document.getElementById("solutions").action = 'content.asp?PageId=' + obj.options[obj.selectedIndex].value;
        document.getElementById("solutions").submit(document.getElementById("solutions"));
}

// Sets 'I need Events that cover' form action to the selected solution and submits the form
function selectEvent(obj){
        document.getElementById("events").action = 'content.asp?PageId=1507&productFilter=' + obj.options[obj.selectedIndex].value;
        document.getElementById("events").submit(document.getElementById("events"));
}

function Hide(obj){
        document.getElementById(obj).style.display = "none";
}

function Show(obj){
        document.getElementById(obj).style.display = "";
}

function ShowHide(obj){
        document.getElementById(obj).style.display=(document.getElementById(obj).style.display!="none")? "none" : "";
}

function getMovie(file,title){
        var so = new SWFObject(file, title, "600", "400", "7", "#a0a9bf");
        so.write("divDemo");
        document.getElementById("divDemo").style.display = "";
}

function openMovie2(){
        document.getElementById("divDemo").style.display = "";
}

function closeMovie2(page){
        var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
        if(InternetExplorer){
                window.location = "/content.asp?PageId=" + page
        }
        else{
                document.getElementById("divDemo").style.display = "none";
        }
}

//corporate find a partner functions
//----------------------------------

// This jumps the region list to the requested index number
function bp_jumpyList(num){
        document.getElementById("select_region").selectedIndex = num;
}

// Updated "jump-to region" function
function selectRegion(obj){

        var regtext = obj.options[obj.selectedIndex].text;
        var id = obj.value;

        if(id != "-1"){
                window.location = "/content.asp?PageId=1502&id=" + id + "&r=" + regtext;
        }
}

/*function selectRegion(reg,regtext){
        if(reg.value != "-1"){
                window.navigate("/content.asp?PageId=1502&id=" + reg.value + "&r=" + regtext);
        }
}*/

//references.asp (and wp_survey.asp) functions
//--------------------------------------------

function maxLength(field, countfield, maxlimit){
    // if too long...trim it!
    if (field.value.length > maxlimit){
        field.value = field.value.substring(0, maxlimit);
        }
    // otherwise, update 'characters left' counter
    else{
        countfield.value = maxlimit - field.value.length;
    }
}

function move(fbox,tbox) {
    tbox.value = "";
    var txtStr = "";
    for(var i=0; i<fbox.options.length; i++) {
        if(fbox.options[i].selected && fbox.options[i].value != "") {
            txtStr = txtStr + fbox.options[i].value + ", ";
            tbox.value = txtStr;
        }
    }
}

//reseller_app.asp functions
//--------------------------

function amendList(){
    var boxLength = document.form1.listCont.length;
    var selectedItem = document.form1.cboSoft.selectedIndex;
    var selectedText = document.form1.cboSoft.options[selectedItem].text + ", ";
    var selectedValue = document.form1.cboSoft.options[selectedItem].value;
    var i;
    var isNew = true;
    if (boxLength != 0) {
        for (i = 0; i < boxLength; i++) {
        thisitem = document.form1.listCont.options[i].text;
        if (thisitem == selectedText) {
            isNew = false;
            break;
            }
        }
    }
    if (form1.cboSoft.value != "-1"){
        if (isNew) {
            newoption = new Option(selectedText, selectedValue, false, false);
            document.form1.listCont.options[boxLength] = newoption;
            form1.listcont2.value = form1.listcont2.value + selectedText;
            }
        }
     form1.txtSoft.value = form1.listcont2.value;
}

function resetList(){
    form1.listCont.innerHTML = "";
    form1.listcont2.value = "";
    form1.txtSoft.innerHTML = "";
    form1.cboSoft.value = "-1";
}

//rsvp.asp functions
//------------------

function showColl(){
    ShowHide("colleague");
}

function moveAddress(){
    if(document.all.chkDetails.checked == true){
        if(document.all.txtCname.value != ""){
            document.all.txtCname2.value = document.all.txtCname.value;
            }
        if(document.all.txtAdd.value != ""){
            document.all.txtAdd2.value = document.all.txtAdd.value;
            }
        if(document.all.txtAdd.value != ""){
            document.all.txtPcode2.value = document.all.txtPcode.value;
            }
        if(document.all.txtAdd.value != ""){
            document.all.txtTel2.value = document.all.txtTel.value;
            }
        }
    else{
        document.all.txtCname2.value = "";
        document.all.txtAdd2.value = "";
        document.all.txtPcode2.value = "";
        document.all.txtTel2.value = "";
    }
}

function CheckChar(form){
    var chartocheck = form.value.toUpperCase();
    form.value = chartocheck;
}

//global functions
//----------------

function Accept(num){
    var newWindow;
    newWindow == window.showModalDialog("../inc/response.asp?var=" + num,"Notification","status:no;center:yes;help:no;resizable:yes;");
}

function PrintPage(src){
    var newWindow;
    if (window.showModalDialog) {
        newWindow = window.showModalDialog(src,"Notification","dialogHeight:600px;dialogWidth:650px;status:no;center:no;help:no;resizable:yes;");
        }
    else {
        newWindow = window.open(src,"msg","height=600px,width=650px,left=0,top=0,resizable=no,scrollbars=yes,location=no,toolbar=no");
    }
}

function Open(src,name,num1,num2){
    msg=window.open("","msg","height="+ num2 +",width="+ num1 +",left=0,top=0,resizable=no,scrollbars=no,location=no,toolbar=no");
    msg.document.write("<html><title>"+ name +"</title>");
    msg.document.write("<body bgcolor='white' topmargin='2px' leftmargin='2px'>");
    msg.document.write("<img src="+ src +" border='0'>");
    msg.document.write("</body></html>");
}

function emailValidate_onblur(field){
    if (field.value != ""){
        if (CheckData(field.value, "Email") == false){
        alert("The email address may be incorrect.\nPlease enter in the format 'user@company'")
        field.focus();
        }
    }
}

function GeneralNum_onblur(field){
    if (field.value != ""){
        if (CheckData(field.value, "Number") == false){
        alert("Please omit any spaces or other characters in the number")
        field.value = "";
        field.focus();
        }
    }
}

function GeneralText_onblur(field) {
    if (field.value != ""){
        if (CheckData(field.value, "String") == false){
        alert("An invalid character has been entered")
        field.value = "";
        field.focus();
        }
    }
}

function GeneralDate_onblur(field) {
    if (field.value != ""){
        if (CheckData(field.value, "Date") == false){
        alert("An invalid date has been entered\n Please enter the date as dd/mm/yyyy")
        field.value = "";
        field.focus();
        }
    }
}

function Mid(str,start,len){
/**
    IN: str - the string we are LEFTing
        start - our string's starting position (0 based!!)
        len - how many characters from start we want to get

    RETVAL: The substring from start to start+len
**/
    // Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";

    var iEnd, iLen = String(str).length;
    if (start + len > iLen){
        iEnd = iLen;
        }
    else{
        iEnd = start + len;
    }
    return String(str).substring(start,iEnd);
}