/// <reference path="jquery-1.3.2-vsdoc.js" />
function ShowFriend(id) {
    currentStatus = $('#friend' + id).css("display");
    //currentStatus = $(take).attr("display");
    if (currentStatus == 'none') {
    document.getElementById('friend' + id + '_left').style.display = 'block';
    document.getElementById('friend' + id).style.display = 'block';
    currentHeigh = $('#box_tell_friend').height();
    newHeight = currentHeigh + 62;
    $('#box_tell_friend').height(newHeight);
    document.getElementById('friendPlus' + id).style.display = 'none';
    }   
}
function openFeedback() {
    /*if(opened)
    {*/
    document.FormFeedBack.reset();
    document.getElementById("insertNws").innerHTML = "";
    document.getElementById("insertNws3").innerHTML = "";
    document.getElementById('feedback').style.width = 315 + 'px';
    document.getElementById('feedback_content').style.display = 'block';
    document.getElementById('close_feedback').style.display = 'block';
    opened = false;
    /*}
    else{
    document.getElementById('feedback').style.width = 0 +'px';
    document.getElementById('feedback_content').style.display = 'none';
    document.getElementById('close_feedback').style.display = 'none';
    opened = true;
    }*/
}
function closeFeedback() {

    document.getElementById('feedback').style.width = 0 + 'px';
    document.getElementById('feedback_content').style.display = 'none';
    document.getElementById('close_feedback').style.display = 'none';
    document.getElementById("insertNws3").innerHTML = "";
    document.getElementById("insertNws").innerHTML = "";
}
function saveFeedBack() {
    thisurl = document.getElementById('url_feedback').value;
    contentObj = document.getElementById('insertNws2');
    email1 = document.getElementById('email_feedback').value;
    topic1 = document.getElementById('topic').value;
    MessageFeedBack1 = document.getElementById('MessageFeedBack').value;
    queryFeed = "";

    AtPos = email1.indexOf("@")
    StopPos = email1.lastIndexOf(".")
    if (AtPos == -1 || StopPos == -1) {
        queryFeed = queryFeed + "<font style='font-family:Tahoma; font-size:11px;text-align:right; padding-right:10px;'>- البريد إلكتروني إلزامي.</font><br/>";
    }

    if (email1 == "") {

    }

    if (MessageFeedBack1 == "") {
        queryFeed = queryFeed + "<font style='font-family:Tahoma; font-size:11px;text-align:right; padding-right:10px;'>- الرسالة إلزامية.</font><br/>";
    }
    if (queryFeed == "") {
        //document.getElementById('FormFeedBack').submit();
        var poststr = "?email1=" + encodeURI(email1) + "&topic1=" + encodeURI(topic1) + "&MessageFeedBack1=" + encodeURI(MessageFeedBack1);
        // alert(thisurl+poststr);
        postAjaxFile(thisurl + poststr, "");
        document.getElementById("insertNws3").innerHTML = "<font style='font-family:Tahoma; font-size:11px;text-align:right; padding-right:10px;'>- لقد تم إرسال المعلومات.</font><br/>";
        //postAjaxFile("FeedBack/saveFeedBack.asp",poststr)
    }
    else {
        document.getElementById("insertNws3").innerHTML = queryFeed;
    }
}
function goAdvSearch(chk, url) {
    document.getElementById('load_search').style.display = 'block';
    catid = "";
    keySearch1 = document.getElementById('keySearch').value;
    item_list1 = document.getElementById('item_list').value;
    for (i = 0; i < chk.length; i++) {
        if (chk[i].checked == true) {
            catid = catid+""+chk[i].value + ";";
    }
}
     contentObj = document.getElementById('result_container');
     getAjaxFile(url + "?keySearch=" + keySearch1 + "&item_list=" + item_list1 + "&catid=" + catid);
}
checked_all = false;
function CheckAll(chk) {
    if (checked_all == false) {
        for (i = 0; i < chk.length; i++) {
            chk[i].checked = true;
        }
        checked_all = true;
    }
    else {
        for (i = 0; i < chk.length; i++) {
            chk[i].checked = false;
        }
        checked_all = false;
    }
}
function closeCalendar(day, month, year) {
    
    closeAllCalendar();
}
function closeAllCalendar() {
    document.getElementById('calendar_content0').style.display = 'none';
    document.getElementById('calendar_content1').style.display = 'none';
    document.getElementById('calendar0').innerHTML = '';
    document.getElementById('calendar1').innerHTML = '';
}
function ShowOther() {
    document.getElementById('vote_other').style.display = 'block';
}
function HideOther() {
    document.getElementById('vote_other').style.display = 'none';
}
function ShowMata(id, url, arTitle) {
    document.getElementById('mata_box' + id).style.display = 'block';
    if (document.getElementById('box_address' + id)) {
    document.getElementById('box_address' + id).style.display = 'none';
}
if (document.getElementById('selArtTitle')) {
    document.getElementById('selArtTitle').value = arTitle;
}
if (document.getElementById('selArtId')) {
    document.getElementById('selArtId').value = id;
}
    document.getElementById('articleId').value = id;
    document.getElementById('calendar' + id).innerHTML = '<div id="newsDateDiv"></div>';
    LoadCalendar(url);
}
function ShowCal(id, url) {
    closeAllCalendar();
    document.getElementById('calendar_content' + id).style.display = 'block';
    document.getElementById('calendar' + id).innerHTML = '<div id="newsDateDiv"></div>';
    LoadCalendar(url);
}
function LoadCalendar(url) {
    displayCal(url, 'newsDateDiv', 'varDate', false, false, '', 'dd/MM/yyyy', '', false, true, false);
}
function CLoseMata(id) {
    document.getElementById('mata_box' + id).style.display = 'none';
    document.getElementById('calendar' + id).innerHTML = '';
}
function CheckUpload() {
    userid = document.getElementById('sessionUserId').value;
    if (userid != 0) {
        pictureName = document.getElementById('picName').value;
        pictureI = document.getElementById('picture').value;
        if (pictureName == "" || pictureI == "") {
            document.getElementById('comp_required').style.display = 'block';
            document.getElementById('comp_message').style.display = 'none';
        }
        else {
            document.getElementById('comp_required').style.display = 'none';
            //document.getElementById('comp_message').style.display = 'block';
            document.getElementById('form1').submit();
        }
        //document.getElementById('form1').submit();
    }
    else {
        showOpacity();
    }
}
function ChangeMap(url) {
    catid = document.getElementById('catmapID').value;
    document.getElementById('Mapframe').src = url + catid;
}
function OpenDropTouristic() {
    document.getElementById('drop_div').style.display = 'block';
}
function ChangeDropTouristic(pic, text, id) {
    document.getElementById('drop_text').innerHTML = text;
    document.getElementById('drop_pic').src = pic;
    document.getElementById('drop_div').style.display = 'none';
    document.getElementById('catmapID').value = id;
}
var urltype1 = "0";
function CheckUserComment(urlType, arId) {
    userid = document.getElementById('sessionUserId').value;
    if (userid != 0) {
        //        document.getElementById('form1').submit();
        //alert($('#SentToComment').val());
        $.post($('#SentToComment').val(), { c_articleId: $('#c_articleId').val(), com_name: $('#com_name').val(), com_user: $('#com_user').val(), com_message: $('#com_message').val() },
                function(data) {
                    if (data != "" && data != null) {
                        var message = $("#com_message").val();
                        var FBID = document.getElementById('sessionFBID').value;
                        
                        $("#commentarea").prepend(data);
                        var x = $("#commentarea > div");
                        $(x[0]).show(500);
                        $('.nb_ta3lik').html(parseInt($('.nb_ta3lik').html()) + 1);
                        $('#com_message').val('اكتب تعليقك');
                        //alert(data);
                        //window.location.reload();
                        if (urlType == "1") {
                            urlType = "CatDetails";
                        }
                        else {
                            urlType = "ActDetails";
                        }
                        var linkToUse = 'http://mamlakati.com.sa/Home/' + urlType + '/' + arId;
                        DisplayMsgFBComment("أضاف تعليق على", message, linkToUse, FBID);
                    }
                    else {
                        //alert("Something went wrong during form submission. Please try again.");
                    }
                });
       
    }
    else {
        if (urlType == "1") {
            urltype1 = "1";
        }
        else {
            urltype1 = "2";
        }
        showOpacity();
    }
}
function showOpacity() {
    document.getElementById('opacitiDiv').style.display = 'block';
    document.getElementById('facebook_wrapper_opacity').style.display = 'block';
    window.scroll(0, 0);
    if (document.getElementById('Centerwrapper') != null) {
        document.getElementById('opacitiDiv').style.height = document.getElementById('Centerwrapper').offsetHeight + "px";
    }
}
var FBAPPID = 163937740316965;
function ChangeCity(id, url) {
    contentObj = document.getElementById('CatList');
    getAjaxFile(url + "/" + id);
}
function ShowByEval(url) {
    document.getElementById('evaluation').className = 'evaluation';
    document.getElementById('ajaxLoader').className = 'ajaxLoaderS';
    document.getElementById('drop_location').style.display = 'none';
    contentObj = document.getElementById('CatList');
    getAjaxFile(url);
}
function ShowDropLoc() {
    document.getElementById('drop_location').style.display = 'block';
    document.getElementById('spacerDrop').style.display = 'block';
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
function ShareMsg(elem, msg, link) {
    FName = document.getElementById('sessionFName').value;
    LName = document.getElementById('sessionLName').value;
    var title = $(elem).parent().parent().parent().parent().find(".title").html();
    //msg = FName + " " + LName + " " + msg;
    msg = msg + "<br/>"
    DisplayMsgFB(title, msg, link);
}
function DisplayMsgFB(title, msg, link) {

    try {
        FB.ui({
            method: 'stream.publish',
            attachment: {
                name: title,
                caption: msg,
                description: link,
                href: link
            },
            action_links: ''
        }, function(response) {
            if (response && response.post_id) {
                //alert('Post was published.');
            } else {
                //alert('Post was not published.');
            }
        });
    } catch (exception) {
        alert('exception');
    }
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
function ShareMsgComment(elem, msg, link) {
    FName = document.getElementById('sessionFName').value;
    LName = document.getElementById('sessionLName').value;
    FBID = document.getElementById('sessionFBID').value;
    var title = $(".title").html();
    //msg = FName + " " + LName + " " + msg;
    DisplayMsgFBComment(title, msg, link, FBID);
}
function DisplayMsgFBComment(title, msg, link, to) {

    //    var path = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(link) + "&t=" + encodeURIComponent(title);
    //    var popUp = window.open(path, msg, 'height=450,width=550,resizable=1');
    var picture = $('#main_picture').find('img').attr("src");
    title = $('.wrapper_information > .title').html();
    FB.ui({
        "method": 'stream.publish',
        "display": "popup",
        "name": title,
        "description": msg,
        "link": link,
        "picture": picture,
        "message": msg,
        "caption": '',
        "to": to
    }, function(response) { }
		);
}	

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
function calHeight() {
    x = document.getElementById('main_picture').offsetHeight;
    document.getElementById('div_desc').style.minHeight = x + "px";
}
function loginFBCallback(response) {
    if (response != null) {
        //alert("welcome "+response.first_name+" "+response.last_name);
        if (window.DOMParser) {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(response, "text/xml");
        }
        else // Internet Explorer
        {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(response);
        }
        FirstName = xmlDoc.getElementsByTagName("user")[0].attributes.getNamedItem("FirstName").nodeValue;
        LastName = xmlDoc.getElementsByTagName("user")[0].attributes.getNamedItem("LastName").nodeValue;
        UserId = xmlDoc.getElementsByTagName("user")[0].attributes.getNamedItem("UserId").nodeValue;
        FBID = xmlDoc.getElementsByTagName("user")[0].attributes.getNamedItem("FBID").nodeValue;
        document.getElementById('welcomeText').style.display = 'block';
        document.getElementById('f_connect').style.display = 'none';
        document.getElementById('facebook_name').innerHTML = FirstName;
        document.getElementById('khourouj').style.display = 'block';
        document.getElementById('facebook_wrapper').style.display = 'none';
        document.getElementById('sessionUserId').value = UserId;
        document.getElementById('sessionFName').value = FirstName;
        document.getElementById('sessionLName').value = LastName;
        document.getElementById('sessionFBID').value = FBID;
        CloseFacebook('facebook_wrapper_opacity');
        if (urltype1 != 0) {
            if (urltype1 == "1") {
                CheckUserComment('1', $('#c_articleId').val());
            }
            else {
                CheckUserComment('2', $('#c_articleId').val());
            }
        }    
    
        //NewSession(UserId);
    }
    else {
        // alert("error log in");
    }

}
isFacebookUserLoggedIn = true;
function checkFBUser() {
    var userid = document.getElementById('sessionUserId').value;
    if (FB != null && FB.getSession() != null) {
        FirstName = document.getElementById('sessionFName').value;
        LastName = document.getElementById('sessionLName').value;
        UserId = userid;
        document.getElementById('welcomeText').style.display = 'block';
        document.getElementById('f_connect').style.display = 'none';
        document.getElementById('facebook_name').innerHTML = FirstName;
        document.getElementById('khourouj').style.display = 'block';
        document.getElementById('facebook_wrapper').style.display = 'none';
    }
    else {
        try {
            if (FB != null) {
                logoutFromFacebook();
            }
        } catch (exception) {

        }
    }
}
function logoutFBCallback() {
    document.getElementById('f_connect').style.display = 'block';
    document.getElementById('welcomeText').style.display = 'none';
    document.getElementById('facebook_name').innerHTML = "";
    document.getElementById('khourouj').style.display = 'none';
    document.getElementById('sessionUserId').value = 0;
    document.getElementById('sessionFName').value = "";
    document.getElementById('sessionLName').value = "";
}
function DropSubCat(id, url) {
    if (id == 0) {
        document.getElementById('div_subloc').innerHTML = "";
        document.getElementById('div_subloc').innerHTML = "<input name='dirId' id='dirId' type='hidden' value='0' /><span style='padding-right:14px;'> إختر فئة فرعية </span>";
    }
    else {
        contentObj = document.getElementById('div_subloc');
        getAjaxFile(url + "/" + id);
    }
}
function Searchdir(url) {
    divcatid = document.getElementById('divcatId').value;
    catid = document.getElementById('dirId').value;
    window.location = url + divcatid + "/" + catid;
}

function goCalendar(month, year) {
    url = document.getElementById('urlCalendar').value;
    window.location = url + "/" + month + "/" + year;
}
function submitVote(url,url2) {
    userid = document.getElementById('sessionUserId').value;
    answerId = 0;
    if (userid != 0) {
        acounter = document.getElementById('ans_counter').value;
        vote_other_value = document.getElementById('vote_other').value;
        for (var i = 1; i <= acounter; i++) {
            if (document.getElementById('vote_ans' + i).checked == true) {
                answerId = document.getElementById('vote_ans' + i).value;
            }
        }
        if (answerId == 0 && vote_other_value == '') {
            alert("all answers are empty");
        }
        else {
            document.getElementById('btn_vote').style.display = 'none';
            document.getElementById('box_results').style.display = 'block';
            contentObj = document.getElementById('vote_result');
            getAjaxFile(url + "/" + answerId + "/" + userid + "?other=" + vote_other_value);
            OpenResult(url2, 'question_answer', 'box_results', 1);
        }
    }
    else {
        showOpacity();
    }
}
function AddLike(userid, id, url) {
    userid = document.getElementById('sessionUserId').value;
    if (userid != 0) {
        contentObj = document.getElementById('likeid' + id);
        getAjaxFile(url + userid + "/" + id);
        document.getElementById('icon_like' + id).className = 'icon_like nocursor';
    }
    else {
        showOpacity();
    }
}
var mouseisinsidelike = 0;
function setmouseenter() {
    //alert("test");
    $('#ActDetail').find(".icon_like").mouseenter(function() {
        mouseisinsidelike = 1;
    }).mouseleave(function() {
        mouseisinsidelike = 0;
    });
}
function ChangeMainArt(url) {
    contentObj = document.getElementById('listArticles');
    getAjaxFile(url);
}
function ChangeLeftActivty(url) {
    contentObj = document.getElementById('left_activityID');
    getAjaxFile(url);
}
function ChangeMainLnews(url) {
    contentObj = document.getElementById('box_news');
    getAjaxFile(url);
}
function OpenTellFriend() {
    document.getElementById('box_tell_friend').style.display = 'block';
}
function CloseTellFriend() {
    document.getElementById('box_tell_friend').style.display = 'none';
    document.getElementById('act_required').style.display = 'none';
    document.getElementById('act_message').style.display = 'none';
    
}
function OpenResult(url, hide, show, src) {
    document.getElementById(show).style.display = 'block';
    document.getElementById(hide).style.display = 'none';
    if (url!="") {
    contentObj = document.getElementById(show);
    getAjaxFile(url + "?src=" + src);
    }
}
function ShowCompForm() {
    document.getElementById('box_comp_form').style.display = 'block';
}
function CloseCompForm() {
    document.getElementById('box_comp_form').style.display = 'none';
}
function SelectMam() {
    oldType = document.getElementById('location_web').value
    if (oldType == 0) {
        document.getElementById('location_web').value = 1;
        document.getElementById('radio_adv1').className = 'radioS_adv';
    }
    else {
        document.getElementById('location_web').value = 0;
        document.getElementById('radio_adv1').className = 'radio_adv';
    }
}
function SelectWeb() {
    oldType2 = document.getElementById('location_write').value
    if (oldType2 == 0) {
        document.getElementById('location_write').value = 1;
        document.getElementById('radio_adv2').className = 'radioS_adv';
    }
    else {
        document.getElementById('location_write').value = 0;
        document.getElementById('radio_adv2').className = 'radio_adv';
    }
}
//function SelectLocation(radio,id){
//	document.getElementById('location').value=id;
//	document.getElementById('radio_adv1').className='radio_adv';
//	document.getElementById('radio_adv2').className='radio_adv';
//	document.getElementById(radio).className='radioS_adv';
//	}
function OpenNewsletter() {
    email = document.getElementById('email').value;
    if (email != 'البريد الإلكتروني') {
        document.getElementById('n_email').value = email;
    }
    document.getElementById('box_newsletter').style.display = 'block';
}
function CloseNewsletter() {
    document.getElementById('box_newsletter').style.display = 'none';
}
function OpenDescription(id) {
    count = document.getElementById('news_counter').value;
    nstatus = document.getElementById('large_desc' + id).style.display;
    if (nstatus == '') {
        nstatus = 'none';
    }
    for (var i = 1; i <= count; i++) {
        document.getElementById('small_desc' + i).style.display = 'block';
        document.getElementById('large_desc' + i).style.display = 'none';
        document.getElementById('btn_news' + i).className = 'btn_plus';
    }
    if (nstatus == 'none') {
        document.getElementById('small_desc' + id).style.display = 'none';
        document.getElementById('large_desc' + id).style.display = 'block';
        document.getElementById('btn_news' + id).className = 'btn_plusS';
    }
    if (nstatus == 'block') {
        document.getElementById('small_desc' + id).style.display = 'block';
        document.getElementById('large_desc' + id).style.display = 'none';
        document.getElementById('btn_news' + id).className = 'btn_plus';
    }
}
var RemainArray = "";
var RemainArray2 = "";
var gallery = "";
var slideCache = new Array();
var galCache = 0;
var piccounter = 1;
var globalpicNb;

function NextGallery() {
    piccounter = piccounter + 1;
    if (piccounter > globalpicNb) {
        piccounter = 1;
    }
    document.getElementById('picounter').innerHTML = piccounter;
    galleryID = document.getElementById('picArray').value;
    if (gallery == "") {
        gallery = galleryID;
    }
    var imageSeparator = gallery.indexOf(";");
    var FirstImg = gallery.substring(0, imageSeparator + 1);
    //if (FirstImg == document.getElementById('CurrentPic').src) {

    var RemainArray = gallery.substring(imageSeparator + 1, gallery.length)
    var NewGallery = RemainArray + FirstImg;
    imageSeparator = NewGallery.indexOf(";");
    var NextImg = NewGallery.substring(0, imageSeparator);
    gallery = NewGallery;
    //waitFor('CurrentPic');
    //if (galCache==1){

    document.getElementById('CurrentPic').src = NextImg;
    document.getElementById('EmilyPicture').src = NextImg;

    //document.getElementById('EmilyPicture').src = '<%=Url.Content("~/Utils/ResizeImage?imagename=" + Url.Content("~/" + NextImg) + "&width=839&height=549&isresize=1") %>';


    //FadeInImage("EmilyPicture",NextImg,"EmilyPictureBackground");
    //ChangeBgHeight();
    //}
}
function waitFor(img) {
    if (!img.complete) {
        window.setTimeout('waitFor(' + img + ')', 5);
    }
    else {
        galCache = 1;
    }
}
function ChangeBgHeight() {
    var newHeight = document.getElementById('CurrentPic').height;
    document.getElementById('EmilyPictureBackground').style.height = newHeight + "px";
}
function PreGallery() {
    galleryID = document.getElementById('picArray').value;
    piccounter = piccounter - 1;
    if (piccounter == 0) {
        piccounter = globalpicNb;
    }
    document.getElementById('picounter').innerHTML = piccounter;
    if (gallery == "") {
        gallery = galleryID;
    }
    gallery = gallery.substring(0, gallery.length - 1);
    var lastIndex = gallery.lastIndexOf(";");
    var LastImg = gallery.substring(lastIndex + 1, gallery.length);
    var RemainArray = gallery.substring(0, lastIndex);
    var NewGallery = LastImg + ";" + RemainArray;
    imageSeparator = NewGallery.indexOf(";");
    var PreImg = NewGallery.substring(0, imageSeparator);
    gallery = NewGallery + ";";

    document.getElementById('CurrentPic').src = PreImg;

    document.getElementById('EmilyPicture').src = PreImg;

    //FadeInImage("EmilyPicture",PreImg,"EmilyPictureBackground");
    //ChangeBgHeight();
}

function CloseGallery() {
    document.getElementById('divDrag').style.display = 'none';
    document.getElementById('opacitiDiv').style.display = 'none';
    if (document.getElementById('picArray')) {
        document.getElementById('picArray').value = '';
    }
    galleryID = "";
    RemainArray = "";
    RemainArray2 = "";
    gallery = "";
    slideCache = new Array();
    galCache = 0;
}
function OpenPolicy() {
    rSize = parseInt(315 / 2)
    resizing(rSize, 'divDrag3');
    MakeGris();
    document.getElementById('divDrag3').style.display = 'block';
}
function ClosePolicy() {
    document.getElementById('divDrag3').style.display = 'none';
    document.getElementById('opacitiDiv').style.display = 'none';
}
function MakeGris() {
    document.getElementById('opacitiDiv').style.display = 'block';
    if (document.getElementById('Centerwrapper') != null) {
        document.getElementById('opacitiDiv').style.height = document.getElementById('Centerwrapper').offsetHeight + "px";
    }
}
function OpenGallery(id, pic, title, picNb) {
    if (mouseisinsidelike != 1) {
        document.getElementById('EmilyPicture').src = pic;
        document.getElementById('pop_title').innerHTML = title + ' (<span id="picounter">1</span>/' + picNb + ')';
        document.getElementById('picArray').value = document.getElementById('picArray' + id).value;
        rSize = parseInt(315 / 2)
        resizing(rSize, 'divDrag');
        MakeGris();
        document.getElementById('divDrag').style.display = 'block';
        globalpicNb = picNb;
    } 
}
function MakeGris() {
    document.getElementById('opacitiDiv').style.display = 'block';
    if (document.getElementById('Centerwrapper') != null) {
        document.getElementById('opacitiDiv').style.height = document.getElementById('Centerwrapper').offsetHeight + "px";
    }
}
function resizing(minus, divid, iframename) {
    var y = (getScreenSizY()) / 2;
    var x = (getScreenSizX()) / 2;

    y = y + getScrollXY();
    try {
        x = x - minus;
        document.getElementById(divid).style.top = y - 290 + 'px';
        document.getElementById(divid).style.left = x - 340 + 'px';

        if (divid == 'divDrag3') {
            document.getElementById(divid).style.top = y - 220 + 'px';
            document.getElementById(divid).style.left = x - 340 + 'px';
        }
    }
    catch (e) {
    }
}
window.onresize = function() {
    resizing();
}
function getScreenSizX() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    // window.alert( 'Width = ' + myWidth );
    // window.alert( 'Height = ' + myHeight );

    return myWidth;
}
function getScreenSizY() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    // window.alert( 'Width = ' + myWidth );
    // window.alert( 'Height = ' + myHeight );

    return myHeight;
}
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return scrOfY;
}


function SelectStar(div, id) {
    for (var x = 1; x <= 5; x++) {
        document.getElementById(div + 'star' + x).className = '';
    }
    for (var x = 1; x <= id; x++) {
        document.getElementById(div + 'star' + x).className = 'selected';
    }
    document.getElementById('evalarticle' + div).value = id;
}
function OpenAddress(id) {
    if (document.getElementById('idarray')) {
        idarraystr = document.getElementById('idarray').value;
        var temp = new Array();
        temp = idarraystr.split(';');
        for (i = 0; i < temp.length-1;  i++) {
            document.getElementById('box_address' + temp[i]).style.display = 'none';  
        }
    }
if (document.getElementById('box_address' + id)){
    document.getElementById('box_address' + id).style.display = 'block';
    }
}
function CloseAddress(id) {
    document.getElementById('box_address' + id).style.display = 'none';
}
function OpenEval(id) {
    document.getElementById('div_opacity' + id).style.display = 'block';
    document.getElementById('pop_evale' + id).style.display = 'block';
}
function ClosepopEval(id) {
    document.getElementById('div_opacity' + id).style.display = 'none';
    document.getElementById('pop_evale' + id).style.display = 'none';
    document.getElementById('twitter' + id).style.display = 'none';
}
global_articleID = "";
function CloseEval(id, userid, url) {
    global_articleID = id;
    evalue = document.getElementById('evalarticle' + id).value;
    visited = document.getElementById('isvisited' + id).value;
//    document.getElementById('div_opacity' + id).style.display = 'none';
//    document.getElementById('pop_evale' + id).style.display = 'none';
    if (visited == 1) {
        visited = true;
    }
    else {
        visited = false;
    }
    if (userid != 0) {
        document.getElementById('load_search'+id).style.display = 'block';
        contentObj = document.getElementById('evalid' + id);
        getAjaxFile(url + userid + "/" + id + "/" + evalue + "/" + visited);
    }
    else {
        showOpacity();
    }
}
function SelectRadio(box, id) {
    oldClassMain = document.getElementById(box + 'radio' + id).className;
    if (oldClassMain.indexOf('S') == -1) {
        for (var x = 1; x <= 2; x++) {
            oldClass = document.getElementById(box + 'radio' + x).className;
            if (oldClass.indexOf('S') != -1) {
                document.getElementById(box + 'radio' + x).className = oldClass.substring(0, oldClass.length - 1);
            }
        }
        document.getElementById(box + 'radio' + id).className = oldClassMain + 'S';
        document.getElementById('isvisited' + box).value = id;
    }
}

var stopTicker = false;
var sCounter = 1;
var preImage = new Array();

counter = 0;

//picArray1 = "images/3.jpg;images/5.jpg";
//picArray2="images/1.jpg;images/2.jpg";
//picArray3="images/4.jpg;images/3.jpg";
//picArray4="images/5.jpg;images/2.jpg";
//picArray5="images/3.jpg;images/1.jpg";

function startRun() {
    RunSlideShow("EmilyPicture", "EmilyPictureBackground", picArray1, 5);
}
function startRun2(id, actid, url, bgurl) {
    clearTimeout(timer_slide);
    document.getElementById('tab_activity').style.backgroundImage = 'url(' + bgurl + ')';
    //document.getElementById('tab_activity').style.backgroundImage = 'url(../../images/act_tab_' + id + '.png)';
    for (var i = 1; i <= 5; i++) {
        document.getElementById('act_tab_' + i).className = 'act_tab';
    }
    document.getElementById('act_tab_' + id).className = 'act_tab selected';
    contentObj = document.getElementById('content_activity');
    getAjaxFile(url);
    picArray = "picArray" + id;
    RunSlideShow("EmilyPicture", "EmilyPictureBackground", eval(picArray), 5);
}
var contentObj;   // refer  the  content of  <div>
function getAjaxFile(urlPage) {
    xmlHttp = CreateHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    xmlHttp.onreadystatechange = stateChanged
    xmlHttp.open("GET", urlPage, true)
    xmlHttp.send(null)
}
function stateChanged(CatId) {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        contentObj.innerHTML = xmlHttp.responseText;
        //init_dw_Scroll();
        if (document.getElementById('ajaxLoader')) {
            document.getElementById('ajaxLoader').className = 'ajaxLoader';
        }
        if (document.getElementById('load_search')) {
            document.getElementById('load_search').style.display = 'none';
        }
        if (document.getElementById('load_search' + global_articleID)) {
            document.getElementById('load_search' + global_articleID).style.display = 'none';
        }
        if (document.getElementById('twitter' + global_articleID)) {
            document.getElementById('twitter' + global_articleID).style.display = 'block';
        }
        
    }
}
function CreateHttpObject() {
    var objXMLHttp = null
    try {
        objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (err) {
            objXMLHttp = null;
        }
    }
    if (!objXMLHttp && typeof XMLHttpRequest != "undefined")
        objXMLHttp = new XMLHttpRequest();
    return objXMLHttp
}

function changeActivity(id, actid, url, bgurl) {
    window.onload = startRun2(id, actid, url, bgurl);
}
function Opendiv() {
    document.getElementById('facebook_wrapper').style.display = 'block';
    var exampleFx = new Fx.Morph('pop_facebook', {
        duration: 500,
        onComplete: function() {
            isSlid = false;
            isopen = true;
        }
    });
    isSlid = true;
    exampleFx.start({
        'height': [0, 175]
    });
}
function Closediv() {

    popStatus = document.getElementById('pop_help').style.bottom;
    if (popStatus == "") {
        popStatus = "-80px";
    }

    bottomLength = popStatus.length;
    BottomValue = parseInt(popStatus.substr(0, popStatus.length - 2));
    var exampleFx = new Fx.Morph('pop_help', {
        duration: 500,
        onComplete: function() {
            isSlid = false;
            isopen = false;
        }
    });
    isSlid = true;
    if (isNaN(parseInt(BottomValue))) {
        BottomValue = 0;
    }
    exampleFx.start({
        'bottom': [BottomValue, -80]
    });
}
function OpenFacebook() {
    document.getElementById('facebook_wrapper').style.display = 'block';
    document.getElementById('f_connect').className = 'f_connectS';
}
function CloseFacebook(id) {
    document.getElementById(id).style.display = 'none';
    document.getElementById('f_connect').className = 'f_connect';
    document.getElementById('opacitiDiv').style.display = 'none';
}
var tebNb = 3;
var currentTab = 1;
var oldTab = 1;
function startShow() {
    hotDeal_interval = setInterval("hotDeal_Rotator()", 5000);
}
function hotDeal_Rotator() {
    currentTab = currentTab + 1;
    if (parseInt(currentTab) > parseInt(tebNb)) currentTab = 1;
    newHotSelect(currentTab, 'rotator')
}
function newHotSelect(hot_nb, thisEvent) {
    if (thisEvent == 'rotator') {
        showHotDeal(hot_nb)
    }
    else if (thisEvent == 'next') {
        clearInterval(hotDeal_interval);
        showHotDeal(hot_nb)
        startShow()
    }
    else if (thisEvent == 'previous') {
        clearInterval(hotDeal_interval);
        showHotDeal(hot_nb)
        startShow()
    }
    else if (thisEvent == 'goto') {

        clearInterval(hotDeal_interval);
        showHotDeal(hot_nb)
        startShow()
    }
    oldTab = hot_nb;
}
function hotDeal_goTo(thisNb) {
    currentTab = thisNb;
    newHotSelect(currentTab, 'goto')
}
function showHotDeal(currentTab) {
    divToShow = 'offer' + currentTab;
    divToSHide = 'offer' + oldTab;
    if (currentTab != oldTab) {
        if (oldTab == 0)// first load
        {
        } else {
            hideDiv(divToSHide, divToShow);
            document.getElementById('nb' + currentTab).className = "selected"
            document.getElementById('nb' + oldTab).className = ""
        }
    }
}
function hideDiv(divid, dividtoShow) {

    document.getElementById(dividtoShow).style.display = 'block';
    document.getElementById(divid).style.display = 'none';
}

var FadeDurationMS = 1000;
function SetOpacity(object, opacityPct) {
    // IE.
    object.style.filter = 'alpha(opacity=' + opacityPct + ')';
    // Old mozilla and firefox
    object.style.MozOpacity = opacityPct / 100;
    // Everything else.
    object.style.opacity = opacityPct / 100;
}
function ChangeOpacity(id, msDuration, msStart, fromO, toO) {
    var element = document.getElementById(id);
    var msNow = (new Date()).getTime();
    var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
    if (opacity >= 100) {
        SetOpacity(element, 100);
        element.timer = undefined;
    }
    else if (opacity <= 0) {
        SetOpacity(element, 0);
        element.timer = undefined;
    }
    else {
        SetOpacity(element, opacity);
        element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")", 10);
    }
}
function FadeInImage(foregroundID, newImage, backgroundID) {
    var foreground = document.getElementById(foregroundID);
    if (foreground.timer) window.clearTimeout(foreground.timer);

    if (backgroundID) {
        var background = document.getElementById(backgroundID);
        if (background) {
            if (background.src) {
                foreground.src = background.src;
                SetOpacity(foreground, 100);
            }
            background.src = newImage;
            background.style.backgroundImage = 'url(' + newImage + ')';
            background.style.backgroundRepeat = 'no-repeat';
            var startMS = (new Date()).getTime();
            foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "'," + FadeDurationMS + "," + startMS + ",100,0)", 10);
        }
    } else {
        foreground.src = newImage;
    }
}
function ChangeTab(id) {
    document.getElementById('row_top_slide').style.backgroundImage = 'url(images/bg_top_' + id + '.jpg)';
}
function NextActivity() {
    clearTimeout(timer_slide);
    RunSlideShow("EmilyPicture", "EmilyPictureBackground", nextImg, 5);
}
function PreActivity() {
    clearTimeout(timer_slide);
    RunSlideShow("EmilyPicture", "EmilyPictureBackground", preImage, 5);
}
function RunSlideShow(pictureID, backgroundID, imageFiles, displaySecs) {
    var imageSeparator = imageFiles.indexOf(";");
    var nextImage = imageFiles.substring(0, imageSeparator);
    var test = imageFiles.lastIndexOf(";");
    var test2 = imageFiles.substring(test + 1, imageFiles.length);
    var test3 = imageFiles.substring(0, test);
    preImage = test2 + ";" + test3;
    //alert(preImage);
    if (slideCache[nextImage] && slideCache[nextImage].loaded) {
        FadeInImage(pictureID, nextImage, backgroundID);
        //ChangeTab(sCounter);
        var futureImages = imageFiles.substring(imageSeparator + 1, imageFiles.length)
			+ ';' + nextImage;
        sCounter = sCounter + 1;
        //alert(futureImages);
        timer_slide = setTimeout("RunSlideShow('" + pictureID + "','" + backgroundID + "','" + futureImages + "'," + displaySecs + ")",
			displaySecs * 1000);
        // Identify the next image to cache.
        imageSeparator = futureImages.indexOf(";");
        nextImage = futureImages.substring(0, imageSeparator);
        //alert(nextImage);
        nextImg = futureImages;
    } else {
        timer_slide = setTimeout("RunSlideShow('" + pictureID + "','" + backgroundID + "','" + imageFiles + "'," + displaySecs + ")",
			250);
    }
    // Cache the next image to improve performance.
    if (slideCache[nextImage] == null) {
        slideCache[nextImage] = new Image;
        slideCache[nextImage].loaded = false;
        slideCache[nextImage].onload = function() { this.loaded = true };
        slideCache[nextImage].src = nextImage;
    }

}
function sendContact() {
    isValidText = true;
    isValuArea = true;
    isValidText = validateForm('c_name', 'c_country', 'c_email@@email');
    document.getElementById('btn_cancel').className = 'btn_cancel2';
    document.getElementById('btn_join').className = 'btn_join2';
    if (isValidText) {
        c_name = document.getElementById("c_name").value;
        c_country = document.getElementById("c_country").value;
        c_email = document.getElementById("c_email").value;
        c_phone = document.getElementById("c_phone").value;
        c_notes = document.getElementById("notes").value;
        fromFlag = 1;

        URL = document.getElementById("UrlContact").value;
        var poststr = "name=" + encodeURI(c_name) + "&country=" + encodeURI(c_country) + "&email=" + encodeURI(c_email) + "&phone=" + encodeURI(c_phone) + "&notes=" + encodeURI(c_notes);
        postAjaxFile(URL, poststr);
        document.getElementById('msg_adv').style.display = 'block';
        document.getElementById('msg_required').style.display = 'none';
        document.getElementById('formCont').reset();
        //document.getElementById('done_message').style.display = 'block';

    } else {
        document.getElementById('msg_required').style.display = 'block';
        document.getElementById('msg_adv').style.display = 'none';
    }
}
function sendAdvertise() {
    isValidText = true;
    isValuArea = true;
    isValidText = validateForm('ad_name', 'ad_country', 'ad_email@@email');
    document.getElementById('btn_cancel').className = 'btn_cancel2';
    document.getElementById('btn_join').className = 'btn_join2';
    if (isValidText) {
        c_name = document.getElementById("ad_name").value;
        c_country = document.getElementById("ad_country").value;
        c_email = document.getElementById("ad_email").value;
        c_locationWeb = document.getElementById("location_web").value;
        c_locationWrite = document.getElementById("location_write").value;
        c_phone = document.getElementById("ad_phone").value;
        c_company = document.getElementById("ad_company").value;
        c_notes = document.getElementById("notes").value;
        fromFlag = 1;

        URL = document.getElementById("Urladvertise").value;
        var poststr = "name=" + encodeURI(c_name) + "&country=" + encodeURI(c_country) + "&email=" + encodeURI(c_email) + "&phone=" + encodeURI(c_phone) + "&location_web=" + encodeURI(c_locationWeb) + "&location_write=" + encodeURI(c_locationWrite) + "&company=" + encodeURI(c_company) + "&notes=" + encodeURI(c_notes);
        postAjaxFile(URL, poststr);
        document.getElementById('msg_adv').style.display = 'block';
        document.getElementById('msg_required').style.display = 'none';
        document.getElementById('formAdv').reset();
    } else {
        document.getElementById('msg_required').style.display = 'block';
        document.getElementById('msg_adv').style.display = 'none';
    }
}
function sendNewsLetter() {
    isValidText = true;
    isValuArea = true;

    isValidText = validateForm('n_name', 'n_country', 'n_email@@email');

    if (isValidText) {
        //document.getElementById('error_message_contact_div').className = 'loader_contact';

        c_name = document.getElementById("n_name").value;
        c_country = document.getElementById("n_country").value;
        c_email = document.getElementById("n_email").value;
        c_phone = document.getElementById("n_phone").value;

        fromFlag = 1;

        URL = document.getElementById("Urlnewssend").value;
        var poststr = "name=" + encodeURI(c_name) + "&country=" + encodeURI(c_country) + "&email=" + encodeURI(c_email) + "&phone=" + encodeURI(c_phone);
        postAjaxFile(URL, poststr);
        document.getElementById('done_message').style.display = 'block';
        setTimeout("CloseNewsletter()", 2000);

    } else {//document.getElementById('error_message_contact_div').className='error_message_conract';

    }
}
function sendFriend() {
    isValidText = true;
    isValuArea = true;

    isValidText = validateForm('f_comment', 'f_name', 'f_friend_name', 'f_email@@email', 'f_friend_email@@email');

    if (isValidText) {
        //document.getElementById('error_message_contact_div').className = 'loader_contact';

        c_articleTitle = document.getElementById("articleTitle").value;
        c_articleId = document.getElementById("articleId").value;
        c_name = document.getElementById("f_name").value;
        c_comment = document.getElementById("f_comment").value;
        c_PageUrl = document.getElementById("PageUrl").value;
        c_friend_name = document.getElementById("f_friend_name").value;
        c_friend_name2 = document.getElementById("f_friend_name2").value;
        c_friend_name3 = document.getElementById("f_friend_name3").value;
        c_friend_name4 = document.getElementById("f_friend_name4").value;
        c_friend_name5 = document.getElementById("f_friend_name5").value;
        c_email = document.getElementById("f_email").value;
        c_friend_email = document.getElementById("f_friend_email").value;
        c_friend_email2 = document.getElementById("f_friend_email2").value;
        c_friend_email3 = document.getElementById("f_friend_email3").value;
        c_friend_email4 = document.getElementById("f_friend_email4").value;
        c_friend_email5 = document.getElementById("f_friend_email5").value;

        fromFlag = 1;

        URL = document.getElementById("UrlsendFriend").value;
        var poststr = "name=" + encodeURI(c_name) + "&PageUrl=" + encodeURI(c_PageUrl) + "&articleId=" + encodeURI(c_articleId) + "&comment=" + encodeURI(c_comment) + "&article_title=" + encodeURI(c_articleTitle) + "&friend_name=" + encodeURI(c_friend_name) + "&email=" + encodeURI(c_email) + "&friend_email=" + encodeURI(c_friend_email) + "&friend_name2=" + encodeURI(c_friend_name2) + "&friend_name3=" + encodeURI(c_friend_name3) + "&friend_name4=" + encodeURI(c_friend_name4) + "&friend_name5=" + encodeURI(c_friend_name5) + "&friend_email2=" + encodeURI(c_friend_email2) + "&friend_email3=" + encodeURI(c_friend_email3) + "&friend_email4=" + encodeURI(c_friend_email4) + "&friend_email5=" + encodeURI(c_friend_email5);
        postAjaxFile(URL, poststr);
        document.getElementById('act_message').style.display = 'block';
        document.getElementById('act_required').style.display = 'none';
        //setTimeout("CloseTellFriend()", 3000);
        document.getElementById('tell_friend').reset();

    } else {//document.getElementById('error_message_contact_div').className='error_message_conract';
        document.getElementById('act_message').style.display = 'none';
        document.getElementById('act_required').style.display = 'block';
    }
}
function postAjaxFile(urlPage, parameters) {
    xmlHttpPost = CreateHttpObject()
    if (xmlHttpPost == null) {
        alert("Browser does not support HTTP Request")
        return
    }

    xmlHttpPost.onreadystatechange = stateChangedPost;

    xmlHttpPost.open("POST", urlPage, true);
    xmlHttpPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    xmlHttpPost.setRequestHeader("Content-length", parameters.length);
    xmlHttpPost.setRequestHeader("Connection", "close");
    xmlHttpPost.send(parameters)

}
function stateChangedPost() {
    if (xmlHttpPost.readyState == 4 || xmlHttpPost.readyState == "complete") {
        if (fromFlag == 1) {
            //alert("email has been sent")
            document.getElementById('alert_required').style.display = 'none';
            document.getElementById('load').style.display = 'none';
            document.getElementById('alert_send').style.display = 'block';

        }
    }
}
function validateForm() {
    isValid = true;
    var paramLength = arguments.length;
    for (i = 0; i < paramLength; i++) {
        parArray = arguments[i].split("@@")
        thislength = parArray.length;
        fieldName = parArray[0]

        if (thislength > 1) {
            fieldType = parArray[1];
            if (fieldType == 'email') {
                isValideEmail = validateEmail(document.getElementById(fieldName).value)
                if (!isValideEmail) {
                    oldClass = document.getElementById(fieldName).parentNode.className;
                    document.getElementById(fieldName).parentNode.className = oldClass + " required";
                    isValid = false;
                } else {
                    oldClass = document.getElementById(fieldName).parentNode.className;

                    document.getElementById(fieldName).parentNode.className = oldClass.replace(/ required/g, "");
                }

            } else if (fieldType == "confirm") {
                isValidPassword = validPassword(document.getElementById(fieldName).value, document.getElementById(fieldName + "_confirm").value)
                if (!isValidPassword) {
                    oldClass = document.getElementById(fieldName).parentNode.className
                    document.getElementById(fieldName).parentNode.className = oldClass + " required";
                    document.getElementById(fieldName + "_confirm").parentNode.className = oldClass + " required";
                    isValid = false;

                } else {

                    document.getElementById(fieldName).parentNode.className = "input_content";
                    document.getElementById(fieldName + "_confirm").parentNode.className = "input_content";
                    //isValid = true;

                }
            }
        } else {

            if (document.getElementById(fieldName).value == '') {
                oldClass = document.getElementById(fieldName).parentNode.className;
                document.getElementById(fieldName).parentNode.className = oldClass + " required";
                isValid = false;
            } else {
                oldClass = document.getElementById(fieldName).parentNode.className;
                document.getElementById(fieldName).parentNode.className = oldClass.replace(/ required/g, "");
            }
        }
    }
    return isValid;
}
function validateEmail(email) {
    var isValid = true
    var email = email
    AtPos = email.indexOf("@")
    StopPos = email.lastIndexOf(".")
    if (AtPos == -1 || StopPos == -1) {

        isValid = false;
        //alert(isValid)
    }

    return isValid;
}
