﻿var xmlHttp;
var mymXmlHttp;

function CreateXmlHttpObject() {
    var objXMLHttp = null
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp
}


function moveArchive(dir) {
    xmlHttp = CreateXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support AJAX");
        return;
    }

    archiveDate = document.getElementById("currentArchiveDate").value;

    if (archiveDate == '') {
        archiveDate = '01/01/2001';
    }
    
    xmlHttp.onreadystatechange = moveArchive_stateChanged;
    xmlHttp.open("GET", "includes/ajaxresponse.asp?archiveDate=" + archiveDate + "&dir=" + dir, true);
    xmlHttp.send(null);
}

function moveArchive_stateChanged() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

        document.getElementById("archiveContent").innerHTML = xmlHttp.responseText;
    }
}

function checkEmail() {

    var email = document.getElementById("frmEmail").value;
    var name = document.getElementById("frmName").value;

    var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

    if (name.length == 0) {
        alert('please enter your name.');
        document.getElementById("frmName").focus();
    }
    else if (pattern.test(email)) {
        alert('thank you.\r\n\r\nyour email address (' + email + ') will be added to our mailing list.\r\nyou will have the option to unsubscribe in all correspondence we send.\r\n\r\nhaleys.');
        document.frmContact.submit();
    }
    else {
        alert('please enter a valid email address.');
        document.getElementById("frmEmail").focus();
    }
}

function imagePreLoader() {
    
    var imageCount = document.getElementById('imageCount').value;
    var imageType = document.getElementById('imageType').value;

    imageObj = new Image();

    images = new Array();

    images[0] = 'img/transparent.png';
    for (i = 1; i <= imageCount; i++) {
        images[i] = 'img/' + imageType + '_' + i + 'b.jpg';
    }

    // start preloading
    for (i = 0; i <= imageCount; i++) {
        imageObj.src = images[i];     
    }


}

function cmsNewsChange() 
{
    archiveID = document.getElementById("selectArchive").value;

    location.href = 'cms.asp?archiveID=' + archiveID;
}

function confirmDelete() {

    if (confirm('Are you sure you wish to permanently delete this new archive?') == true) {
        document.forms['frmDeleteNews'].submit();
    }
    else {
        return false;
    }
}

function confirmDeleteImage() {

    if (confirm('Are you sure you wish to permanently remove the image from this archive?') == true) {
        document.forms['frmDeleteImage'].submit();
    }
    else {
        return false;
    }
}

function searchBox(e) {

    e = e || window.event;
    var code = e.keyCode || e.which;

    if (code == 13) {
        window.location = 'news.asp?ss=' + document.getElementById('searchString').value
    }
}

function getMymUrls(update) {
    mymXmlHttp = CreateXmlHttpObject()
    if (mymXmlHttp == null) {
        alert("Browser does not support AJAX");
        return;
    }

    mymXmlHttp.onreadystatechange = getMymUrls_stateChanged;
    mymXmlHttp.open("GET", "includes/ajaxresponse.asp?f=getMymFeed&update=" + update, true);
    mymXmlHttp.send(null);
}

function getMymUrls_stateChanged() {

    if (mymXmlHttp.readyState == 4 || mymXmlHttp.readyState == "complete") {
        document.getElementById('hostedURLs').innerHTML = mymXmlHttp.responseText;
    }
}
