function phonovationValidation(thisform) {
// alert(thisform);
    var mobileField = eval("document." + thisform + ".mobile");
    var mobileValue = mobileField.value;

    var carrierField = eval("document." + thisform + ".carrier");
    var carrierValue = carrierField.value;

    var formname = eval("document." + thisform);

    var errortrue = 0
    var errormsg1 = ""
    var errormsg1a = ""
    var errormsg1b = ""
    var errormsg2 = ""

    var ireland=0
    var uk=0


    if (mobileValue == "353871234567 (example)") { 
        errortrue = 1;
        errormsg1b = "Please enter your real mobile phone number."
    } 

    if (mobileValue.length < 9) { 
        errortrue = 1;
        errormsg1 = "You must enter the full international mobile number: all numerals, no spaces, beginning with 353 (Ireland) or 44 (UK)."
    } 

    if (  
        (mobileValue.charAt(0) == "3") && (mobileValue.charAt(1) == "5") && (mobileValue.charAt(2) == "3") 
        ) {
        ireland=1
        }
        
    if (  
        (mobileValue.charAt(0) == "4") && (mobileValue.charAt(1) == "4") 
        ) {
        uk=1
        }

    if (  (ireland == 0) && (uk == 0)
        ) {
  
        errortrue = 1;
        errormsg1a = "We only support Ireland and UK mobile numbers (your number must start with 353 or 44)."

    } 
    
    if (carrierValue == "nocarrier") { 
        errortrue = 1;
        errormsg2 = "You must select a mobile carrier (Vodaphone, O2, Meteor, 3)."
    } 

    if (errortrue == 1) {
        alert(errormsg1 + '\n' + errormsg1a + '\n' + errormsg1b + '\n' + errormsg2);
        return false;    
    }

    else {
        formname.submit();

   return true;
    }
}


function checkSearch() {
    var companyField = document.SearchForm.Company;
    var companyValue = companyField.value;

    var keywordField = document.SearchForm.Keywords;
    var keywordValue = keywordField.value;

    var locationField = document.SearchForm.Location;
    var locationValue = locationField.value;

    var categoryField = document.SearchForm.CategoryType;
    var categoryValue = categoryField.value;



    if (
        ( (keywordValue == "") && (companyValue == "") && (locationValue <= 0) && (categoryValue <= 0))
    ) 
        {

            alert("You haven't yet selected anything to search for. \n Try a company name, or a keyword, or a \n search category, or even a town or a group of towns.");
        return false;

    } else {

   return true;
    }
}

function Expand(item) {
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
   if (visible) {
     obj.style.display="none";
   } else {
      obj.style.display="block";
   }
}

function Display(item) {
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
   if (visible) {

   } else {
      obj.style.display="block";
   }
}

function hideMe(name) {
    var obj = document.getElementById(name);
    obj.style.display = "none";
    }

function showMe(name) {
    var obj = document.getElementById(name);
    obj.style.display = "block";
    }    
    
function CheckCity() {
            var cityValue = document.Upload.City.options.selectedIndex;

                obj1=document.getElementById('cityinfo1');

                // alert(cityValue);

            if (cityValue == '0') { // Cork City

                obj1.style.display="block";

                return;

            }
}


function CheckUS() {
            var countryValue = document.Upload.Country.options.selectedIndex;
            var districtValue = document.Upload.District.value;

                obj1=document.getElementById('stateinfo1');
                obj2=document.getElementById('stateinfo2');

                // alert(countryValue);

            if (countryValue == '222') { // US United States

                obj1.style.display="none";
                obj2.style.display="block";

                return;

            } else {

                obj2.style.display="none";
                obj1.style.display="block";

                return;

            }
}


function checkuserid() {
                // alert(thisuserid);

            if (document.Upload.userid.value.length < 3) {
                alert("Used ID must be at least 3 characters");
                return ;
            }
}


function checkpassword() {
            var thispassword = document.Upload.setpassword.value;
            var thispasswordField = document.Upload.setpassword;

                // alert(thispassword);

            if (thispassword.length < 3) {

                alert("Password must be at least 3 characters");
                thispasswordField.focus();
                return;
            }
}

function checkEmail() {
    var emailField = document.Upload.Email;
    var emailValue = emailField.value;
    if (emailValue == '') {
        alert("You must enter your email address!");
        emailField.focus();
        return;
    } else if (emailValue.indexOf("@") == -1) {
        alert("You must enter a valid email address!\n\n(i.e. address@company.com)");
        emailField.focus();
        emailField.select();
        return;
    }
}

function submitandcheck() {

        if (document.Upload.userid.value.length < 3) {
            alert("Used ID must be at least 3 characters");
            document.Upload.userid.focus();
            document.Upload.userid.select();
            return ;
        } else if (document.Upload.setpassword.value.length < 3) {
            alert("Password must be at least 3 characters");
            document.Upload.setpassword.focus();
            document.Upload.setpassword.select();
            return ;
        } else if (document.Upload.Email.value == '') {
            alert("You must enter your email address!");
            document.Upload.Email.focus();
            return;
        } else if (document.Upload.Email.value.indexOf("@") == -1) {
            alert("You must enter a valid email address!\n\n(i.e. address@company.com)");
            document.Upload.Email.focus();
            document.Upload.Email.select();
            return;
        } else {
        document.forms.Upload.submit();
        }
}

function packagesubmitandcheck() {

    if (document.Upload.listingtype[0].checked == 0) {    // not "Basic"
        for (var i=1; i < document.Upload.listingtype.length; i++) {
        
            if (document.Upload.listingtype[i].checked) {                
            
                checkindex = "document.Upload.paymentplan" + i;
            
                if (eval(checkindex)[0].checked == 0 && eval(checkindex)[1].checked == 0){
            
                    alert("You must select a payment plan for the " + document.Upload.listingtype[i].value + " account.");  
                    return true;
                }
            } 
        } 
    }
    
     else if (document.Upload.OrganizationWorkflow.value == "") {
        alert("You must specify a TeleResearch Workflow step.");
        return true;
    }
    return false;
}

function companysubmitandcheck() {

    if (document.Upload.Company.value.length < 1) {
        alert("Please enter your company name; this is a required field.");
        hideMe('eirebizcentral');hideMe('companyprofile');hideMe('cataloguepage');showMe('accountinfo');hideMe('subscriptions');        
        document.Upload.Company.focus();
        document.Upload.Company.select();
        return true;   
    } else if (document.Upload.LocationID.value == 0) {
    alert("You must click the Pick Your Location button and choose a location.");
    hideMe('eirebizcentral');hideMe('companyprofile');hideMe('cataloguepage');showMe('accountinfo');hideMe('subscriptions'); 
    return true;
    } else if (document.Upload.authcontactname.value.length < 1) {
        alert("Please enter the full name of the authorised contact for this account; this is a required field.");
        hideMe('eirebizcentral');hideMe('companyprofile');hideMe('cataloguepage');showMe('accountinfo');hideMe('subscriptions'); 
        document.Upload.authcontactname.focus();
        document.Upload.authcontactname.select();
        return true;            
    } else if (document.Upload.userid.value.length < 3) {
        alert("Used ID must be at least 3 characters");
        hideMe('eirebizcentral');hideMe('companyprofile');hideMe('cataloguepage');showMe('accountinfo');hideMe('subscriptions'); 
        document.Upload.userid.focus();
        document.Upload.userid.select();
        return true;
    } else if (document.Upload.setpassword.value.length < 3) {
        alert("Password must be at least 3 characters");
        hideMe('eirebizcentral');hideMe('companyprofile');hideMe('cataloguepage');showMe('accountinfo');hideMe('subscriptions'); 
        document.Upload.setpassword.focus();
        document.Upload.setpassword.select();
        return true;              
    } else if (document.Upload.listingtype[0].checked == 0) {    // not "Basic"
        for (var i=1; i < document.Upload.listingtype.length; i++) {
    
            if (document.Upload.listingtype[i].checked) {                
    
                checkindex = "document.Upload.paymentplan" + i;
    
                if (eval(checkindex)[0].checked == 0 && eval(checkindex)[1].checked == 0){
    
                    alert("You must select a payment plan for the " + document.Upload.listingtype[i].value + " account.");  
                    return true;
                }
            } 
        } 
    }
    return false;
}

function minimalcompanysubmitandcheck() {

    if (document.Upload.Company.value.length < 1) {
        alert("Please enter your company name; this is a required field.");
        document.Upload.Company.focus();
        document.Upload.Company.select();
        return true;   
//    } else if (document.Upload.LocationID.value == 0) {
//    alert("You must click the Pick Your Location button and choose a location.");
//    return true;
    } else if (document.Upload.authcontactname.value.length < 1) {
        alert("Please enter the full name of the authorised contact for this account; this is a required field.");
        document.Upload.authcontactname.focus();
        document.Upload.authcontactname.select();
        return true;            
//    } else if (document.Upload.userid.value.length < 3) {
//        alert("Used ID must be at least 3 characters");
//        document.Upload.userid.focus();
//        document.Upload.userid.select();
//        return true;
//    } else if (document.Upload.setpassword.value.length < 3) {
//        alert("Password must be at least 3 characters");
//        document.Upload.setpassword.focus();
//        document.Upload.setpassword.select();
//        return true;  
    } else if (document.Upload.listingtype[0].checked == 0) {    // not "Basic"
        for (var i=1; i < document.Upload.listingtype.length; i++) {
    
            if (document.Upload.listingtype[i].checked) {                
    
                checkindex = "document.Upload.paymentplan" + i;
    
                if (eval(checkindex)[0].checked == 0 && eval(checkindex)[1].checked == 0){
    
                    alert("You must select a payment plan for the " + document.Upload.listingtype[i].value + " account.");  
                    return true;
                }
            } 
        } 
    }
    return false;
}


function checkForm() {
    var emailField = document.CustomerRegistrationForm.PrimaryEmail;
    var emailValue = emailField.value;
    if (emailValue == '') {
        alert("You must enter your email address!");
        emailField.focus();
        return;
    } else if (emailValue.indexOf("@") == -1) {
        alert("You must enter a valid email address!\n\n(i.e. address@company.com)");
        emailField.focus();
        emailField.select();
        return;
    }
    var fieldValue = "";
    var len = 2;
    for (var n=1; n <= len; n++) {
        var dml = eval("document.CustomerRegistrationForm.ItemID" + n);
        for (var p=0; p < dml.length; p++) {
            if (dml[p].checked) {
                if (fieldValue != "") {
                    fieldValue += ",";
                }
                fieldValue += dml[p].value;
            }
        }
    }
    document.CustomerRegistrationForm.ItemID.value = fieldValue;
    document.CustomerRegistrationForm.submit();
}

var isNav, isIE;
var coll = "";
var styleObj = "";
var x=0
var y=0    

if (parseInt(navigator.appVersion) >= 4) {
    if (navigator.appName == "Netscape") {
        isNav = true;
    } else {
        isIE = true;
        coll = "all.";
        styleObj = ".style";           

    }
}


function showMeCenter(name,linkid,anchorid) {


            var obj = document.getElementById(name).style;
            var linkobj = document.getElementById(linkid);
            var objt = document.getElementById(name);
    
        if (document.body.scrollTop < 200) {

        location.hash=anchorid;
        }

       //    linkobj.onclick=getEvent

       //    linkobj.onmouseover=centerMe


            //    x=event.x; //relative to currently viewable area
            //    y=event.y;

                var a= document.body.clientWidth // the window
                var b= document.body.clientHeight

                var r= objt.clientWidth  // BUG: the div starts at 0 because display:none
                var s= objt.clientHeight  // BUG: the div starts at 0 because display:none

                var l= document.body.scrollLeft  // the scrollbar
                var m= document.body.scrollTop


         //    alert('x is ' + x +'y is ' + y);
          //   alert('a is ' + a +'b is ' + b);
           //  alert('r is ' + r +'s is ' + s);
          //   alert('l is ' + l +'m is ' + m);


            toppos = Math.round((b/2)-(s/2)+(m))
            leftpos = Math.round((a/2)-(r/2)+(l))


                if (isIE) {
                obj.pixelLeft = leftpos
                obj.pixelTop = toppos
                } else {
                obj.left = leftpos
                obj.top = toppos
                }

                obj.display = "block";

        x=0;
        y=0;

        return false;



}
    
    

function showMe2(name,linkid,anchorid) {


            var obj = document.getElementById(name).style;
            var linkobj = document.getElementById(linkid);
            var objt = document.getElementById(name);
            var shimname = name + "shim"
            var objshim=document.getElementById(shimname).style;

            linkobj.onmousedown=getEvent

       //    linkobj.onmouseover=centerMe


            //    x=event.x; //relative to currently viewable area
            //    y=event.y;

                var a= document.body.clientWidth // the window
                var b= document.body.clientHeight

           //     var r= objt.clientWidth  // the div
           //     var s= objt.clientHeight

                var l= document.body.scrollLeft  // the scrollbar
                var m= document.body.scrollTop


           //  alert('x is ' + x +'y is ' + y);
          //   alert('a is ' + a +'b is ' + b);
          //   alert('r is ' + r +'s is ' + s);
          //   alert('l is ' + l +'m is ' + m);

if (x > 1) {

            var s= document.body.scrollTop

            toppos = y + 10 + s;
            leftpos = x

                if (isIE) {
                obj.pixelLeft = leftpos
                obj.pixelTop = toppos
                } else {
                obj.left = leftpos
                obj.top = toppos
                }
                // obj.visibility = "visible";
                // obj.overflow = "visible";

                obj.display = "block";

                if (isIE) {
                objshim.pixelLeft = leftpos
                objshim.pixelTop = toppos
                } else {                
                objshim.left = leftpos
                objshim.top = toppos
                }
                // objshim.visibility = "visible";
                // objshim.overflow = "visible";
                objshim.display = "block";
                
            }
x=0;
y=0;

return;

}


    //used when there is no shim
function showMe3(name,linkid,anchorid) {


            var obj = document.getElementById(name).style;
            var linkobj = document.getElementById(linkid);
            var objt = document.getElementById(name);


            linkobj.onmousedown=getEvent

       //    linkobj.onmouseover=centerMe


            //    x=event.x; //relative to currently viewable area
            //    y=event.y;

                var a= document.body.clientWidth // the window
                var b= document.body.clientHeight

         //       var r= objt.clientWidth  // the div
         //       var s= objt.clientHeight

                var l= document.body.scrollLeft  // the scrollbar
                var m= document.body.scrollTop


           //  alert('x is ' + x +'y is ' + y);
          //   alert('a is ' + a +'b is ' + b);
          //   alert('r is ' + r +'s is ' + s);
          //   alert('l is ' + l +'m is ' + m);

if (x > 1) {

            var s= document.body.scrollTop

                      if (isIE) {
                            toppos = y + 60 + s;
                            
                      } else {
                            toppos = y + 60
                      }
                            leftpos = x

                if (isIE) {
                obj.pixelLeft = leftpos
                obj.pixelTop = toppos
                } else {
                obj.left = leftpos
                obj.top = toppos
                }

                obj.display = "block";
                location.hash=anchorid;

            }
x=0;
y=0;

return;

}


function getEvent(evt) {


    if (isIE) {
   //     x=event.x; // returns the coords within an image if on an image
   //     y=event.y; // returns the coords within an image if on an image
   
          x=event.clientX;
          y=event.clientY;
   
    } 
    else {


      x=evt.pageX; 
      y=evt.pageY;
    }


      //  alert('x is ' + x + ' y is ' + y);
    return false;

}



function centerMe(name) {

//alert('foo');
    var obj = document.getElementById(name).style;
    var objt = document.getElementById(name);

    var r= objt.clientWidth  // the div
    var s= objt.clientHeight

    var l= document.body.scrollLeft  // the scrollbar
    var m= document.body.scrollTop

    toppos = Math.round((b/2)-(s/2)+(m))
    leftpos = Math.round((a/2)-(r/2)+(l))

obj.pixelLeft = leftpos  
obj.pixelTop = toppos
                

}  

    
// the remaining are not used


function getXY(e) {
    if (isNav) {

        x=e.pageX; 
        y=e.pageY;
    }
    if (isIE&&document.all) {


        x=event.x; 
        y=event.y;
        alert('x is ' + x +'y is ' + y);
        
        
        
    }
    
    if (isIE&&!document.all) {

        x=e.pageX; 
        y=e.pageY;
    }


}    

// CheckRequiredFields
//  Checks that the user entered something in the given required fields.
//  The first argument is the form and the remaining arguments (as many as
//  needed) are the names of the required fields.
//  Use as on submit routine for the form. Example:
//      <form action="scripts/client_input.cgi" method="POST"
//          onSubmit='return CheckRequiredFields(this, "firstname", "lastname", "Title");'>
// Author: Joan Walton, Specific Impulse Inc. December 1999

function CheckRequiredFields(theForm) {
    for (var i=1; i < CheckRequiredFields.arguments.length; i++) {
        if (eval("theForm." + CheckRequiredFields.arguments[i] +
                ".value.length") == 0) {
            alert("Please enter your " + CheckRequiredFields.arguments[i]);
            return false;
        }
    }
    return true;
}


function delayRedirect() {
    setTimeout('document.location.href="index.cfm"', '4000');
}

function hiLite(imgName,imgArrayName) {
        document.images[imgName].src = eval(imgArrayName + ".src");
}

function fillIn(this_field_name, target_field_name)  {
        target_field_name.value = this_field_name.value
}

var newWindow

 function openWin(myWin)  {
    if (!newWindow || newWindow.closed) {
    newWindow = window.open(myWin,"Mywindow","scrollbars,resizable=yes,height=550,width=650")
    } else {
    newWindow.focus();
    newWindow.location.href=myWin;
    }
    return true;
}


var smallWindow

 function openSmallWin(mySmallWin)  {
    if (!smallWindow || smallWindow.closed) {
    smallWindow = window.open(mySmallWin,"mysmallwindow","scrollbars,resizable=yes,height=150,width=400")
    } else {
    smallWindow.focus();
    smallWindow.location.href=mySmallWin;
    }
    return true;
}


var introWindow

 function openIntroWin(myIntroWin)  {
    if (!introWindow || introWindow.closed) {
    introWindow = window.open(myIntroWin,"myintroWindow","scrollbars,resizable=yes,height=350,width=450")
    } else {
    introWindow.focus();
    introWindow.location.href=myIntroWin;
    }
    return true;
}


//<!-- Original:  Martin Webb (martin@irt.org) -->

// <!-- This script and many more are available free online at -->
// <!-- The JavaScript Source!! http://javascript.internet.com -->

//  function right(e) {
//  if (navigator.appName == 'Netscape' &&
//  (e.which == 3 || e.which == 2))
//  return false;
//  else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {/ alert("Sorry, you do not have permission to right click."); return false; } return true; }

//  document.onmousedown=right;
//  document.onmouseup=right;
//  if (document.layers) window.captureEvents(Event.MOUSEDOWN);
//  if (document.layers) window.captureEvents(Event.MOUSEUP);
//  window.onmousedown=right;
//  window.onmouseup=right;


function showMeCenterOLD(name,linkid,anchorid) {

    if (isIE&&document.all) {

            var obj = document.getElementById(name).style;
            var linkobj = document.getElementById(linkid);
            var objt = document.getElementById(name);
    
        if (document.body.scrollTop < 200) {

        location.hash=anchorid;
        }

       //    linkobj.onclick=getEvent

       //    linkobj.onmouseover=centerMe


            //    x=event.x; //relative to currently viewable area
            //    y=event.y;

                var a= document.body.clientWidth // the window
                var b= document.body.clientHeight

                var r= objt.clientWidth  // the div
                var s= objt.clientHeight

                var l= document.body.scrollLeft  // the scrollbar
                var m= document.body.scrollTop


         //    alert('x is ' + x +'y is ' + y);
          //   alert('a is ' + a +'b is ' + b);
          //   alert('r is ' + r +'s is ' + s);
          //   alert('l is ' + l +'m is ' + m);


            toppos = Math.round((b/2)-(s/2)+(m))
            leftpos = Math.round((a/2)-(r/2)+(l))

                obj.pixelLeft = leftpos  
                obj.pixelTop = toppos

                obj.display = "block";

        x=0;
        y=0;

        return false;

    }
    
    else {
    
    location.href='directory_source.cfm';
    
//    alert('not ie')
    return true;
    
    }
}

function clearSelections(item) {
var mySelect = document.getElementById(item);
for (var i=0; i < mySelect.length; i++) 
    mySelect.options[i].selected=false;
}

function pickBusCats(item) {
var mySelect = document.getElementById(item);
var categoryList = "";
for (var i=0; i < mySelect.length; i++) 
    if (mySelect.options[i].selected) {
        var tempVal = mySelect.options[i].value;
        if (categoryList == "") 
            categoryList = tempVal;
        else
            categoryList += "," + tempVal;
    }
document.getElementById("CategoryType").value = categoryList;
//alert(categoryList)
}

function pickLocations(item) {
var mySelect = document.getElementById(item);
var locationList = "";
for (var i=0; i < mySelect.length; i++) 
    if (mySelect.options[i].selected) {
        var tempVal = mySelect.options[i].value;
        if (locationList == "") 
            locationList = tempVal;
        else
            locationList += "," + tempVal;
    }
document.getElementById("Location").value = locationList;
//alert(document.getElementById("Location").value)
}    
