function SymError() {
    return false;
}

window.onerror = SymError;
var bName = navigator.appName;

function showUploadWindow(threadid) {
    var rand = Math.random().toString();
    var ordval = rand.substring(2, rand.length);
    var options = 'width=350,height=160,scrollbars=yes,status=yes,resizeable=yes';
    var wname = 'up' + ordval;
    var url = '/s/talkboard2.PicUploader?threadid=' + threadid;
    var w = window.open(url, wname, options);
}

function ccPicturePop() {
    var rand = Math.random().toString();
    var ordval = rand.substring(2, rand.length);
    var options = 'width=350,height=160,scrollbars=yes,status=yes,resizeable=yes';
    var wname = 'up' + ordval;
    var url = '/s/talkboard2.PicUploaderVersion2';
    var w = window.open(url, wname, options);
}

function tb3ShowUploadWindow(threadid) {
    var rand = Math.random().toString();
    var ordval = rand.substring(2, rand.length);
    var options = 'width=350,height=190,scrollbars=yes,status=yes,resizeable=yes';
    var wname = 'up' + ordval;
    var url = '/PicUpload?threadid=' + threadid;
    var w = window.open(url, wname, options);
}

function tb3CcPicturePop() {
    var rand = Math.random().toString();
    var ordval = rand.substring(2, rand.length);
    var options = 'width=350,height=200,scrollbars=yes,status=yes,resizeable=yes';
    var wname = 'up' + ordval;
    var url = '/NewThreadPicUpload';
    var w = window.open(url, wname, options);
}

function checkBlankSubject() {
    var top = document.forms["CCONV"].subject.value;
    if (!top || top == '') {
        return confirm('Are you sure you want to create a thread with no subject?nOK=Yes, cancel=No');
    } else {
        return true;
    }
}

function logPop() {
  var rand = Math.random().toString();
  var ordval = rand.substring(2,rand.length);
  var qstring = escape(document.location);
  window.open('/Talk?handlelogpopup=1&vanilla=1&target=' + qstring, ordval,'width=400,height=350,location=no,resizable=yes');
}

function moveMulti(fromSelect, toSelect) {
    while (moveOne(fromSelect, toSelect) == 1)
    {
   	}
}

function moveOne(fromSelect, toSelect) {
    var result = false;
    var index = fromSelect.selectedIndex;
    if (index > 0) {
        var item = fromSelect.options[index];
        var o = new Option(item.text, item.value);
        if (bName == "Microsoft Internet Explorer") {
            toSelect.add(o);
        } else {
            toSelect.add(o, null);
        }
        fromSelect.remove(index);
        result = true;
    }
    return result;
}

function moveAll(fromSelect, toSelect) {
    while (fromSelect.length > 1) {
        var item = fromSelect.options[1];
        if (bName == "Microsoft Internet Explorer") {
            toSelect.add(new Option(item.text, item.value));
        } else {
            toSelect.add(new Option(item.text, item.value), null);
        }
        fromSelect.remove(1);
    }
}

function selectAllItems(chosenTopics) {
    if (chosenTopics.length == 1) {
	    alert ('Not searching: You have not selected any topics to search. You won\'t find any messages.\nSelect one or more topics and use the arrow buttons to move them into the "chosen" box.');
        return false;
    } else {
        for (i = 1; i < chosenTopics.length; i++) {
            chosenTopics.options[i].selected = true;
        }
        return true;
    }
}

function selectAllChosen(chosenTopics, radio) {
    var b = true;
    if (radio.checked) {
        if (!selectAllItems(chosenTopics)) {
            b = false;
        }
    }
    for (i = 1; i < chosenTopics.length; i++) {
        chosenTopics.options[i].selected = true;
    }
    return b;
}

function loadFavs(chosenTopics, availTopics)
 {
    var cval = GetCookie('tstops');
    if (cval != null) {
        var tops = cval.split(',');
        var lSize = tops.length;
        var index = 0;
        while (index < lSize) {
            var topicId = tops[index];
            //alert ('Calling for ' + topicId);
            moveById(topicId, chosenTopics, availTopics);
            index++;
        }
    }
}

function moveById(id, chosenTopics, availTopics) {
    var optList = availTopics.options;

    var olen = optList.length;
    //alert ('Seeking *' + id + '* len is ' + olen);
    var i = 0;
    var found = false;
    while (i < olen && !found) {
        var item = optList[i];
        if (item.value == id) {
            //alert ('Found ' + item.value + ' ' + item.text);
            found = true;
            var o = new Option(item.text, item.value);
            if (bName == "Microsoft Internet Explorer") {
                chosenTopics.add(o);
            } else {
                chosenTopics.add(o, null);
            }
            availTopics.remove(i);
        } else {
            // inc if did not move one
            i++;
        }
    }
}

function saveFavs(chosenTopics) {
    var optList = chosenTopics.options;
    var olen = optList.length;
    var cname = 'tstops';
    var cval = '0';
    var index = 0;

    while (index < olen) {
        var opt = optList[index];
        if (opt.value != -1) {
            cval = cval + ',' + opt.value;
        }
        index++
    }
    SetCookie(cname, cval, expiry, '/', '.mumsnet.com', false);
    //(cval);
    alert('Your favourites have been saved');
}

//Copy from this line

function getsubcat(obj, frmname) {
    var pId = obj[obj.selectedIndex].value;
    var pTableName = obj[obj.selectedIndex].id;
    document.forms[frmname].ptablename.value = pTableName;
    LocalRemotable.getSubCategory(pTableName, pId, selectReplay);
}

var selectReplay = function(data)
 {
    var selectObj = document.getElementById('subcat');
    clearAll(selectObj);
    var arr = data;
    var id = "";
    var desc = "";
    for (var i = 0; i < arr.length; i++) {
        var str = arr[i].split('^');
        desc = str[0];
        id = str[1];
        addNewOption(selectObj, desc, id);
    }
}

function clearAll(obj) {
    var len = obj.length;
    if (len > 0) {
        for (var i = 1; i < len; i++) {
            obj.remove(i);
        }
    }
}

function addNewOption(obj, text, value) {
    var o = new Option(text, value);
    if (bName == "Microsoft Internet Explorer") {
        obj.add(o);
    } else {
        obj.add(o, null);
    }
}

function setproductname(obj, frmname, pid) {
    document.forms[frmname].pid.value = obj[obj.selectedIndex].value;
}

