﻿
function getDim2(el) {
    for (var lx = 0, ly = 0; el != null;
		ly += el.offsetTop, lx += el.offsetLeft, el = el.offsetParent);
    return { y: ly }
}
function getDim(el) {
    for (var lx = 0, ly = 0; el != null;
		lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return { x: lx }
}

function Pos(obj1) {
    m = getDim2(document.getElementById('pos' + obj1));
    document.getElementById('menu' + obj1).style.top = m.y + 2 + "px";

    m = getDim(document.getElementById('pos' + obj1));
    document.getElementById('menu' + obj1).style.left = m.x - 13 + "px";
}



function PosAfter(obj1, obj2) {
    document.getElementById('menupop1').value = obj1;
    document.getElementById('menupop1').value = obj2;
}

function PosSaver(obj1) {
    mainBox = document.getElementById('menupop').value

    if (mainBox == "0") {
        document.getElementById('menupop').value = obj1;
    }
    else {
       
        document.getElementById('menupop').value = document.getElementById('menupop').value + "," + obj1;
    }

}

function PosRemover(obj1) {
    var str = document.getElementById('menupop').value;
    document.getElementById('menupop').value = str.replace(obj1, "");



}


function PosDrop(objNew) {
    m = getDim2(document.getElementById('pos' + objNew));
    document.getElementById('menu' + objNew).style.top = m.y - 1 + "px";

    m = getDim(document.getElementById('pos' + objNew));
    document.getElementById('menu' + objNew).style.left = m.x - 1 + "px";
}

function PosDropNorm(objNew) {
    m = getDim2(document.getElementById('pos' + objNew));
    document.getElementById('menu' + objNew).style.top = m.y + 45 + "px";

    m = getDim(document.getElementById('pos' + objNew));
    document.getElementById('menu' + objNew).style.left = m.x - 1 + "px";
}

function PosDropNorm2(objNew) {
    
    m = getDim2(document.getElementById('pos' + objNew));
    document.getElementById('menu' + objNew).style.top = m.y - 1 + "px";

    m = getDim(document.getElementById('pos' + objNew));
    document.getElementById('menu' + objNew).style.left = m.x - 1 + "px";

}



function showmenu(id) {
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hidemenu(id) {
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
    var el = (document.getElementById) ? document.getElementById(id) : (document.all) ? document.all[id] : (document.layers) ? document.layers[id] : null;
    if (el) el.css = (el.style) ? el.style : el;
    return el;
}

function echeck(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(" ") != -1) {
        alert("Invalid E-mail ID")
        return false
    }


}


function isNumeric(value) {
    if (value != null && !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
    return true;
}

function postthread(param) {
    param = document.getElementById(param);
    param.disabled = true;
    param.value = "Posting...";
}

function checkData() {
    if (document.example.fName.value == "") {
        alert("Please enter your first name.");
        document.example.fName.focus();
        return false;
    }
    if (document.example.lName.value == "") {
        alert("Please enter your last name.");
        document.example.lName.focus();
        return false;
    }

    if (document.example.Eadd.value == "") {
        alert("Please enter Your email address.");
        document.example.Eadd.focus();
        return false;
    }

    var emailID = document.example.Eadd;
    if (echeck(emailID.value) == false) {
        emailID.value = ""
        emailID.focus()
        return false
    }

    postthread('submitbutton');
}


function checkDataSearch() {

    if (document.norm.tSearch.value == "") {
        alert("Please enter a key word.");
        document.norm.tSearch.focus();
        return false;
    }

    if (document.norm.tSearch.value == "Type keywords here") {
        alert("Please enter a key word.");
        document.norm.tSearch.focus();
        return false;
    }

}

function checkDataAdmin() {

    if (isNumeric(document.frmPageEdit.Pricefrom.value) == false) {
        alert("Price can only be a numeric value");
        document.frmPageEdit.Pricefrom.focus();
        return false;
    }
   
}





