function getCatId(){
    //alert("getCatId...");
    var catId = ""; catId = getQuerystring("catid", null);
    var ansId = ""; ansId = getQuerystring("ansid", null);
    var pageNum = ""; pageNum = getQuerystring("curpagenum", null);
    var filterOption = ""; filterOption = getQuerystring("filteroption", null);
    var pollId = ""; pollId = getQuerystring("pollid", null);
    //alert(pollId);
    
  if(catId.length == 0) 
	{
		catId = "8";	

	}

	try {
	    //alert(catId);
           	getFlashMovie("Carousel").sendCatId(catId, pathPrefix, ansId, pageNum, filterOption, pollId);
		//only the construct below works on the server...dont know why!
           	//document.getElementById("Carousel").sendCatId(catId, pathPrefix);//pathPrefix is there in the masterpage and is the server path
       	}
       	catch (e) {
       	    if (document.all) {
       	        document.getElementById("Carousel").sendCatId(catId, pathPrefix, ansId, pageNum, filterOption, pollId);
       	    }
       	    else {
       	        alert(e);
       	    }
       	}

       	//alert("getCatId..." + catId);

}

//function gets the obj tags for the video
function getVideoSrc(filePath, caption) {
    //alert(filePath + "::" + caption);
    //for metacafe
    
	writeMediaDiv(filePath, caption, "1")
	//now call writeDiv with option "1"

}

//redirects user to given URL (url) where pathPrefix is defined in the page as the serverURL.
function redirectPage(url) {
    location.href = pathPrefix + url;
}

//open facebook share
function jmfbs_click() {
    //alert("fbs_click");
    u = location.href; ;
    t = "JMPage";
    openWindow('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), null, null);
    //return false;
}

function jmtw_click() {
    u = location.href; ;
    t = "JMPage";
    openWindow("http://twitter.com/home?status=" + encodeURIComponent(u) + "&t=" + encodeURIComponent(t), 775, 350);
    //return false;
}

function showShare(pollid) {

   
    var URL = pathPrefix + "/Poll/PollResultDetails.aspx?pollid=" + pollid;
    var ShowShareinnerHTML = "<table style='padding-bottom:10'>";
    ShowShareinnerHTML += "<tr valign='top'><td>"
    ShowShareinnerHTML += "<a class=\"st-taf\" href=\"http://tellafriend.socialtwist.com:80\" onclick=\"return false;\" style=\"border:0;padding:0;margin:0;\">";
    ShowShareinnerHTML += "<div id='imgTellandShare' onmouseout=\"STTAFFUNC.hideHoverMap(this)\" onmouseover=\"STTAFFUNC.showHoverMap(this, '2009111930017', '" + URL + "', document.title)\" onclick=\"STTAFFUNC.showHoverMap(this, '2009111930017', '" + URL + "', document.title)\"></div></a>";
    ShowShareinnerHTML += "</td></tr></table>";
    document.getElementById("dvShareQuestion").innerHTML = ShowShareinnerHTML;
    document.getElementById("dvShareQuestion").style.display = 'block';
    document.getElementById("dvShareQuestion").style.left =  695 + "px";
    document.getElementById("dvShareQuestion").style.top = (scrolledV + 5) + "px";
    STTAFFUNC.showHoverMap(document.getElementById('imgTellandShare'), '2009111930017', URL, document.title);
    

}



function getQuerystring(key, default_) {

  
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href.toLowerCase());
  
  if(qs == null)
    return default_;
  else
    return qs[1];
}

//returns the movie object with id 'movieName'

function getFlashMovie(movieName) {
         //var isIE = navigator.appName.indexOf("Microsoft") != -1;
    //return (isIE) ? window[movieName] : document[movieName];
    
    if (navigator.appName.indexOf("Microsoft") != -1) {
        //alert(document.getElementById(movieName));
        return document.getElementById(movieName);
    }
    else {
        if (document[movieName].length != undefined) {
            //alert(document[movieName][1]);
            return document[movieName][1];
        }
        //alert(document[movieName]);
        return document[movieName];
    }

}

//writes the Media Div...
function writeMediaDiv(url, caption, changeObj, flashVars) {
	//alert(url + "::" + changeObj);
	//to call jQuery
try{
	//location.href = "#TB_inline?height=155&width=300&inlineId=hiddenModalContent";
	switch(changeObj){
		//
	    case "1":
	    putDiv("TB_ajaxContent", caption, url, flashVars);
	    break;


	default:
	    tb_show(caption, url);
	    break;
		//alert(caption + ":"+url);

	}
	//forsome reason this does not work in IE (probably JS)
	//(changeObj=="1")?putDiv("TB_ajaxContent", caption, url):alert(caption);
	
}
catch(e){
	alert(e);
}
}

//function to put a div in a div with passed Id
function putDiv(Id, caption, url, flashVars){
	//url += "&autoplay=1";
	//alert("putDiv" + url);
	//location.href = "#TB_inline?height=155&width=300&inlineId=hiddenModalContent"

    $(document).ready(function() {
        tb_show(caption, '');
        var divTB = document.getElementById(Id);
        //if the url has ".flv" play it on the flv player...
        //	    if (url.indexOf(".flv") > -1) {
        //	        divTB.innerHTML = "<object width=100% height=100% classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 id=ep><param name=allowfullscreen value=true /><param name=allowscriptaccess value=always /><param name=wmode value=transparent /><param name=movie value='" + pathPrefix + "/Themes/Flash/jmFLVPLayer_small.swf' /><param name=bgcolor value=#000000 /><embed src='" + pathPrefix + "/Themes/Flash/jmFLVPLayer_small.swf' type=application/x-shockwave-flash bgcolor=#000000 allowfullscreen=true allowscriptaccess=always width=100% wmode=transparent height=100%></embed></object>";
        //	    }
        //else {
        //alert(url);
        divTB.innerHTML = GetEmbedForPreview(url, pathPrefix, "100%", "100%");
        //}
        //document.getElementById('ep').playVideo();
    });

}

//function to report abuse..............
function reportAbuse(pollId) {
    //check login
    if (UserID != null && UserID > 0) {
        //do the flag
        sPage = "P";
        
        var url = pathPrefix + "/reportFlag.aspx?serverUrl=" + pathPrefix + "&pollId=" + pollId + "&srcPage=" + sPage + "TB_iframe=true&height=202&width=402" ; //srcPage='P'---Poll 'BC'---Blog Comments
        writeMediaDiv(url, 'Report inappropriate content to JabberMonkey', "2");
    }
    else {
       
       LoginPopUp();
     
    }

}

function reportBlogCommentAbuse(BlogUserCommentDetailsId) {
    //check login
    if (UserID != null && UserID > 0) {
        //do the flag
        sPage ="BC";
        var url = pathPrefix + "/reportFlag.aspx?serverUrl=" + pathPrefix + "&BlogUserCommentDetailsId=" + BlogUserCommentDetailsId + "&srcPage=" + sPage + "TB_iframe=true&height=202&width=402" ; //srcPage='P'---Poll 'BC'---Blog Comments  
        writeMediaDiv(url, 'Report inappropriate content to JabberMonkey', "2");
    }
    else {
       
       LoginPopUp();
     
    }

}

function reportAlbumCommentAbuse(AlbumMediaCommentId) {
    //check login
    if (UserID != null && UserID > 0) {
        //do the flag
        sPage = "AMC";
        var url = pathPrefix + "/reportFlag.aspx?serverUrl=" + pathPrefix + "&AlbumMediaCommentId=" + AlbumMediaCommentId + "&srcPage=" + sPage + "TB_iframe=true&height=202&width=402"; //srcPage='P'---Poll 'BC'---Blog Comments
         writeMediaDiv(url, 'Report inappropriate content to JabberMonkey', "2");
    }
    else {

        LoginPopUp();

    }

}

//function for ajax calls...returns the response...

//function to rate poll..............
function ratePoll(pollId, rating) {
    //check login
    //alert("ratePoll(" + pollId + "," + rating + ")");
    if (UserID != null && UserID > 0) {
        //do the flag
        var url = pathPrefix + "/Poll/PollRating.aspx?UserId=" + UserID + "&PollID=" + pollId + "&Rt=" + rating;
        //var avRating;
        //make an AJAX request here...using jQuery

        $.get(pathPrefix + "/Poll/PollRating.aspx", { UserId: UserID, PollID: pollId, Rt: rating }, function(data) {
            //avRating = data;
            setRating(data);
        });
        
        ////////////////////////////////////////////////////////////////
    }
    else {

        LoginPopUp();

    }

}

function setRating(avRating) {
    //set the star to the average rating returned///////////////////
    try {
        //alert(catId);
        getFlashMovie("Carousel").sendRating(avRating);
        //only the construct below works on the server...dont know why!
        //document.getElementById("Carousel").sendCatId(catId, pathPrefix);//pathPrefix is there in the masterpage and is the server path
    }
    catch (e) {
        if (document.all) {
            document.getElementById("Carousel").sendRating(avRating);
        }
        //else {
            alert(e);
        //}
    }
}

//function to load Chat
function loadChat(qPostedById, userImageSrc, qPostedBy) {
    //check login
    if (UserID != null && UserID > 0) {
        try {
            //jsOpenWindowChat(UserID, qPostedById, userImageSrc, qPostedBy);
            var popup = UserID + "|" + qPostedById;
            var sURL = ServerUrl + "/Chat/Chat.aspx?FromUserId=" + UserID + "&FullName=Me" + "&UserName=" + qPostedBy + "&UserIcon=" + userImageSrc + "&ToUserId=" + qPostedById + "&ToUsername=" + qPostedBy + "";
            //var sUrl = ServerUrl + '/Chat/Chat.aspx?ChatId=' + hdChatID + '&FromUserId=' + UserID + '&ToUserId=' + qPostedById + '&Username=' + qPostedBy + '&IsVedioRequest=0' + '&UserIcon=' + userImageSrc;
            if(UserID != qPostedById) CreateDiv(popup, sURL);
        }
        catch (e) {
            alert("An error occured while trying to open the chat window.\n" + e);
        }
        //alert("Open Chat here...");
    }
    else {

        LoginPopUp();

    }
}


//function to show an alert from Flash...
function fAlert(msg){
	alert(msg);
}

//function to open a new window

function openWindow(url, width, height) { 
    //if no http:// is there, add it!
    if (url.indexOf("http://") == -1) {
        url = "http://" + alltrim(url);
    }
    var nWidth;
    var nHeight;
    if(width==null || height==null){
        nWidth = screen.width / 2;
        nHeight = screen.height / 2;
    }
    else{
        nWidth = width;
        nHeight = height;
    }
//    var nTop = (screen.availWidth - nWidth) / 2;
//    var nLeft = (screen.availHeight + nHeight) / 2;
//    newWindow = window.open(url, 'WinName', 'width=' + nWidth + ',height=' + nHeight + ',left=' + nLeft + ',top=' + nTop);
    var nTop;
    var nHeight;
    // Fudge factors for window decoration space.
    // In my tests these work well on all platforms & browsers.
    nLeft = (screen.width - nWidth) / 2;
    nTop = (screen.height - nHeight) / 2;
    // IE5 and other old browsers might allow a window that is
    // partially offscreen or wider than the screen. Fix that.
    // (Newer browsers fix this for us, but let's be thorough.)
    if (nLeft < 0) {
        nWidth = screen.width;
        nLeft = 0;
    }
    if (nTop < 0) {
        nHeight = screen.height;
        nTop = 0;
    }
    var win = window.open(url,
    'nPopup',
    'width=' + nWidth + ', height=' + nHeight + ', ' +
    'left=' + nLeft + ', top=' + nTop + ', ' +
    'location=no, menubar=no, scrollbars=1,resizable=1,status=no, toolbar=no');
    // Just in case width and height are ignored
    //win.resizeTo(nWidth, nHeight);
    // Just in case left and top are ignored
    //win.moveTo(nLeft, nTop);
    win.focus();
    //var win = window.open(url);
    
}

//to change the size of the div that holds the poll percentages (barChart.swf)
function resizeFDiv(divId, divFId, newHeight) {

    var htmlObj = document.getElementById(divId);
    var fObj = document.getElementById(divFId);
    //alert("id=" + divId + " :" + htmlObj + ", fId=" + divFId + " :" + fObj)
    if (document.getElementById(divId)) {

        document.getElementById(divId).style.height = newHeight + "px";
        document.getElementById(divFId).style.height = newHeight + "px";
        
    }
}

//trim functions
function ltrim(str) {
    return str.replace(/^\s+/, '');
}
function rtrim(str) {
    return str.replace(/\s+$/, '');
}
function alltrim(str) {
    return str.replace(/^\s+|\s+$/g, '');
}


