var currentUrl = window.location.href;
//alert(currentUrl.indexOf("www.kingcentre.com"));
if (currentUrl.indexOf("www.kingcentre.com")!=-1){
	//re = /www.kingcentre.com/gi;
    //currentUrl = currentUrl.replace(re,"www.theprofessionalcentre.com");
    //alert(currentUrl);
    //window.location.href = currentUrl;
    window.location.href = "http://www.theprofessionalcentre.com";
}

/* start generic functions */
function isnArray() {
    argnr=isnArray.arguments.length
    for (var i=0;i<argnr;i++) {
        this[i+1] = isnArray.arguments[i];
    }
}
/* end generic functions */

var todaysDateStr = "";
var isnMonths=new isnArray("January","February","March","April","May","June","July","August","September","October","November","December");

today=new Date();
todaysDateStr = isnMonths[today.getMonth()+1]+" "+today.getDate()+", "+" "+getFullYear(today);
//document.write(isnMonths[today.getMonth()+1]+" "+today.getDate()+", "+" "+getFullYear(today));

/* start interface JS */
function buttonRolloverOn(whatButton) {
    buttonSrc = eval("document.images['" + whatButton + "'].src");
    buttonSrc = buttonSrc.replace("_off.","_on.");
    document.images[whatButton].src = buttonSrc;
}

function buttonRolloverOff(whatButton) {
    buttonSrc = eval("document.images['" + whatButton + "'].src");
    buttonSrc = buttonSrc.replace("_on.","_off.");
    document.images[whatButton].src = buttonSrc;
}
/* end interface JS */

/* start date functions */
function getFullYear(d) {
    var y = d.getYear();
    if (y < 1000) y += 1900;
    return y;
}

function populateDates(whatForm,whatMonth) {
    thisForm = whatForm;
    if (whatMonth == 0 || whatMonth == 2 || whatMonth == 4 || whatMonth == 6 || whatMonth == 7 || whatMonth == 9 || whatMonth == 11) {
        makeDates(thisForm,31);
    }else if (whatMonth == 3 || whatMonth == 5 || whatMonth == 8 || whatMonth == 10) {
        makeDates(thisForm,30);
    }else{
        //if (isLeapYear(getFullYear(today))){
        if (isLeapYear(thisForm.year.options[thisForm.year.options.selectedIndex].value)){
            makeDates(thisForm,29);
        }else{
            makeDates(thisForm,28);
        }
    }
}

function isLeapYear(whatYear) {
    if ((whatYear % 4 == 0) && (whatYear % 100 != 0) || (whatYear % 400 == 0)){
        return true;
    }else{
        return false;
    }
}

function makeDates(whatForm,howManyDays) {
    tempStr = "";
    thisForm = whatForm;
    thisForm.day.options.length = 0;
    for (var x = 0;x<howManyDays;x++){
        thisForm.day.options[x] = new Option(x+1,x+1,false,false);
    }
}

function setCurrentDate() {
    document.forms[0].month.options.selectedIndex = today.getMonth();
    document.forms[0].day.options.selectedIndex = today.getDate() - 1;
    /*if (2003 - getFullYear(today) < 2) {
        document.forms[0].year.options.selectedIndex = 2003 - getFullYear(today);
    }else{
        document.forms[0].year.options.selectedIndex = 0;
    }*/
    document.forms[0].year.options.selectedIndex = getFullYear(today) - 2009;
}
/* end date functions */

/* start form validation functions */
function validateForm() {
    /* first, we validate the individual elements. if things are missing, alert the user.
    if everything is okay, then copy the contents of the form to the second form and
    submit it. */
    userForm = document.forms[0];
    errorMessage = "";
    errorMessage += checkName(userForm.realname.value);
    errorMessage += checkEmail(userForm.email.value);
    errorMessage += checkPhone(userForm.phoneNumber.value);
    errorMessage += checkPCs(userForm.numberOfPCs.value);
    if (errorMessage != ""){
        errorMessage = "Sorry, there are some problems with your information. Please correct your information and re-submit the form.\n\n" + errorMessage;
        alert(errorMessage);
        return false;
    }else{
        
        /*document.forms[1].elements[3].value = userForm.fromEmail.value;*/
        compiledInfoStr = "";
        compiledInfoStr += "Contact Name - " + userForm.realname.value + "\n";
        compiledInfoStr += "Email address - " + userForm.email.value + "\n";
        compiledInfoStr += "Phone number - " + userForm.phoneNumber.value + " Ext. " + userForm.phoneNumberExt.value + "\n";
        var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
        compiledInfoStr += "Space required - " + monthArray[parseInt(userForm.month.options[userForm.month.options.selectedIndex].value)] + " " + userForm.day.options[userForm.day.options.selectedIndex].value + ", " + userForm.year.options[userForm.year.options.selectedIndex].value + "\n";
        compiledInfoStr += "Number of employees - " + userForm.numberOfEmployees.options[userForm.numberOfEmployees.options.selectedIndex].value + "\n";
        if (userForm.highSpeed[0].checked=="1"){
            var highSpeed = "Yes";
        }else{
            var highSpeed = "No";
        }
        compiledInfoStr += "High Speed Internet Access required - " + highSpeed + "\n";
        compiledInfoStr += "Number of PCs - " + userForm.numberOfPCs.value + "\n";
        compiledInfoStr += "Additional comments/questions - " + userForm.additionalComments.value;
        userForm.compiledInformation.value = compiledInfoStr;
        return true;
    }
}

function checkName(strng) {
    var error = "";
    if (strng.length == 0) {
        error = "Please enter your name.\n"
    }
    return error;     
}

function checkEmail(strng) {
    var error="";
    if (strng == "") {
        error = "Please enter an email address.\n";
    }
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }else{
        //test email for illegal characters
        var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (strng.match(illegalChars)) {
            error = "The email address contains illegal characters.\n";
        }
    }
    return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone(strng) {
    var error = "";
    if (strng == "") {
        error = "Please enter a phone number.\n";
    }
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.";
    }
    if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
    return error;
}

function checkPCs(strng) {
    var error = "";
    if (strng.length == 0) {
        error = "Please enter the number of PCs you have.\n"
    }
    return error;     
}

// valid selector from dropdown list

function checkDropdown(choice) {
    var error = "";
    if (choice == 0) {
        error = "You didn't choose an option from the drop-down list.\n";
    }    
    return error;
} 
/* end form validation functions */