﻿var displayid, cutdisplaystring;
var iHeadline,iDescription,iAboutyou;
var isTraChinese,isTraEnglish;
isTraChinese = false;
isTraEnglish = false;
var strTraH_C,strTraD_C,strTraA_C,strTraH_E,strTraD_E,strTraA_E;
cutdisplaystring = 600;

function SendMailStart()
{
    if($("divsendkiss"))
        $("divsendkiss").style.display = "none";
    if(!$("divsendmail"))
    {
        var objdiv = document.createElement("div");
        objdiv.id = "divsendmail";
        objdiv.style.margin = "10px";
        objdiv.style.backgroundColor = "#ffeeee";
        document.getElementById("divsend").appendChild(objdiv);
        
        var divsendmailtitle = document.createElement("div");
        divsendmailtitle.className= "displaylinedivsend";
        divsendmailtitle.innerHTML = "<a href=\"/user/sendmail.aspx?userid=" + displayid + "&returnurl=/display.aspx?id=" + displayid + "\">Send Mail</a>";
        document.getElementById("divsendmail").appendChild(divsendmailtitle);

        var divsubject = document.createElement("div");
        divsubject.id = "divsendmailsubject";
        divsubject.style.padding = "5px 5px 0px 5px";
        divsubject.innerHTML = "Subject:<br/> <input type=\"text\" name=\"subject\" id=\"subject\" class=\"inputgary\" onfocus=\"changeclass(this,'inputgaryonfocus')\" onblur=\"changeclass(this,'inputgary');\" size=\"48\" maxlength=\"60\" />";
        document.getElementById("divsendmail").appendChild(divsubject);
        
        var divcontent = document.createElement("div");
        divcontent.id = "divsendmailcontent";
        divcontent.style.padding = "5px 5px 0px 5px";
        divcontent.innerHTML = "Content:<br/> <textarea style=\"width: 320px; height: 120px;\" id=\"content\" name=\"content\"></textarea>";           
        document.getElementById("divsendmail").appendChild(divcontent);
        
        var divbutton = document.createElement("div");
        divbutton.id = "divsendmailbutton";
        divbutton.style.padding = "5px";
        divbutton.innerHTML = " <input type=\"button\" id=\"sendmailbutton\" value=\"Send Mail\" onclick=\"SendMail()\" /> <input onclick=\"location.href='/user/sendmail.aspx?userid=" + displayid + "&returnurl=/display.aspx?id=" + displayid + "';\" type=\"button\" value=\"Send File\" /> <input type=\"button\" id=\"sendmailbuttonclose\" value=\"Close\" onclick=\"hiddensendmail()\" style=\"margin-left:12px;\" />";           
        document.getElementById("divsendmail").appendChild(divbutton);
    }
    else
    {
        if($("divsendmail").style.display == "")
            $("divsendmail").style.display = "none";
        else
            $("divsendmail").style.display = "";

       document.getElementById("divsendmailsubject").style.display = ""; 
       document.getElementById("divsendmailcontent").style.display = "";
       document.getElementById("divsendmailbutton").style.display = "";
       $("sendmailbutton").disabled = false;
       $("sendmailbuttonclose").disabled = false;
       if($("divsendmailsuccess"))
        document.getElementById("divsendmailsuccess").style.display = "none";
    }
}

function SendMail()
{
    var subject, content;
    if($F("subject") == "")
        alert("Error: Subject is null!");
    else if($F("content") == "")
        alert("Error: Content is null!");
    else
    {
        subject = $F("subject");
        content = $F("content");
        $("sendmailbutton").disabled = true;
        $("sendmailbuttonclose").disabled = true;
        var url = "/ajax.aspx?action=sendmail&d=" + new Date();
        var pars = "userid=" + displayid + "&subject=" + encodeURIComponent(subject) + "&content=" + encodeURIComponent(content);
        var myAjax = new Ajax.Request(
            url,
            {method: 'post', parameters: pars, onComplete: SendMailReturn}
            );
    }
}
function GetSendReturnError(i)
{
    var s;
    switch(i)
    {
        case 0:
            s = "Send Fail!";
            break;
        case 1:
            s = "Send Success!";
            break;
        case 2:
            s = "You must log in to send messages.";
            break;
        case 3:
            s = "You must input both subject and content.";
            break;
        case 4:
            s = "The recipient Member cannot be located.";
            break;
         case 5:
            s = "You cannot send a message to yourself.";
            break;    
        case 6:
            s = "You are not an approved Member.";
            break;
        case 7:
            s = "You have already sent your maximum messages for today.";
            break;
        case 8:
            s = "You have already sent your maximum kisses for today.";
            break; 
        case 9:
            s = "The recipient Member cannot be located.";
            break;
        case 10:
            s = "Sorry, but you have been blacklisted by this member.";
            break;
        default:
            s = "Error." + i;
            break;
    }    
    return s;
}
function SendMailReturn(originalRequest)
{
    var dataArray = originalRequest.responseXML.getElementsByTagName("list");
    var l = "";
    var imsg = 0;
    var b = false;
    if(dataArray.length > 0)
    {
        imsg = parseInt(dataArray[0].getAttribute("value"));
        if(imsg==1)
        {
            l = "Send Success!<label onclick=\"hiddensendmail()\" style=\"color: blue;\">close</label>";
            b = true;
        }
        else
            l = GetSendReturnError(imsg);
    }
    if(b)
    {
        $("subject").value = "";
        $("content").value = "";
       document.getElementById("divsendmailsubject").style.display = "none"; 
       document.getElementById("divsendmailcontent").style.display = "none";
       document.getElementById("divsendmailbutton").style.display = "none";
    }
    if(!$("divsendmailsuccess"))
    {
        var divreturn = document.createElement("div");
        divreturn.id = "divsendmailsuccess";
        divreturn.style.padding = "5px";
        divreturn.style.color = "red";
        divreturn.innerHTML = l;           
        document.getElementById("divsendmail").appendChild(divreturn);
    }
    else
    {
        document.getElementById("divsendmailsuccess").style.display = "";
        document.getElementById("divsendmailsuccess").style.color = "red";
        document.getElementById("divsendmailsuccess").innerHTML = l
    }

}
function hiddensendmail()
{
    document.getElementById("divsendmail").style.display = "none";
}
function SendKissStart()
{
    if($("divsendmail"))
        $("divsendmail").style.display = "none";
    if(!$("divsendkiss"))
    {
        var objdiv = document.createElement("div"); 
        objdiv.setAttribute("id", "divsendkiss");
        objdiv.style.margin = "10px";
        objdiv.style.backgroundColor = "#ffeeee";
        document.getElementById("divsend").appendChild(objdiv);
        
        var divsendkisstitle = document.createElement("div");
        divsendkisstitle.className= "displaylinedivsend";
        divsendkisstitle.innerHTML = "<a href=\"/user/sendkiss.aspx?userid=" + displayid + "&returnurl=/display.aspx?id=" + displayid + "\">Send Kiss</a>";
        document.getElementById("divsendkiss").appendChild(divsendkisstitle);
        
        var divsendkisscontent = document.createElement("div");
        divsendkisscontent.setAttribute("id","divsendkisscontent");
        divsendkisscontent.style.padding = "5px";
        document.getElementById("divsendkiss").appendChild(divsendkisscontent);
    
        var url = "/ajax.aspx?action=getkiss&d=" + new Date();
        var pars = "";
        var myAjax = new Ajax.Request(
            url,
            {method: 'post', parameters: pars, onComplete: GetKissListReturn}
            );
    }
    else
    {
        if($("divsendkiss").style.display == "none")
            $("divsendkiss").style.display = "";
        else
            $("divsendkiss").style.display = "none";
        document.getElementById("divsendkisscontent").style.display = "";
        if($("divsendkisssuccess"))
            document.getElementById("divsendkisssuccess").style.display = "none";
        $("sendkissbutton").disabled = false;
        $("sendkissbuttonclose").disabled = false;
    }
}
function GetKissListReturn(originalRequest)
{
    var dataArray = originalRequest.responseXML.getElementsByTagName("list");
    for(var i=0; i<dataArray.length; i++)
    {
        var divkisslist = document.createElement("div");
        divkisslist.innerHTML = "<div style=\"width: 90%;\"><div style=\"float: left;\"><input type=\"radio\" name=\"inputsendkissradio\" id=\"inputsendkissradio" + i + "\" value=\"" + dataArray[i].getAttribute("value") + "\" /></div> <div style=\"float: left;\"><label for=\"inputsendkissradio" + i + "\">" + dataArray[i].getAttribute("content") + "</label></div><div style=\"clear: both;\"></div></div>";
        document.getElementById("divsendkisscontent").appendChild(divkisslist);
    }
    var inputsendkissbutton = document.createElement("input");
    inputsendkissbutton.setAttribute("type", "button");
    inputsendkissbutton.setAttribute("id", "sendkissbutton");
    inputsendkissbutton.setAttribute("value", "Send Kiss");
    inputsendkissbutton.onclick = SendKiss;
    document.getElementById("divsendkisscontent").appendChild(inputsendkissbutton);
        
    var inputsendkissbuttonclose = document.createElement("input");
    inputsendkissbuttonclose.setAttribute("type", "button");
    inputsendkissbuttonclose.setAttribute("id", "sendkissbuttonclose");
    inputsendkissbuttonclose.setAttribute("value", "Close");
    inputsendkissbuttonclose.onclick = function(){ hiddensendkiss(); };
    inputsendkissbuttonclose.style.marginLeft = "12px";
    document.getElementById("divsendkisscontent").appendChild(inputsendkissbuttonclose);
}

function SendKiss()
{
    var sendkisspkid = 0;
    for(var i=0; i<document.getElementsByName("inputsendkissradio").length; i++)
    {
        if(document.getElementsByName("inputsendkissradio")[i].checked == true)
        {
            sendkisspkid = document.getElementsByName("inputsendkissradio")[i].value;
            break;
        }
    }
    if(sendkisspkid > 0)
    {
        $("sendkissbutton").disabled = true;
        $("sendkissbuttonclose").disabled = true;
        var url = "/ajax.aspx?action=sendkiss&d=" + new Date();
        var pars = "userid=" + displayid + "&kisspkid=" + sendkisspkid;
        var myAjax = new Ajax.Request(
            url,
            {method: 'post', parameters: pars, onComplete: SendKissReturn}
            );
    }
    else
        alert("Please choose which kiss to send.");
}

function SendKissReturn(originalRequest)
{
    var dataArray = originalRequest.responseXML.getElementsByTagName("list");
    var l = "";
    var imsg = 0;
    var b = false;
    if(dataArray.length > 0)
    {
        imsg = parseInt(dataArray[0].getAttribute("value"));
        if(imsg==1)
        {
            l = "Send Kiss Success!<label onclick=\"hiddensendkiss()\" style=\"color: blue;\">close</label>";
            b = true;
        }
        else
            l = GetSendReturnError(imsg);
    }
    if(b)
    {
        document.getElementById("divsendkisscontent").style.display = "none";
    }
    if(!$("divsendkisssuccess"))
    {
        var divsendkisssuccess = document.createElement("div");
        divsendkisssuccess.id = "divsendkisssuccess";
        divsendkisssuccess.style.padding = "5px";
        divsendkisssuccess.style.color = "red";
        divsendkisssuccess.innerHTML = l;
        document.getElementById("divsendkiss").appendChild(divsendkisssuccess);
    }
    else
    {
        document.getElementById("divsendkisssuccess").style.color = "red";
        document.getElementById("divsendkisssuccess").style.display = "";
        document.getElementById("divsendkisssuccess").innerHTML = l;
    }
}
function hiddensendkiss()
{
    document.getElementById("divsendkiss").style.display = "none";
}

function SubstringAboutyou()
{
    var aboutyou, tempaboutyou,l;
    l = cutdisplaystring;
    aboutyou = $("displayaboutyou").innerHTML;
    if(aboutyou.length > l)
    {
        $("displayaboutyou").innerHTML = "";
        var divcontent = document.createElement("div");
        divcontent.id = "divhiddenaboutyou";
        divcontent.innerHTML = aboutyou.substring(0, l) + "...";           
        $("displayaboutyou").appendChild(divcontent);

        var divhiddenaboutyoubar = document.createElement("div");
        divhiddenaboutyoubar.id = "divhiddenaboutyoubar";
        divhiddenaboutyoubar.style.padding = "5px 3px";
        divhiddenaboutyoubar.style.backgroundColor = "#f6f6f6";
        divhiddenaboutyoubar.style.color = "blue";
        divhiddenaboutyoubar.innerHTML = "....last " + (aboutyou.length - l) + " words. Click to view all.";
        divhiddenaboutyoubar.onclick = function(){HiddenOrShowAboutyou(this, true);};
        $("displayaboutyou").appendChild(divhiddenaboutyoubar);

        var objdiv = document.createElement("div");
        objdiv.innerHTML = "<textarea style=\"display: none;\" id=\"hiddeninputaboutyou\">" + aboutyou + "</textarea>";
        $("displayaboutyou").appendChild(objdiv);
    }
}
function HiddenOrShowAboutyou(t,b)
{
    var aboutyou;
    aboutyou = $("hiddeninputaboutyou").value;
    if(b)
    {
        $("divhiddenaboutyou").innerHTML = aboutyou;
        t.innerHTML = " Collapse";
        t.onclick = function(){HiddenOrShowAboutyou(this, false);};
    }
    else
    {
        $("divhiddenaboutyou").innerHTML = aboutyou.substring(0, cutdisplaystring) + "...";
        t.innerHTML = "....last " + (aboutyou.length - cutdisplaystring) + " words. Click to view all.";
        t.onclick = function(){HiddenOrShowAboutyou(this, true);};
    }
}

function HiddenOrShowDiv(id)
{
    if(document.getElementById(id).style.display=='')
        document.getElementById(id).style.display = 'none';
    else
        document.getElementById(id).style.display = '';
    sendEvent('stop');
}
function sendEvent(typ,prm){ 
    thisMovie("player_id").sendEvent(typ,prm); 
}
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
//取得用户中文翻译的结果
function GetUserChineseTranslation(t)
{
    t.style.color = "#cccccc";
    $("divtranslationenglishbutton").style.color = "#ffffff";
    if(isTraChinese)
    {
        $("headlinetranslation").innerHTML = strTraH_C;
        $("descriptiontranslation").innerHTML = strTraD_C;
        $("aboutyoutranslation").innerHTML = strTraA_C;
    }
    else
        GetUserTranslation(0);
}
//取得用户英文翻译的结果
function GetUserEnglishTranslation(t)
{
    t.style.color = "#cccccc";
    $("divtranslationchinesebutton").style.color = "#ffffff";
    if(isTraEnglish)
    {        
        $("headlinetranslation").innerHTML = strTraH_E;
        $("descriptiontranslation").innerHTML = strTraD_E;
        $("aboutyoutranslation").innerHTML = strTraA_E;
    }
    else
        GetUserTranslation(1);
}
function GetUserTranslation(tt)
{
    var url = "/ajax.aspx?action=getuserinfotranslation&date=" + new Date();
    var pars = "userid=" + displayid + "&translationtype=" + tt + "&h=" + iHeadline + "&d=" + iDescription + "&a=" + iAboutyou;
    if(iHeadline == 1)
    {
        $("headlinetranslation").innerHTML = "Translation in progress...";
        $("headlinetranslation").className = "translationclass";
        $("headlinetranslation").style.display = "";
    }
    else
        $("headlinetranslation").style.display = "none";
    if(iDescription == 1)
    {
        $("descriptiontranslation").innerHTML = "Translation in progress...";
        $("descriptiontranslation").className = "translationclass";
        $("descriptiontranslation").style.display = "";
    }
    else
        $("descriptiontranslation").style.display = "none";
    if(iAboutyou == 1)
    {
        $("aboutyoutranslation").innerHTML = "Translation in progress...";
        $("aboutyoutranslation").className = "translationclass";
        $("aboutyoutranslation").style.display = "";
    }
    else
        $("aboutyoutranslation").style.display = "none";
    if(tt == 0)
        var myAjax = new Ajax.Request(
                            url,
                            {
                                method: 'post',
                                parameters: pars,
                                onFailure: ReturnUserTranslationFail,
                                onComplete: ReturnUserTranslationChinese
                            });
    else
        var myAjax = new Ajax.Request(
                        url,
                        {
                            method: 'post',
                            parameters: pars,
                            onFailure: ReturnUserTranslationFail,
                            onComplete: ReturnUserTranslationEnglish
                        });
}
function ReturnUserTranslationFail(originalRequest)
{
    $("headlinetranslation").innerHTML = "Translation error...";
    $("descriptiontranslation").innerHTML = "Translation error...";
    $("aboutyoutranslation").innerHTML = "Translation error...";
    isTraChinese = true;
    isTraEnglish = true;
}
function ReturnUserTranslationChinese(originalRequest)
{
    var dataArray = originalRequest.responseXML.getElementsByTagName("list");
    if(dataArray.length > 0)
    {
        $("headlinetranslation").innerHTML = dataArray[0].getAttribute("headline");
        $("descriptiontranslation").innerHTML = dataArray[0].getAttribute("description");
        $("aboutyoutranslation").innerHTML = dataArray[0].getAttribute("aboutyou");
    }
    else
    {
        $("headlinetranslation").innerHTML = "Translation error...";
        $("descriptiontranslation").innerHTML = "Translation error...";
        $("aboutyoutranslation").innerHTML = "Translation error...";
    }
    strTraH_C = $("headlinetranslation").innerHTML;
    strTraD_C = $("descriptiontranslation").innerHTML;
    strTraA_C = $("aboutyoutranslation").innerHTML;
    isTraChinese = true;
}
function ReturnUserTranslationEnglish(originalRequest)
{
    var dataArray = originalRequest.responseXML.getElementsByTagName("list");
    if(dataArray.length > 0)
    {
        $("headlinetranslation").innerHTML = dataArray[0].getAttribute("headline");
        $("descriptiontranslation").innerHTML = dataArray[0].getAttribute("description");
        $("aboutyoutranslation").innerHTML = dataArray[0].getAttribute("aboutyou");
    }
    else
    {
        $("headlinetranslation").innerHTML = "Translation error...";
        $("descriptiontranslation").innerHTML = "Translation error...";
        $("aboutyoutranslation").innerHTML = "Translation error...";
    }
    strTraH_E = $("headlinetranslation").innerHTML;
    strTraD_E = $("descriptiontranslation").innerHTML;
    strTraA_E = $("aboutyoutranslation").innerHTML;
    isTraEnglish = true;
}
function CheckPhotoPassword(){
    var url = "/ajax.aspx?action=checkphotopassword&date=" + new Date();
    var photopassword;
    photopassword = $F("inputphotopassword");
    if(photopassword.length > 0){
        var pars = "userid=" + displayid + "&password=" + $F("inputphotopassword");
        var myAjax = new Ajax.Request(
                        url,{
                            method: 'post',
                            parameters: pars,
                            onFailure: CheckPhotoPasswordFail,
                            onComplete: CheckPhotoPasswordCom});
    }else
        alert("Submit password!");
}
function CheckPhotoPasswordFail(originalRequest){
    alert("error!");
}
function CheckPhotoPasswordCom(originalRequest){
    var dataArray = originalRequest.responseXML.getElementsByTagName("list");
    var ImageUrlTemp;
    ImageUrlTemp = "s"
    if(dataArray.length > 0){
        if(dataArray[0].getAttribute("value") == 1){
            for(i=1; i<dataArray.length; i++){
                if(dataArray[i].getAttribute("flag") == 1)
                    ImageUrlTemp = "m";
                else
                    ImageUrlTemp = "s";
                $("lightbox_" + i).setAttribute("rel", "lightbox[kkbac]");
                $("lightbox_" + i).setAttribute("title", dataArray[i].getAttribute("msg"));
                $("lightbox_" + i).setAttribute("href", "/files/images/userimages/" + dataArray[i].getAttribute("photo"));
                $("lightbox_" + i).setAttribute("target", "_blank");
                $("lightbox_image_" + i).setAttribute("src", "/files/images/userimages/" + ImageUrlTemp + dataArray[i].getAttribute("photo"));
                $("lightbox_" + i).onclick = function (){myLightbox.start(this); return false;} 
            }
            $("divphotopassword").innerHTML = "Loading....";
            PhotoLoading();
        }else
            alert("Password Incorrect!");
    }else{
        alert("error!");
    }
}
var photoload = 1;
var photoloadtol = 0;
function PhotoLoading(){
    if(photoload>10) photoload = 1;
    var l = "";
    for(var i=0;i<photoload;i++)
        l += " . ";
    $("divphotopassword").innerHTML = "Loading" + l;
    photoload++;
    if(photoloadtol<10){photoloadtol++;setTimeout(PhotoLoading,300);}else{ClosePhotoPassword();}
}
function ShowPasswordInput(event){
    var id = "divphotopassword";
    var mx = Event.pointerX(event) + "px";
    var my = Event.pointerY(event) + 12 + "px";
    var p = $(id);
    if(p){
        p.style.left = mx;
        p.style.top = my;
        Element.show(p);
    }else{
        var div = document.createElement("div");
        div.setAttribute("id", id);
        div.style.position = "absolute";
        div.style.top = my;
        div.style.left = mx;
        div.style.zIndex = "100";
        div.style.border = "solid 1px #ddd";
        div.style.padding = "8px";
        div.style.backgroundColor = "#ffa";
        div.style.fontWeight = "bold";
        document.body.appendChild(div);//end
        var label = document.createElement("label");
        label.innerHTML = "This photo is locked. Password required: ";
        $(id).appendChild(label);
        var input = document.createElement("input");
        input.setAttribute("id","inputphotopassword");
        input.setAttribute("type","password");
        input.setAttribute("size","12");
        input.setAttribute("maxlength","30");
        input.style.fontSize = "12px";
        input.style.lineHeight = "14px";
        input.style.height = "14px";
        input.style.padding = "0px 2px";
        input.style.margin = "0px 1px";
        input.style.border = "0px";
        input.style.color = "#a50000";
        input.style.borderBottom = "1px #ccc solid";
        input.style.backgroundColor = "#ffa";
        $(id).appendChild(input);
        var a = document.createElement("a");
        a.innerHTML = " Submit ";
        a.style.cursor = "pointer";
        a.onclick = CheckPhotoPassword;
        $(id).appendChild(a);
        var b = document.createElement("a");
        b.innerHTML = " Close ";
        b.style.cursor = "pointer";
        b.onclick = ClosePhotoPassword;
        $(id).appendChild(b);
    }
}
function ClosePhotoPassword(){
    Element.hide($("divphotopassword"));
}
function AddFavourite(){
    return confirm("Do you wish to add this member to your favourites list so you can find her easily? If so click \"yes\"");
}
function AddBlackList(){
    return confirm("Do you wish to add this member to your blacklist so they can't contact you? If so click \"yes\"");
}