//base_url = "http://localhost/myemoticons/";
base_url = "http://www.myemoticons.com/";

function GotoAddSmiley() {

location.href="AddSmiley.asp"
}

function GoTOSearch() {
    //alert("hi");
    var search = document.getElementById("txtSearch").value;
    window.location = base_url + "Search.asp?sKeyword=" + search;
}
function removeheader(key) {
    if (key == "Search") {
        document.getElementById("txtSearch").value = "";
    }
}

function SelectAll(id) {
    //alert(id);
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function Search() {
    //alert("luck");
    var searchkey = document.getElementById("txtSearch").value;
    window.location = base_url + "admin/ListEmoticons.asp" + "?search=" + searchkey;

}

function getSubCat(id, tdid, fname) {
    //alert(id + " " + tdid + " " + fname );
    var xmlhttp;
    var str = '<option value="Select">Select</option>';
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        alert("Your browser does not support XMLHTTP!");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            document.getElementById(tdid).innerHTML = xmlhttp.responseText;
            if (id == 'mainCatDD') {
                
                document.getElementById('subSubCatDD').innerHTML = str;
                document.getElementById('subSubSubCatDD').innerHTML = str;
            }
            else if (id == 'subCatDD') {
                document.getElementById('subSubSubCatDD').innerHTML = str;
            }
        }
    }
    url = fname + ".asp?catName=" + document.getElementById(id).value
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}

function trim(strVar) {
    if (strVar.length > 0) {
        while (strVar.charAt(0) == " ")
            strVar = strVar.substring(1, strVar.length);
        while (strVar.charAt(strVar.length - 1) == " ")
            strVar = strVar.substring(0, strVar.length - 1);
    }
    return strVar;
}

function printError() {
    //document.getElementById('addSmiley').submit();
    //alert("bye");
    if (document.getElementById('mainCatDD').value == "Select" || document.getElementById('mainCatDD').value == "") {
        document.getElementById("errorList").innerHTML = "Please Select at least one main category!";
        document.getElementById('mainCatDD').focus();
        return false;
    }
    if (trim(document.getElementById('txtAltText').value) == "") {
        document.getElementById("errorList").innerHTML = "Please enter Alt Text!";
        document.getElementById('txtAltText').focus();
        return false;
    }
    if (trim(document.getElementById('txtEmoDesc').value) == "") {
        document.getElementById("errorList").innerHTML = "Please enter Emoticon description!";
        document.getElementById('txtEmoDesc').focus();
        return false;
    }
    if (trim(document.getElementById('txtFileName').value) == "") {
        document.getElementById("errorList").innerHTML = "Please enter Emoticon Name!";
        document.getElementById('txtFileName').focus();
        return false;
    }
//    if (document.getElementById('attach1').value == "") {
//        document.getElementById("errorList").innerHTML = "Please brows file";
//        document.getElementById('attach1').focus();
//        return false;
//    }
    if ((document.getElementById('attach1').value.lastIndexOf(".gif") == -1)) {
        document.getElementById("errorList").innerHTML = "Please upload only (.gif) extention file!";
        document.getElementById('attach1').focus();
        return false;
    }
    //document.forms["addSmiley"].submit();txtBrows
    document.getElementById('addSmiley').submit();
}
function printEditError() {
    //document.getElementById('addSmiley').submit();
    //alert("bye");
    
    if (document.getElementById('mainCatDD').value == "Select" || document.getElementById('mainCatDD').value == "") {
        document.getElementById("errorList").innerHTML = "Please Select at least one main category!";
        document.getElementById('mainCatDD').focus();
        return false;
    }
    if (trim(document.getElementById('txtAltText').value) == "") {
        document.getElementById("errorList").innerHTML = "Please enter Alt Text!";
        document.getElementById('txtAltText').focus();
        return false;
    }
    if (trim(document.getElementById('txtEmoDesc').value) == "") {
        document.getElementById("errorList").innerHTML = "Please enter Emoticon description!";
        document.getElementById('txtEmoDesc').focus();
        return false;
    }
    if (trim(document.getElementById('txtFileName').value) == "") {
        document.getElementById("errorList").innerHTML = "Please enter Emoticon name!";
        document.getElementById('txtFileName').focus();
        return false;
    }
    if(document.getElementById('txtBrows').value != ""){
    
        if ((document.getElementById('txtBrows').value.lastIndexOf(".gif") == -1)) 
        {
            document.getElementById("errorList").innerHTML = "Please upload only (.gif) extention file!";
            document.getElementById('txtBrows').focus();
            return false;
        }
    }
    document.getElementById('EditSmiley').submit();
}

function PressEnter(field, event) {
    //alert('hi');
    var search = document.getElementById('txtSearch').value;
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) {
        var searchkey = document.getElementById("txtSearch").value;
        window.location = base_url + "admin/ListEmoticons.asp" + "?search=" + searchkey;
    }
    else
        return false;
}


