﻿var bDefault
var iIEversion
function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");

    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}
$(document).ready(function() {
    $('textarea').elastic();
    iIEversion = getIEVersionNumber()
    var str = location.href

    if (str.substring(str.lastIndexOf('/') + 1, eval(str.lastIndexOf('/') + 2)).toLowerCase() == "#" || str.substring(str.lastIndexOf('/') + 1, eval(str.lastIndexOf('/') + 8)).toLowerCase() == "default" || str.substring(str.lastIndexOf('/') + 1, eval(str.lastIndexOf('/') + 8)).toLowerCase() == "") {

        $get('Consultancy1_txtComment').value = "write comment..";
        $get('Consultancy1_txtComment').className = "CommentText";
        $get('Consultancy1_txtComment').style.height = "15px";

        $get('Consultancy1_txtFullName').value = "your name here..";
        $get('Consultancy1_txtFullName').className = "CommentText";
        $get('Consultancy1_txtFullName').style.height = "15px";

        $get('Consultancy1_txtEmail').value = "your mail here..";
        $get('Consultancy1_txtEmail').className = "CommentText";
        $get('Consultancy1_txtEmail').style.height = "15px";

        bDefault = true

        $get('divDots').style.visibility = "visible";

    } else {
        for (i = 0; i <= $get('txtNumber').value; i++) {
            if (i < 10) {
                i = "0" + i
            }
            $get('lstComment_ctl' + i + '_txtComment').value = "write comment..";
            $get('lstComment_ctl' + i + '_txtComment').className = "CommentText";
            $get('lstComment_ctl' + i + '_txtComment').style.height = "15px";

            if (iIEversion == 7) {
                $get('lstComment_ctl' + i + '_divQA').style.height = "44px";
            }
        }
        if ($get('txtOpenOnload').value == 1) {
            openQA('lstComment_ctl00_divQA', 'lstComment_ctl00_divQAinner', 'lstComment_ctl00_DivMore', 'lstComment_ctl00_DivLess');
        }
        $get('txtOpenOnload').value = 0
        bDefault = false
    }

    if (bDefault) {
//        if ($get('divQAinner').offsetHeight > 100) {
//            $get('divDots').style.visibility = "visible";
//        } else {
//            $get('divDots').style.visibility = "hidden";
//        }

        if ($get('divQAinner').offsetHeight < 70) {
            $get('DivMorePic').style.visibility = "hidden"
            $get('DivMore').style.visibility = "hidden"
            $get('DivLess').style.visibility = "hidden"
            $get('DivLessPic').style.visibility = "hidden"
        }
        $get('Consultancy1_txtQuestion').style.height = "15px";
        $get('Consultancy1_txtQuestion').className = "CommentText";
        $get('Consultancy1_txtQuestion').value = "write question..";
    } else {
        if ($get('txtQuestion').value == "") {
            $get('txtQuestion').value = "write question..";
            $get('txtQuestion').className = "QuestionTextBox";
        }
    }
});
function txtFocus(id) {
    if (id == 'Consultancy1_txtQuestion') {
        if ($get(id).value == "write question..") {
            $get(id).value = ""
            $get(id).style.height = "30px";
            $get(id).className = "CommentText";
        }
    } else if (id == 'txtQuestion') {
        if ($get(id).value == "write question..") {
            $get(id).value = ""
            $get(id).className = "QuestionTextBox";
        }
    } else if (id == 'Consultancy1_txtFullName') {
        if ($get(id).value == "your name here..") {
            $get(id).value = ""
        }
    } else if (id.substring(id.lastIndexOf('_') + 1, id.length) == 'txtComment') {
        if ($get(id).value == "write comment..") {
            $get(id).value = ""
            $get(id).style.height = "30px";
        }
    } else if (id.substring(id.lastIndexOf('_') + 1, id.length) == 'txtEmail') {
        if ($get(id).value == "your mail here..") {
            $get(id).value = ""
        }
    } else if (id == 'txtCarMake') {
        if ($get(id).value == "Make") {
            $get(id).value = "";
            $get(id).style.width = "75px";
        }
    } else if (id == 'TxtCarModel') {
        if ($get(id).value == "Model") {
            $get(id).value = "";
            $get(id).style.width = "75px";
        }
    } else if (id == 'TxtCarYear') {
        if ($get(id).value == "Year") {
            $get(id).value = "";
            $get(id).style.width = "75px";
        }
    }
    $get(id).className = "InfoText";
}

function CommentVisibility(vOptional) {
    if (vOptional == undefined) {
        vOptional = 'divComment';
    }
    if ($get(vOptional).style.position == "static") {
        $get(vOptional).style.position = "absolute";
        $get(vOptional).style.visibility = "hidden";
    } else {
        $get(vOptional).style.position = "static";
        $get(vOptional).style.visibility = "visible";
    }
}
function txtBlur(id) {
    // alert(id + "::::" + $get(id).value + ":::" + id.substring(id.lastIndexOf('_') + 1, id.length));
    if (id == 'Consultancy1_txtQuestion') {
        $get(id).className = "CommentFullText"
        if ($get(id).value == "") {
            $get(id).value = "write question.."
            $get(id).style.height = "18px";
            $get(id).className = "CommentText"
        }
    } else if (id == 'txtQuestion') {
        $get(id).className = "QuestionTextBox"
        if ($get(id).value == "") {
            $get(id).value = "write question.."
        }
    } else if (id == 'Consultancy1_txtFullName') {
        $get(id).className = "CommentFullText"
        if ($get(id).value == "") {
            $get(id).value = "your name here.."
            $get(id).className = "CommentText"
        }
    } else if (id.substring(id.lastIndexOf('_') + 1, id.length) == 'txtComment') {
        $get(id).className = "CommentFullText"
        if ($get(id).value == "") {
            $get(id).value = "write comment.."
            $get(id).className = "CommentText"
            $get(id).style.height = "18px";
        }
    } else if (id.substring(id.lastIndexOf('_') + 1, id.length) == 'txtEmail') {
        $get(id).className = "CommentFullText"
        if ($get(id).value == "") {
            $get(id).value = "your mail here.."
            $get(id).className = "CommentText"
        }
    } else if (id == 'txtCarMake') {
        $get(id).className = "SmallTextBox";
        if ($get(id).value == "") {
            $get(id).value = "Make";
        }
    } else if (id == 'TxtCarModel') {
        $get(id).className = "SmallTextBox"
        if ($get(id).value == "") {
            $get(id).value = "Model";

        }
    } else if (id == 'TxtCarYear') {
        $get(id).className = "SmallTextBox"
        if ($get(id).value == "") {
            $get(id).value = "Year";

        }
    }
}
var vHeight;
var i = 0
function openQA(divQA, divQAinner, divMore, divLess) {
    if (divQA == undefined) {
        divQA = 'divQA';
    }
    if (divQAinner == undefined) {
        divQAinner = 'divQAinner';
    }
    vHeight = setInterval('enlargeHeight("' + divQA + '","' + divQAinner + '","' + divMore + '","' + divLess + '")', 15);
}
function enlargeHeight(divQA, divQAinner, divMore, divLess) {
    var height = ($get(divQA).style.height.substring(0, $get(divQA).style.height.lastIndexOf("px")));
    if (height == "") {
        height = $get(divQA).offsetHeight;
    }

    height = eval(parseInt(height) + 3 * i);
    i += 0.3
    $get(divQA).style.height = height + "px"
    var maxHeight;
    if (bDefault) {
        maxHeigh = 75;
    } else {
        maxHeigh = $get(divQAinner).offsetHeight - 2;
    }
    if (height > maxHeigh) {
        if (bDefault) {
//            if ($get(divQAinner).offsetHeight > 100) {
//                $get('divDots').style.visibility = "visible";
//            } else {
//                $get('divDots').style.visibility = "hidden";
//            }
        }
        $get(divQA).style.height = maxHeigh + "px";
        clearInterval(vHeight)
        $get(divQAinner).style.overflow = "auto"
        if (bDefault) {
            $get('DivMorePic').style.visibility = "hidden"
            $get('DivMore').style.visibility = "hidden"
            $get('DivLess').style.visibility = "visible"
            $get('DivLessPic').style.visibility = "visible"
        } else {
            $get(divMore).style.visibility = "hidden";
            $get(divLess).style.visibility = "visible";
        }

        i = 0;
    }
}
function closeQA(divQA, divQAinner, divMore, divLess) {
    if (divQA == undefined) {
        divQA = 'divQA';
    }
    if (divQAinner == undefined) {
        divQAinner = 'divQAinner';
    }
    vHeight = setInterval('initialHeight("' + divQA + '","' + divQAinner + '","' + divMore + '","' + divLess + '")', 15);
}
function initialHeight(divQA, divQAinner, divMore, divLess) {
    var height = ($get(divQA).style.height.substring(0, $get(divQA).style.height.lastIndexOf("px")));
    height = eval(parseInt(height) - 3 * i);
    i += 0.3
    $get(divQA).style.height = height + "px"
    var minHeight
    if (bDefault) {
        vInitialHeight = 39
    } else {
        if (iIEversion == 7) {
            vInitialHeight = 44.5;
        } else {
            vInitialHeight = 41;
        }
    }
    if ($get(divQAinner).offsetHeight <= vInitialHeight) {
        minHeight = $get(divQAinner).offsetHeight
    } else {
        minHeight = vInitialHeight
    }
    if (height < minHeight) {
        if (bDefault) {
//            if ($get(divQAinner).offsetHeight > 100) {
//                $get('divDots').style.visibility = "visible";
//            } else {
//                $get('divDots').style.visibility = "hidden";
//            }
        }
        $get(divQA).style.height = minHeight + "px";
        clearInterval(vHeight)
        $get(divQAinner).style.overflow = "visible"
        if (bDefault) {
            $get('DivMorePic').style.visibility = "visible"
            $get('DivLessPic').style.visibility = "hidden"
            $get('DivMore').style.visibility = "visible"
            $get('DivLess').style.visibility = "hidden"
        } else {
            $get(divMore).style.visibility = "visible"
            $get(divLess).style.visibility = "hidden"
        }

        i = 0;
    }

}

function doValidation(id) {
    var EmailID;
    var CommentID;
    EmailtxtID = id + 'txtEmail';
    EmaillblID = id + 'lblEmail';
    CommenttxtID = id + 'txtComment';
    if ($get(EmailtxtID).value == "" || $get(EmailtxtID).value == "your mail here..") {
        $get(id + 'lblDeny').innerText = "Please enter your mail";
        $get(id + 'divDeny').style.visibility = "visible";
    } else if ($get(EmailtxtID).value != $get(EmaillblID).value) {
        $get(id + 'lblDeny').innerText = "You are not allow to comment because you are not the owner of this thread";
        $get(id + 'divDeny').style.visibility = "visible";
    } else if ($get(CommenttxtID).value == "" || $get(CommenttxtID).value == "write comment..") {
        $get(id + 'lblDeny').innerText = "Please write your comment.";
        $get(id + 'divDeny').style.visibility = "visible";
    } else {
        __doPostBack('', $get(id + 'txtIndex').value);
    }
}
function doValidationHomePage() {
    if ($get('Consultancy1_txtEmail').value == "" || $get('Consultancy1_txtEmail').value == "your mail here..") {
        $get('Consultancy1_lblDeny').innerText = "Please enter your mail";
        $get('divDeny').style.visibility = "visible";
    } else if ($get('Consultancy1_lblEmail').value != $get('Consultancy1_txtEmail').value) {
        $get('Consultancy1_lblDeny').innerText = "You are not allow to comment because you are not the owner of this thread";
        $get('divDeny').style.visibility = "visible";
    } else if ($get('Consultancy1_txtComment').value == "" || $get('Consultancy1_txtComment').value == "write comment..") {
        $get('Consultancy1_lblDeny').innerText = "Please write your comment.";
        $get('divDeny').style.visibility = "visible";
    } else {
        __doPostBack('', '1');
    }
}
var tListMove
var speedOfList = 10
var MaskHeight = 450
function listMoveUp() {
    tListMove = setTimeout('MoveUpTheList()', 1)
}
function listMoveDown() {
    tListMove = setTimeout('MoveDownTheList()', 10)
}
function MoveUpTheList() {
    var topList = ($get('list').style.top.substring(0, $get('list').style.top.lastIndexOf("px")));
    if ($get('list').offsetHeight > MaskHeight) {
        if (topList > (MaskHeight - $get('list').offsetHeight)) {
            $get('list').style.top = topList - speedOfList + "px";
            clearInterval(tListMove);
            tListMove = setTimeout('MoveUpTheList()', 1)
        } else {
            clearInterval(tListMove);
        }
    }
}
function MoveDownTheList() {
    var topList = ($get('list').style.top.substring(0, $get('list').style.top.lastIndexOf("px")));
    if (topList >= 0) {
        $get('list').style.top = "0px";
        clearInterval(tListMove);
    } else {
        $get('list').style.top = eval(parseInt(topList) + speedOfList) + "px";
        clearInterval(tListMove);
        tListMovesetT = setTimeout('MoveDownTheList()', 10)
    }

}
function listStop() {
    clearInterval(tListMove);
}
