// IE support
if (window.ActiveXObject && !window.XMLHttpRequest) {
    window.XMLHttpRequest = function () {
        return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
    };
}
//修改描述
function update(photoId, descvalue) {
    var req = new XMLHttpRequest();
    if (req) {
        req.onreadystatechange = function () {
            if (req.readyState == 4 && req.status == 200) {
            }
        };
    }
    req.open("POST", "/photoAjax/updateDesc", true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.send("photoId=" + photoId + "&desc=" + descvalue);
}
function initDesc(idx, photoId) {
    var desc = document.getElementById(idx);
    desc.onclick = "";
    desc.onmouseover = "";
    desc.innerHTML = "<textarea id='txt' class='highlight' style='margin-top: 0px; font-size: 14px; margin-bottom: 0px; width: 480px' ROWS='5'>" + document.getElementById("hid" + idx).value + "</textarea><br><input type='button' value='\u4fdd\u5b58' onclick='getvalue(" + idx + "," + photoId + ");' class='butt'>&nbsp;&nbsp;<input type='button' value='\u53d6\u6d88' onclick='resetDescHTML(" + idx + "," + photoId + ");' class='cancelbutt'>";
}
function getvalue(idx, photoId) {
    desctxt = document.getElementById("txt");
    var desc = document.getElementById(idx);
    var descvalue = desctxt.value;
    if (descvalue.length > 3000) {
        alert("\u63cf\u8ff0\u5b57\u6570\u592a\u591a\uff01 \u8bf7\u91cd\u65b0\u8f93\u5165\u3002");//描述字数太多！ 请重新输入。
        return;
    }
    var str = descvalue.replace(/(^\s*)|(\s*$)/g, "");
    desc.innerHTML = "saving........";
    if (str == "") {
		update(photoId, '');
        document.getElementById("hid" + idx).value = "";
        desc.innerHTML = "<div id='sp" + idx + "' onclick='initDesc(" + idx + "," + photoId + ");' style='width: 480px; font-size: 14px;' onmouseover='ch(this);' onmouseout='res(this);'><i style='color: #888; width: 480px; font-size: 14px;'>\u70b9\u51fb\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0</i></div>";//点击添加图片描述
    } else {
		update(photoId, descvalue);
        document.getElementById("hid" + idx).value = descvalue;
        desc.innerHTML = "<div id='sp" + idx + "' onclick='initDesc(" + idx + "," + photoId + ");' style='width: 480px; font-size: 14px; word-wrap:break-word;' onmouseover='ch(this);' onmouseout='res(this);'>" + descvalue.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>") + "</div>";
    }
}
function resetDescHTML(idx, photoId) {
    var desc = document.getElementById(idx);
    if (document.getElementById("hid" + idx).value == "" || document.getElementById("hid" + idx).value == "\u70b9\u51fb\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0") {//点击添加图片描述
        desc.innerHTML = "<div id='sp" + idx + "' onclick='initDesc(" + idx + "," + photoId + ");' style='width: 480px' onmouseover='ch(this);' onmouseout='res(this);'><i style='color: #888; width: 480px; font-size: 14px; ' onmouseover='ch(this);' onmouseout='res(this);'>\u70b9\u51fb\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0<i></div>";//点击添加图片描述
    } else {
        desc.innerHTML = "<div id='sp" + idx + "' onclick='initDesc(" + idx + "," + photoId + ");' style='margin-top: 0px; font-size: 14px; margin-bottom: 0px; width: 480px' onmouseover='ch(this);' onmouseout='res(this);'>" + document.getElementById("hid" + idx).value.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>") + "</div>";
    }
}
//修改标题
function updateTit(photoId, titvalue) {
    var req = new XMLHttpRequest();
    if (req) {
        req.onreadystatechange = function () {
            if (req.readyState == 4 && req.status == 200) {
            }
        };
    }
    req.open("POST", "/photoAjax/updateTitle", true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.send("photoId=" + photoId + "&title=" + titvalue);
}
function initTit(idx, photoId) {
    var tit = document.getElementById("tit" + idx);
    tit.onclick = "";
    tit.onmouseover = "";
    tit.innerHTML = "<input type='text' id='txtTit' class='highlight' style='margin-top: 0px; font-size: 18px; margin-bottom: 0px; width: 500px' value='" + document.getElementById("hidTit" + idx).value + "'><br><input type='button' value='\u4fdd\u5b58' onclick='getTit(" + idx + "," + photoId + ");' class='butt'>&nbsp;&nbsp;<input type='button' value='\u53d6\u6d88' onclick='resetTitHTML(" + idx + "," + photoId + ");' class='cancelbutt'>";
}
function getTit(idx, photoId) {
    var txtTit = document.getElementById("txtTit");
    var tit = document.getElementById("tit" + idx);
    var titvalue = txtTit.value;
    if (titvalue.length > 120) {
        alert("\u6807\u9898\u5b57\u6570\u592a\u591a\uff01 \u8bf7\u91cd\u65b0\u8f93\u5165\u3002");//标题字数太多！ 请重新输入。
        return;
    }
    var str = titvalue.replace(/(^\s*)|(\s*$)/g, "").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    tit.innerHTML = "saving........";
    if (str == "") {
		updateTit(photoId,'');
        document.getElementById("hidTit" + idx).value = "";
        tit.innerHTML = "<div id='sp" + idx + "' onclick='initTit(" + idx + "," + photoId + ");' style='width: 500px' onmouseover='ch(this);' onmouseout='res(this);'><i style='color: #888'>\u70b9\u51fb\u6dfb\u52a0\u56fe\u7247\u6807\u9898</i></div>";//点击添加图片标题
    } else {
		updateTit(photoId,titvalue);
        document.getElementById("hidTit" + idx).value = titvalue;
        tit.innerHTML = "<div id='sp" + idx + "' onclick='initTit(" + idx + "," + photoId + ");' style='width: 500px' onmouseover='ch(this);' onmouseout='res(this);'><h1 id='title_div44177575' style='margin-top: 0px; font-size: 18px; margin-bottom: 0px; width: 500px'>" + titvalue.replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</h1></div>";
    }
}
function resetTitHTML(idx, photoId) {
    var tit = document.getElementById("tit" + idx);
    if (document.getElementById("hidTit" + idx).value == "" || document.getElementById("hidTit" + idx).value == "\u70b9\u51fb\u6dfb\u52a0\u56fe\u7247\u6807\u9898") {//点击添加图片标题
        tit.innerHTML = "<i style='color: #888' onclick='initTit(" + idx + "," + photoId + ");' onmouseover='ch(this);' onmouseout='res(this);'>\u70b9\u51fb\u6dfb\u52a0\u56fe\u7247\u6807\u9898</i>";//点击添加图片标题
        tit.onmouseover = "ch(this);";
    } else {
        tit.innerHTML = "<div id='sp" + idx + "' onclick='initTit(" + idx + "," + photoId + ");' onmouseover='ch(this);' onmouseout='res(this);'><h1 id='title_div44177575' style='margin-top: 0px; font-size: 18px; margin-bottom: 0px; width: 500px'>" + document.getElementById("hidTit" + idx).value.replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</h1></div>";
    }
}

// 
function stringReplaceAll(AFindText, ARepText) {
    raRegExp = new RegExp(AFindText, "g");
    return this.replace(raRegExp, ARepText);
}
function skipto(pageNo, pageCount) {
    if (pageNo > pageCount) {
        alert("\u5df2\u8d85\u51fa\u603b\u9875\u6570.");//已超出总页数
        return;
    }
    document.pagefrm.pageNo.value = pageNo;
    document.getElementById("pagefrm").submit();
}
function checkPageNo(pageNo, pageCount) {
    if (pageNo > pageCount) {
        alert("\u5df2\u8d85\u51fa\u603b\u9875\u6570.");//已超出总页数.
        return;
    }
    document.jump.submit();
}
function checkPageNo1(pageNo, pageCount) {
    if (pageNo > pageCount) {
        alert("\u5df2\u8d85\u51fa\u603b\u9875\u6570.");
        return;
    }
    document.jump1.submit();
}
// 鼠标覆盖文本的效果显示
function ch(activeX) {
    activeX.style.background = "#ffc";
}
function res(activeX) {
    activeX.style.background = "#fff";
}
//修改标题 in photoHome
function initTitInHome(photoId) {
    var tit = document.getElementById("tit_" + photoId);
    tit.style.background = "#fff";
    tit.onclick = "";
    tit.onmouseover = "";
    tit.onmouseout = "";
    tit.innerHTML = "<input type='text' id='txtTit_" + photoId + "' class='highlight' style='font-size: 14px; width: 240px;' value='" + document.getElementById("hidTit_" + photoId).value + "'/><br>";
    tit.innerHTML += "<input type='button' value='保存' onclick='getTitInHome(" + photoId + ");' class='butt'/>&nbsp;&nbsp;<input type='button' value='取消' onclick='resetTitInHome(" + photoId + ");' class='butt'/>";
}
function getTitInHome(photoId) {
    var txtTit = document.getElementById("txtTit_" + photoId);
    var tit = document.getElementById("tit_" + photoId);
    var titvalue = txtTit.value;
    if (titvalue.length > 120) {
        alert("标题字数太多！ 请重新输入。");
        return;
    }
    var str = titvalue.replace(/(^\s*)|(\s*$)/g, "").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    tit.innerHTML = "saving........";
    if (str == "") {
		updateTitInHome(photoId, '');
        document.getElementById("hidTit_" + photoId).value = "";
        tit.onclick = function() { initTitInHome(photoId); };
    	tit.onmouseover = function() { ch(this); };
        tit.onmouseout = function() { res(this); };
        tit.innerHTML = "<i style='font-size: 14px; color: #888; margin: 0px; padding: 0px;'>点击添加图片标题</i>";
    } else {
		updateTitInHome(photoId, titvalue);
        document.getElementById("hidTit_" + photoId).value = titvalue;
        tit.onclick = function() { initTitInHome(photoId); };
    	tit.onmouseover = function() { ch(this); };
        tit.onmouseout = function() { res(this); };
        tit.innerHTML = "<h4 style='font-size: 14px; margin: 0px; padding: 0px;'>" + titvalue.replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</h4>";
    }
}
function updateTitInHome(photoId, titvalue) {
    var req = new XMLHttpRequest();
    if (req) {
        req.onreadystatechange = function () {
            if (req.readyState == 4 && req.status == 200) {
            }
        };
    }
    req.open("POST", "/photoAjax/updateTitle", true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.send("photoId=" + photoId + "&title=" + titvalue);
}
function resetTitInHome(photoId) {
    var tit = document.getElementById("tit_" + photoId);
    if (document.getElementById("hidTit_" + photoId).value == "" || document.getElementById("hidTit_" + photoId).value == "点击添加图片标题") {
        tit.onclick = function() { initTitInHome(photoId); };
    	tit.onmouseover = function() { ch(this); };
        tit.onmouseout = function() { res(this); };
        tit.innerHTML = "<i style='font-size: 14px; color: #888; margin: 0px; padding: 0px;'>点击添加图片标题</i>";
        
    } else {
    	tit.onclick = function() { initTitInHome(photoId); };
    	tit.onmouseover = function() { ch(this); };
        tit.onmouseout = function() { res(this); };
        tit.innerHTML = "<h4 style='font-size: 14px; margin: 0px; padding: 0px;'>" + document.getElementById("hidTit_" + photoId).value.replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</h4>";
    }
}
