function showdiv(name){
    var obj = (document.getElementById) ? document.getElementById(name) : eval("document.all[name]");
    if (obj.style.display == "none") {
        obj.style.display = "";
        if (name == "srchcontainerimgadv") {
            ajaxpage("set_session_variables.html?advanced=1", "");
            ajaxpage("set_session_variables.html?showoptions=1", "");
            document.getElementById("options").innerHTML = "Fewer Options"
        }
        if (name == "hideshow") {
            ajaxpage("set_session_variables.html?openlightbox=1", "");
            ajaxpage("lightbox.html", "hideshow");
            document.getElementById("img_lb_show").src = "/images/icons/lb_hide.gif"
        }
        if (name == "hideshowbin") {
            ajaxpage("set_session_variables.html?openclipbin=1", "");
            ajaxpage("clipbin.html", "hideshowbin");
            document.getElementById("img_cb_show").src = "/images/icons/cb_hide.gif"
        }
    }
    else {
        obj.style.display = "none";
        if (name == "srchcontainerimgadv") {
            ajaxpage("set_session_variables.html?advanced=0", "");
            ajaxpage("set_session_variables.html?showoptions=0", "");
            document.getElementById("options").innerHTML = "More Options"
        }
        if (name == "hideshow") {
            ajaxpage("set_session_variables.html?openlightbox=0", "");
            document.getElementById("img_lb_show").src = "/images/icons/lb_show.gif"
        }
        if (name == "hideshowbin") {
            ajaxpage("set_session_variables.html?openclipbin=0", "");
            document.getElementById("img_cb_show").src = "/images/icons/cb_show.gif"
        }
    }
}

function show(a){
    document.getElementById(a).style.display = "";
    switch (a) {
        case "hideshow":
            if (document.getElementById("img_lb_show") != null) {
                document.getElementById("img_lb_show").src = "/images/icons/lb_hide.gif"
            }
            break;
        case "hideshowbin":
            if (document.getElementById("img_cb_show") != null) {
                document.getElementById("img_cb_show").src = "/images/icons/cb_hide.gif"
            }
            break
    }
}

function showhide(a, b){
    document.getElementById(a).style.display = "";
    document.getElementById(b).style.display = "none"
}

function hidediv(name){
    var obj = (document.getElementById) ? document.getElementById(name) : eval("document.all[name]");
    if (obj.style.display == "none") {
        obj.style.display = ""
    }
    else {
        obj.style.display = "none"
    }
}

function hdiv(a){
    document.getElementById(a).style.display = "none"
}

function sdiv(a){
    document.getElementById(a).style.display = ""
}

function MM_swapImgRestore(){
    var d, b, c = document.MM_sr;
    for (d = 0; c && d < c.length && (b = c[d]) && b.oSrc; d++) {
        b.src = b.oSrc
    }
}

function MM_preloadImages(){
    var f = document;
    if (f.images) {
        if (!f.MM_p) {
            f.MM_p = new Array()
        }
        var e, c = f.MM_p.length, b = MM_preloadImages.arguments;
        for (e = 0; e < b.length; e++) {
            if (b[e].indexOf("#") != 0) {
                f.MM_p[c] = new Image;
                f.MM_p[c++].src = b[e]
            }
        }
    }
}

function MM_findObj(f, e){
    var c, b, a;
    if (!e) {
        e = document
    }
    if ((c = f.indexOf("?")) > 0 && parent.frames.length) {
        e = parent.frames[f.substring(c + 1)].document;
        f = f.substring(0, c)
    }
    if (!(a = e[f]) && e.all) {
        a = e.all[f]
    }
    for (b = 0; !a && b < e.forms.length; b++) {
        a = e.forms[b][f]
    }
    for (b = 0; !a && e.layers && b < e.layers.length; b++) {
        a = MM_findObj(f, e.layers[b].document)
    }
    if (!a && e.getElementById) {
        a = e.getElementById(f)
    }
    return a
}

function MM_swapImage(){
    var e, d = 0, b, c = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (e = 0; e < (c.length - 2); e += 3) {
        if ((b = MM_findObj(c[e])) != null) {
            document.MM_sr[d++] = b;
            if (!b.oSrc) {
                b.oSrc = b.src
            }
            b.src = c[e + 2]
        }
    }
}

function testIsValidObject(a){
    if (null == a) {
        return false
    }
    if ("undefined" == typeof(a)) {
        return false
    }
    return true
}

function updateSearchType(){
    if (testIsValidObject(document.search.rf_brand_id) && testIsValidObject(document.search.rp_brand_id) && testIsValidObject(document.search.sp_brand_id)) {
        if (document.search.rf_brand_id.selectedIndex == -1 && document.search.rp_brand_id.selectedIndex == -1 && document.search.sp_brand_id.selectedIndex == -1) {
            document.search.search_type.value = "keyword"
        }
        else {
            document.search.search_type.value = "keyword"
        }
    }
}

function selectChange(){
    if (testIsValidObject(document.search.rf_brand_id) && testIsValidObject(document.search.rp_brand_id) && testIsValidObject(document.search.sp_brand_id)) {
        document.search.rp_search.checked = 0;
        document.search.rf_search.checked = 0;
        document.search.rpe_search.checked = 0;
        updateSearchType()
    }
}

function checkBoxChange1(){
    if (testIsValidObject(document.search.rp_brand_id)) {
        document.search.rp_brand_id.selectedIndex = -1
    }
    if (testIsValidObject(document.search.sp_brand_id)) {
        document.search.sp_brand_id.selectedIndex = -1
    }
    updateSearchType()
}

function checkBoxChange2(){
    if (testIsValidObject(document.search.rf_brand_id)) {
        document.search.rf_brand_id.selectedIndex = -1
    }
    updateSearchType()
}

function go_page(page_to_jump, image_page, total_page, urlparam){
    var c = (eval(page_to_jump) - 1) * eval(image_page) + 1;
    var t = (eval(total_page) - 1) * eval(image_page) + 1;
    var ct = 0;
    if (c > t) {
        ct = t
    }
    else {
        if (c <= 0) {
            ct = 1
        }
        else {
            ct = c
        }
    }
    if (urlparam.indexOf("images.html") != -1) {
        str = urlparam.replace("images.html", "images_ajax.html")
    }
    else {
        if (urlparam.indexOf("footage.html") != -1) {
            str = urlparam.replace("footage.html", "footage_ajax.html")
        }
    }
    ajaxpage("" + str + "&counter=" + ct + "", "results")
}

function deselect(c){
    var b = new Array();
    for (var a = 0; a < c.options.length; a++) {
        if (c.options[a].selected) {
            c.options[a].selected = false
        }
    }
}

function clear_filters(c, b, a){
    deselect(c);
    deselect(b);
    deselect(a);
    document.search.rp_search.checked = 1;
    document.search.rpe_search.checked = 1;
    document.search.rf_search.checked = 1
}

function ajaxpage(a, d){
    var c = false;
    if (d == "results") {
        if (document.getElementById("loading_sheader1")) {
            document.getElementById("loading_sheader1").style.display = ""
        }
        if (document.getElementById("loading_sheader2")) {
            document.getElementById("loading_sheader2").style.display = ""
        }
    }
    if (window.XMLHttpRequest) {
        c = new XMLHttpRequest()
    }
    else {
        if (window.ActiveXObject) {
            try {
                c = new ActiveXObject("Msxml2.XMLHTTP")
            } 
            catch (b) {
                try {
                    c = new ActiveXObject("Microsoft.XMLHTTP")
                } 
                catch (b) {
                }
            }
        }
        else {
            return false
        }
    }
    c.onreadystatechange = function(){
        loadpage(c, d)
    };
    nocache = Math.random();
    n_url = a;
    if (a.indexOf("?") == -1) {
        n_url = n_url + "?nocache=" + nocache
    }
    else {
        n_url = n_url + "&nocache=" + nocache
    }
    c.open("GET", n_url, true);
    c.send(null)
}

function loadpage(b, a){
    if (b.readyState == 4 && (b.status == 200 || window.location.href.indexOf("http") == -1)) {
        if (a != "") {
            document.getElementById(a).innerHTML = b.responseText;
            if (a == "results") {
                document.getElementById("within").style.display = "";
                document.getElementById("lf").scrollTop = 0;
                if (document.getElementById("loading_sheader1")) {
                    document.getElementById("loading_sheader1").style.display = "none"
                }
                if (document.getElementById("loading_sheader2")) {
                    document.getElementById("loading_sheader2").style.display = "none"
                }
                if (location.hostname.indexOf("dev") == -1) {
                    pageTracker._trackPageview("/SearchResultsAjax")
                }
            }
        }
    }
}

function toggle_div(b, d, e, a, c){
    for (i = 1; i <= d; i++) {
        if (i != b) {
            document.getElementById(e + i).style.display = "none";
            document.images["arrow_" + i].src = "images/lightbox/lb_dnarrow.gif"
        }
    }
    if (document.getElementById(e + b).style.display == "none") {
        document.getElementById(e + b).style.display = "";
        document.images["arrow_" + b].src = "images/lightbox/lb_uparrow.gif";
        if (c == "img") {
            ajaxpage("job_bag.html?event=set_default_lb&set_firstlb=0&job_bag_id=" + a + "&jbrownum=" + b, "item" + b)
        }
        else {
            ajaxpage("clipbin_ajax.html?event=set_default_lb&set_firstlb=0&bin_id=" + a + "&jbrownum=" + b, "item" + b)
        }
    }
    else {
        document.getElementById(e + b).style.display = "none";
        document.images["arrow_" + b].src = "images/lightbox/lb_dnarrow.gif";
        if (c == "img") {
            ajaxpage("job_bag.html?event=set_default_lb&set_firstlb=1&jbrownum=" + b, "item" + b)
        }
        else {
            ajaxpage("clipbin_ajax.html?event=set_default_lb&set_firstlb=1&jbrownum=" + b, "item" + b)
        }
    }
}

function edit_lb(b, a, c, f, e, d){
    if (b == "") {
        if (d == "img") {
            alert("Lightbox name cannot be blank.\nYour change has not been saved.")
        }
        else {
            alert("Clipbin name cannot be blank.\nYour change has not been saved.")
        }
        document.getElementById("lbn_" + a).style.backgroundColor = "#cccccc";
        document.getElementById("lbn_" + a).value = e
    }
    else {
        document.getElementById("lbn_" + a).style.backgroundColor = "white";
        if (d == "img") {
            ajaxpage("job_bag.html?event=editlbname&jbrownum=" + a + "&lightbox_id=" + c + "&jb_newname=" + b + "&totaljb=" + f, "jb")
        }
        else {
            ajaxpage("clipbin_ajax.html?event=editlbname&jbrownum=" + a + "&bin_id=" + c + "&jb_newname=" + b + "&totaljb=" + f, "jb")
        }
    }
}

function popupWindow(c, d, a, e, b){
    var f = window.open(c, b, "toolbar=no,location=no,directories=no,status=yes,scrollbars=" + e + ",resizable=yes,width=" + d + ",height=" + a);
    f.focus()
}

function getForm(g){
    var e = "";
    var f = "";
    var d = "";
    var c = "";
    var b = "";
    for (var a = 0; a < g.elements.length; a++) {
        b = g.elements[a];
        f = b.title;
        d = b.value;
        c = b.name;
        switch (b.type) {
            case "text":
            case "hidden":
            case "password":
            case "textarea":
                e += c + "=" + encodeURI(d) + "&";
                break;
            case "checkbox":
            case "radio":
                if (b.checked) {
                    e += c + "=" + encodeURI(d) + "&"
                }
                break;
            case "select-one":
                e += c + "=" + b.options[b.selectedIndex].value + "&";
                break;
            case "select-multiple":
                e += c + "=" + getSelectedValues(b) + "&";
                break
        }
    }
    e = e.substr(0, (e.length - 1));
    return e
}

function getSelectedValues(a){
    var c = new Array();
    for (var b = 0; b < a.options.length; b++) {
        if (a.options[b].selected) {
            c[c.length] = a.options[b].value
        }
    }
    return c
}

function EnterPressed(b){
    var a;
    if (b && b.which) {
        b = b;
        a = b.which
    }
    else {
        b = event;
        a = b.keyCode
    }
    if (a == 13) {
        return true
    }
    else {
        return false
    }
}

function check_price(){
    ticked = false;
    for (i = 0; i < document.add_rf_to_order.price_id.length; i++) {
        if (document.add_rf_to_order.price_id[i].checked) {
            ticked = true
        }
    }
    return ticked
}

function saveAdvancedState(a){
    var a;
    document.getElementById("advOptions").value = a
}

function cleanup(a){
    var a;
    ColdFusion.Window.destroy(a, true)
}

function resetSearch(b){
    var b = document.getElementById("searchForm");
    var c = b.image_per_page;
    var a = b.image_from;
    for (i = 0; i < b.orientation.length; i++) {
        b.orientation[i].checked = true
    }
    for (i = 0; i < b.colour_type.length; i++) {
        b.colour_type[i].checked = true
    }
    for (i = 0; i < b.illustrations.length; i++) {
        b.illustrations[i].checked = true
    }
    c.selectedIndex = 0;
    a.selectedIndex = 0;
    b.search_string.value = "enter keyword/s";
    document.getElementById('searchWithinResults').checked = false;
    document.getElementById('searchType').checked = false;
    document.getElementById('search_type').value = "keyword";
}

function activateDrags(){
    $(".draggable").draggable({
        helper: "clone"
    })
}

function onloginRefreh(){
    window.location.href = window.location.href
}

function getprice(b, c){
    var a = {
        productPrice: $(this).val()
    };
    $.ajax({
        type: "POST",
        url: "/registration_control.cfm?planSelector=" + b,
        datatype: "html",
        data: a,
        success: function(d){
            $("#endTab" + c).html(d)
        }
    })
}

function getpromotion(a, c){
    var b = {
        promocode: $(this).val()
    };
    $.ajax({
        type: "POST",
        url: "registration_control.cfm?promocode=" + a.value + "&plan=" + c,
        datatype: "html",
        data: b,
        success: function(d){
            $("#total").html(d)
        }
    })
}

function showAreaMyAccount(a){
    document.getElementById("changePassword").style.display = "none";
    document.getElementById("changeCreditCard").style.display = "none";
    document.getElementById("viewYourInvoice").style.display = "none";
    document.getElementById("accountdetails").style.display = "none";
    document.getElementById(a).style.display = "";
}

function changePassword(a){
    var a;
    var b = new User;
    b.setCallbackHandler(updateSuccessful);
    b.setErrorHandler(updateFail);
    oldPassword = document.getElementById("oldPassword").value;
    newPassword = document.getElementById("newPassword").value;
    confirmPassword = document.getElementById("confirmPassword").value;
    if (confirmPassword != newPassword) {
        document.getElementById("passwordStatus").innerHTML = "<h3 class='error'>New password and confirm password does not match.</h3>"
    }
    else {
        if (oldPassword == "") {
            document.getElementById("passwordStatus").innerHTML = "<h3 class='error'>Old password is blank.</h3>"
        }
        else {
            if (newPassword == "") {
                document.getElementById("passwordStatus").innerHTML = "<h3 class='error'>New password is blank.</h3>"
            }
            else {
                status = b.changeUserPassword(a, oldPassword, newPassword)
            }
        }
    }
}

function updateSuccessful(a){
    if (a == 0) {
        document.getElementById("passwordStatus").innerHTML = "<h3 class='error'>Your old password is invalid.</h3>"
    }
    else {
        if (a == 1) {
            document.getElementById("passwordStatus").innerHTML = "<h3 class='information'>You have successfully changed your password.</h3>"
        }
    }
}

function updateFail(){
    document.getElementById("passwordStatus").innerHTML = "<h3 class='information'>An error occured while processing your request.</h3>"
}

function changeActionURL(){
    var searchFormName = document.getElementById('searchForm');
    var searchString = document.getElementById('search_string').value;
    var prevSearchStringFormatted = '';
    searchString = searchString.replace(/^\s+|\s+$/g, '');
    searchStringFormatted = searchString.replace(/ /g, "/");
    var searchWithinResults = document.getElementById('searchWithinResults');
    if (searchWithinResults.checked == true) {
        var prevSearch = document.getElementById('prevSearch');
        if (prevSearch.value != null || prevSearch.value != '') {
            prevSearchString = prevSearch.value.replace(/^\s+|\s+$/g, '');
            prevSearchStringFormatted = prevSearchString.replace(/ /g, "/");
            document.getElementById('search_string').value = prevSearch.value + ' ' + searchString;
        }
    }
    if (prevSearchStringFormatted == '') {
        searchFormName.action = '/search.html?/' + searchStringFormatted;
    }
    else {
        searchFormName.action = '/search.html?/' + prevSearchStringFormatted + '/' + searchStringFormatted;
    }
    return true;
}

function changeCCDetails(b){
    var b;
    var g = new User;
    g.setCallbackHandler(updateCCSuccessful);
    g.setErrorHandler(updateCCFail);
    var a = document.getElementById("cardType").value;
    var e = document.getElementById("holderName");
    var j = document.getElementById("cardNum");
    var f = document.getElementById("verCode");
    var d = document.getElementById("ccMonth").value;
    var h = document.getElementById("ccYear").value;
    var c = document.getElementById("ccIDValue").value;
    if (e.textLength < 3) {
        document.getElementById("ccStatus").innerHTML = "<h3 class='error'>Credit card holder's name is too short.</h3>"
    }
    else {
        if (j.textLength < 13) {
            document.getElementById("ccStatus").innerHTML = "<h3 class='error'>Invalid credit card number.</h3>"
        }
        else {
            if (f.textLength < 1) {
                document.getElementById("ccStatus").innerHTML = "<h3 class='error'>Security code can not be blank.</h3>"
            }
            else {
                document.getElementById("ccStatus").innerHTML = "";
                g.changeCCDetails(b, a, e.value, d, h, f.value, j.value, c)
            }
        }
    }
}

function updateCCSuccessful(a){
    if (a.STATUS == 0) {
        document.getElementById("ccStatus").innerHTML = "<h3 class='information'>" + a.MSGS + "</h3>"
    }
    else {
        if (a.STATUS == 1) {
            document.getElementById("ccStatus").innerHTML = "<h3 class='error'>" + a.MSGS + "</h3>"
        }
    }
}

function updateCCFail(a){
    console.dir(a);
    document.getElementById("ccStatus").innerHTML = "<h3 class='error'> An error occured while processing your request.</h3>"
}

function refreshAvailableDownloads(){
    setTimeout("getAvailableDownloads()", 1000)
}

function getAvailableDownloads(){
    ColdFusion.navigate("/includeWindow.html?viewName=dspShowAvailableDownloads.cfm", "availableDownloads")
}

function callbackhandler(){
    alert("callbackhandler")
}

function myerrorhandler(b, a){
    alert(b + a)
};
function disableSubmitButton(){
	if(document.getElementById('moveToStep3')){
		document.getElementById('moveToStep3').disabled = true;
	}
}
