
function forgotpass() {
    settings ='height=245,width=350,top=0,left=0,scrollbars=yes,resizable=1'
    Page='/popup/ForgotPassword.php'
    win1 = window.open(Page,'newname',settings)
}

function advancedKeywordSearch() {
    if (document.advanced_keyword_search.key_words.value == "" || document.advanced_keyword_search.key_words.value == "Keyword search") {
        window.alert("Please enter keywords to search.");
        document.advanced_keyword_search.key_words.focus();
        return false;
    } else {
        var section_name = document.getElementById('section_name').value;
        document.advanced_keyword_search.action = '/page/'+section_name+'/SearchResults.php';
    }

    document.advanced_keyword_search.submit();
}

function NewWindow(mypage,myname,w,h,scroll) {
LeftPosition =  0;
TopPosition =  0;

settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=1'
win = window.open(mypage,myname,settings)
win.focus();
}

function NewWindowStatusNO(mypage,myname,w,h,scroll) {
	LeftPosition =  0;
	TopPosition =  0;

	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',status=no,resizable=1'
    win = window.open(mypage,myname,settings)
}


// ================================================================================
//  Shared functions
// ================================================================================

// Reloads a page from the value selected in a select.
function reloadPageFromASelect(select) {
     if (select.value != "") {
        target = select.value;
        location.href = target;
     }
}

function LinkwizzLoadSelect(xmlreply, selectElement, selectedValue, SelectsToClear) {
    if (xmlreply.status == Http.Status.OK) {

        //alert("selectElement: "+xmlreply.responseText);

        for (i=0; i < SelectsToClear.length; i++) {
            if (SelectsToClear[i]) {
                SelectsToClear[i].length = 1;
            }
        }

        selectElement.length = 1;
        var NewData = xmlreply.responseText.split("@LW1@");
        selectElement.length = NewData.length + 1;
        for (i=0; i < NewData.length; i++) {
            var DataItem = NewData[i].split("@LW2@");
            selectElement[i + 1].value = DataItem[0];
            selectElement[i + 1].text  = DataItem[1];
            if (selectedValue == DataItem[0]) {
                selectElement[i + 1].selected = true;
            }
        }
    }
}

function LinkwizzSetInnerHTML(xmlreply, elementToFill) {
    if (xmlreply.status == Http.Status.OK) {
        //alert("selectElement: "+xmlreply.responseText);
        elementToFill.innerHTML = xmlreply.responseText;
    }
}

function setRadioByElementNameValue(elementName, elementValue) {
    var RadioElements = document.getElementsByName(elementName);
    for (i=0; i < RadioElements.length; i++) {
        if (RadioElements[i].value == elementValue) {
            RadioElements[i].checked = true;
        } else {
            RadioElements[i].checked = false;
        }
    }
}

// ================================================================================
//  AdvancedSearch/EditPerson/... Location functions
// ================================================================================

function LocationStateChange(form) {
    var newStateID = form.state_id.options[form.state_id.options.selectedIndex].value;
    var oldStateID = -1;
    if (form.previous_state_id) {
        oldStateID = form.previous_state_id.value;
        form.previous_state_id.value = newStateID;
    }

    var selectedValue = -1;
    var selectElement = form.elements["region_id"];

    var SelectsToClear = new Array();
    SelectsToClear[0] = form.elements["suburb_id"];

    if (newStateID == "") {
        form.region_id.length = 1;
        form.suburb_id.length = 1;
    } else {
        if (newStateID == oldStateID) {
        } else {
        //alert("/ajax/lists/State/RegionsList-"+newStateID+".txt");
            Http.get({
                url: "/ajax/lists/State/RegionsList-"+newStateID+".txt",
                callback: LinkwizzLoadSelect,
                cache: Http.Cache.GetNoCache
                }, [selectElement, selectedValue, SelectsToClear]);
        }
    }
}

function LocationRegionChange(form) {
    var newRegionID = form.region_id.options[form.region_id.options.selectedIndex].value;
    var oldRegionID = form.previous_region_id.value;
    var selectedValue = -1;
    var selectElement = form.elements["suburb_id"];
    var SelectsToClear = new Array();

    form.previous_region_id.value = newRegionID;

    if (newRegionID == "") {
        form.suburb_id.length = 1;
    } else {
        if (newRegionID == oldRegionID) {
        } else {
            Http.get({
                    url: "/ajax/lists/Region/SuburbsList-" + newRegionID + ".txt",
                    callback: LinkwizzLoadSelect,
                    cache: Http.Cache.GetNoCache
                    }, [selectElement, selectedValue, SelectsToClear]);
        }
    }
}

// ================================================================================
//  Business/AdvancedSearch function(s)
// ================================================================================

function businessCategoryChange(form, post) {
    if (!post) {
        post = '';
    }

    var newElement = form.elements["category_id"+post];
    var oldElement = form.elements["previous_category_id"+post];

    var newValue = newElement.options[newElement.options.selectedIndex].value;
    var oldValue = oldElement.value;
    oldElement.value = newValue;

    var selectedValue = -1;
    var selectElement = form.elements["child_category_id"+post];
    var SelectsToClear = new Array();

    if (newValue == "") {
        selectElement.length = 1;
    } else {
        if (newValue == oldValue) {
        } else {
            Http.get({
                    url: "/ajax/lists/BusinessCategory/ChildCategoriesList-" + newValue + ".txt",
                    callback: LinkwizzLoadSelect,
                    cache: Http.Cache.GetNoCache
                    }, [selectElement, selectedValue, SelectsToClear]);
        }
    }
}

function classifiedCategoryChange(form, post) {
    if (!post) {
        post = '';
    }

    var newElement = form.elements["category_id"+post];
    var oldElement = form.elements["previous_category_id"+post];

    var newValue = newElement.options[newElement.options.selectedIndex].value;
    var oldValue = oldElement.value;
    oldElement.value = newValue;

    var selectedValue = -1;
    var selectElement = form.elements["child_category_id"+post];
    var SelectsToClear = new Array();

    if (newValue == "") {
        selectElement.length = 1;
    } else {
        if (newValue == oldValue) {
        } else {
            Http.get({
                    url: "/ajax/lists/ClassifiedCategory/ChildCategoriesList-" + newValue + ".txt",
                    callback: LinkwizzLoadSelect,
                    cache: Http.Cache.GetNoCache
                    }, [selectElement, selectedValue, SelectsToClear]);
        }
    }
}


// ================================================================================
//  Automotive function(s)
// ================================================================================

function AutomotiveTypeChange(form) {
    var newValue = form.automotive_type_id.options[form.automotive_type_id.options.selectedIndex].value;
    var oldValue = form.previous_automotive_type_id.value;
    var selectedValue = -1;
    var selectElement = form.elements["automotive_manufacturer_id"];

    var SelectsToClear = new Array();
    SelectsToClear[0] = form.elements["automotive_model_id"];

    form.previous_automotive_type_id.value = newValue;

    if (newValue == "") {
        form.automotive_manufacturer_id.length = 1;
        form.automotive_model_id.length = 1;
    } else {
        if (newValue == oldValue) {
        } else {
            Http.get({
                url: "/ajax/lists/Automotive/ManufacturerList-"+newValue+".txt",
                callback: LinkwizzLoadSelect,
                cache: Http.Cache.GetNoCache
                }, [selectElement, selectedValue, SelectsToClear]);
        }
    }
}

function AutomotiveManufacturerChange(form) {
    var newValue = form.automotive_manufacturer_id.options[form.automotive_manufacturer_id.options.selectedIndex].value;
    var oldValue = form.previous_automotive_manufacturer_id.value;
    var selectedValue = -1;
    var selectElement = form.elements["automotive_model_id"];
    var SelectsToClear = new Array();

    form.previous_automotive_manufacturer_id.value = newValue;

    if (newValue == "") {
        selectElement.length = 1;
    } else {
        if (newValue == oldValue) {
        } else {
            Http.get({
                    url: "/ajax/lists/Automotive/ModelList-" + newValue + ".txt",
                    callback: LinkwizzLoadSelect,
                cache: Http.Cache.GetNoCache
                    }, [selectElement, selectedValue, SelectsToClear]);
        }
    }
}

function glassCarLookup(obj_target) {

	// assigning methods
	this.popup    = glassCarLookup_popup;
	this.clear    = glassCarLookup_clear;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error: no target control specified");
	this.target = obj_target;

}

function glassCarLookup_popup() {
    var nvic = document.getElementById('nvic').value;
	var obj_glasswindow =
        window.open(
                    '/page/automotive/GlassCarLookup.php?nvic=' + nvic,
                    'GlassLookup',
                    'width=500,height=640,status=no,resizable=1,scrollbars=1,top=200,left=200,dependent=yes,alwaysRaised=yes'
                    );
	obj_glasswindow.opener = window;
	obj_glasswindow.focus();
}


function glassCarLookup_clear() {
    document.getElementById('nvic').value = "";

    document.getElementById('nvic_disp1').style.display = "block";
    document.getElementById('nvic_disp2').style.display = "none";
}


function editBuyerAlert() {
    if (document.edit_buyer_alert.agree_forward_details.checked == false) {
        window.alert("You have to agree to the Terms & Conditions")
            document.edit_buyer_alert.agree_forward_details.focus();
        return false;
    }

    if (document.edit_buyer_alert.automotive_type_id.value == "") {
        window.alert("You must select an automotive type, make, model as well as either a year range, or price range!");
        document.edit_buyer_alert.automotive_type_id.focus();
        return false;
    } else if (document.edit_buyer_alert.automotive_manufacturer_id.value == "") {
        window.alert("You must select an automotive type, make, model as well as either a year range, or price range!");
        document.edit_buyer_alert.automotive_manufacturer_id.focus();
        return false;
    } else if (document.edit_buyer_alert.automotive_model_id.value == "") {
        window.alert("You must select an automotive type, make, model as well as either a year range, or price range!");
        document.edit_buyer_alert.automotive_model_id.focus();
        return false;
    }

    if (
        (document.edit_buyer_alert.automotive_year_lower_limit.value == "" || document.edit_buyer_alert.automotive_year_upper_limit.value == "")
        &&
        (document.edit_buyer_alert.automotive_price_upper_limit.value == "")
        ) {
        window.alert("You must select an automotive type, make, model as well as either a year range, or price range!");
        document.edit_buyer_alert.automotive_year_lower_limit.focus();
        return false;
    }

    document.edit_buyer_alert.submit();
}
