
var CurrenUser_LoggedIn = false;
var CurrentUser_UserID = 0;


function E(id) { return document.getElementById(id); }
function ES(id) { return E(id).style; }

isIE = document.all ? true : false;
IEVersion = 0; // we assume a sane browser
if (navigator.appVersion.indexOf("MSIE") != -1) IEVersion = parseFloat(navigator.appVersion.split("MSIE")[1]);

HighestZIndex = 999;
function NewHighestZIndex() { return ++HighestZIndex; }

function Coordinates(x, y) { this.X = x; this.Y = y; }
function Dimensions(w, h) { this.Width = w; this.Height = h; }

function EventVariable(event) {
	if (isIE)
		this.PageCoordinates = new Coordinates(window.event.clientX + document.body.scrollLeft, window.event.clientY + document.body.scrollTop);
	else
		this.PageCoordinates = new Coordinates(event.pageX, event.pageY);
	this.CallerObject = isIE ? window.event.srcElement : event.target;
	this.KeyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	this.MouseButton = isIE ? event.button : event.which;
	this.ControlKey = (event.altKey ? 1 : 0) + (event.ctrlKey ? 2 : 0) + (event.shiftKey ? 4 : 0);
	this.Type = event.type;
}

function PageProperties() {
	this.Scroll = new Coordinates((self.pageXOffset ? self.pageXOffset : ((document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : (document.body ? document.body.scrollLeft : 0))), (self.pageYOffset ? self.pageYOffset : ((document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : (document.body ? document.body.scrollTop : 0))));
	this.Dim = new Dimensions((self.innerWidth ? self.innerWidth : ((document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : (document.body ? document.body.clientWidth : 0))), (self.innerHeight ? self.innerHeight : ((document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0))));
}

function PutAtCenter(layerID) {
	pp = new PageProperties();
	var x = (pp.Scroll.X + (pp.Dim.Width > E(layerID).offsetWidth ? pp.Dim.Width - E(layerID).offsetWidth : 50) / 2) + 'px';
	var y = (pp.Scroll.Y + (pp.Dim.Height > E(layerID).offsetHeight ? pp.Dim.Height - E(layerID).offsetHeight : 50) / 2) + 'px';
	ES(layerID).top = y;
	ES(layerID).left = x;
}
function Pop(layerID) {
	ES(layerID).display = "block";
	ES(layerID).zIndex = NewHighestZIndex();
	PutAtCenter(layerID);
}

function AddToFavorites() {
	title = "NepalUpclose.com - All the news of Nepal";
	url = "http://www.NepalUpclose.com";
	Browser = "";
	if (window.sidebar) Browser = "FIREFOX";
	if (Browser == "" && window.external) Browser = "IE";
	if (Browser == "" && window.opera && window.print) Browser = "OPERA";
	switch (Browser) {
		case "FIREFOX": window.sidebar.addPanel(title, url, ""); break;
		case "IE": window.external.AddFavorite(url, title); break;
		case "OPERA": return true; break;
	}
}

var exdate = new Date();
exdate.setDate(exdate.getDate() + 1);

function ShowLoader() {
	ES("imgLoaderMain").visibility = "visible";
}

function HideLoader() {
	ES("imgLoaderMain").visibility = "hidden";
}

function ShowContent() {
	ES(ClientID.pnlBody).display = "block";
}

function ShowModalBackground() {
	var div = E("divModalPopup");
	if (!div) {
		alert('Could not create background layer for modal popup');
		return;
	}
	div.style.left = 0;
	div.style.top = 0;
	var pp = new PageProperties();
	div.style.width = document.body.scrollWidth;
	div.style.height = document.body.scrollHeight;
	div.style.position = "absolute";
	div.style.backgroundColor = "#000044";
	div.style.zIndex = NewHighestZIndex();
	div.style.display = "block";
	if (!document.all) div.style.opacity = 0.4;
	if (IEVersion < 7) ES("ifrmModalPopup").display = "block";
}

function ShowModal(event, id) {
	document.body.style.overflow = "hidden";
	ES(id).display = "block"; // need to do this here otherwise offsetWidth would be 0 below
	var pp = new PageProperties();
	//var x = (pp.Scroll.X + (pp.Dim.Width > E(id).offsetWidth ? pp.Dim.Width - E(id).offsetWidth : 50) / 2) + 'px';
	//var y = (pp.Scroll.Y + (pp.Dim.Height > E(id).offsetHeight ? pp.Dim.Height - E(id).offsetHeight : 50) / 2) + 'px';
	ShowModalBackground();

	ES(id).position = "absolute";
	ES(id).left = 0;
	ES(id).top = pp.Scroll.Y;
	ES(id).display = "block";
	ES(id).zIndex = NewHighestZIndex();
}

function HideModal(id) {
	ES("divModalPopup").display = "none";
	ES(id).display = "none";
	document.body.style.overflow = "auto";
	document.body.style.overflowY = "scroll";
}


var CurrentPost = 0;
var ifrmFullPost_Mode = "";
function ShowFullPostURL(url) {
	try {
		ES("ifrmFullPost").display = "none";
		ShowModal(null, "divFullPost");
		ifrmFullPost_Mode = "LOADING";
		E("ifrmFullPost").src = url;
		ES("divFullPost_Preloader").display = "block";
		ES("divFullPost_BackTop").display = "none";
		ShowFullPostBigyapan();
		CurrentPost = 0;
		setTimeout(Handle_ifrmFullPost_OnLoad, 300);
	} catch (ex) { alert("3ShowFullPostURL: " + ex.message); }
}

function ShowFullPost(event, postID, mode) {
	try {
		var prefix = "";
		if (mode == "Highlights") prefix = "H_";
		ES("ifrmFullPost").display = "none";
		ShowModal(event, "divFullPost");
		ifrmFullPost_Mode = "LOADING";
		var linkElem = E(prefix + "Post" + postID + "_RemoteUrl");
		var link = linkElem.data ? linkElem.data : (linkElem.textContent ? linkElem.textContent : linkElem.innerText);
		E("ifrmFullPost").src = link;
		$("#divFullPost_Preloader").slideToggle(300);
		ES("divFullPost_BackTop").display = "none";
		ShowFullPostBigyapan();
		CurrentPost = postID;
		setTimeout(Handle_ifrmFullPost_OnLoad, 15000);
	} catch (ex) { alert("ShowFullPost: " + ex.message); }
}
function ShowFullPostBigyapan() {
	if (!E("divFullPostBigyapan")) return;
	ES("divFullPostBigyapan").display = "block";
	PutAtCenter("divFullPostBigyapan");
	ES("divFullPostBigyapan").zIndex = NewHighestZIndex();
}

function HideFullPost() {
	if (CurrentPage == "NEWS_DETAILS") {
		location.href = "Default.aspx";
		return;
	} 
	try {
		ES("divFullPostBigyapan").display = "none";
	} catch (ex) { }
	try {
		ES(ClientID.pnlPlaceHolder).display = "block";
		HideModal("divFullPost");
		if (E("ifrmFullPost").src != hostURL + "pages/ifrm.html") E("ifrmFullPost").src = hostURL + "pages/ifrm.html"; //"about:blank";
		HideComments();
		ShowContent();
	} catch (ex) { }
}

function Handle_ifrmFullPost_OnLoad() {
	try {
		if (ifrmFullPost_Mode == "") return;
		ES("ifrmFullPost").display = "block";
		ES("ifrmFullPost").zIndex = NewHighestZIndex();
		ifrmFullPost_Mode = "";
		ES("divFullPost_Preloader").display = "none";
		ES("divFullPost_BackTop").display = "block";
		ES("ifrmFullPost").height = document.body.clientHeight - 42;
		MarkRead(CurrentPost);
		try { ES("divFullPostBigyapan").display = "none"; } catch (exdate) { }
		try { pageTracker._trackPageview('/News-Details.aspx?PostID=' + CurrentPost); } catch (exdate) { }
		CallBack("UPDATE_VIEW_COUNT", CurrentPost);
	} catch (ex) { alert("Handle_ifrmFullPost_OnLoad: " + ex.message); }
}

function FixPopup() {
	if (!E("ifrmFullPost")) return;
	if (E("ifrmFullPost").src != "about:blank") return;
	if (ES("divFullPost").display != "block") return;
	HideFullPost();
}



function Handle_body_OnKeyDown(event) {
	var ev = new EventVariable(event);
	if (ev.KeyCode != 8 && ev.KeyCode != 27) return true;
	var tag = ev.CallerObject.tagName.toLowerCase();
	var type = ev.CallerObject.type ? ev.CallerObject.type.toLowerCase() : "";
	if (tag == 'input' || type == 'text' || type == 'textarea') return true;
	HideFullPost();
	return false;
}

var ReadingHighlightPost = false;
function SwapNewsPostViewMode(postID, mode) {
	try {
		var prefix = "";
		if (mode == "Highlights") {
			prefix = "H_";
			ReadingHighlightPost = !ReadingHighlightPost;
		}
		if (!E(prefix + "PostE" + postID)) return; //TODO: need to fix this for highlighted items

		if (ES(prefix + "PostE" + postID).display == "none" || ES(prefix + "PostE" + postID).display == "") {
			MarkPreviewed(postID);
			$("#" + prefix + "PostE" + postID).slideToggle(300);
			$("#" + prefix + "PostC" + postID).slideToggle(600);
			try { pageTracker._trackEvent("Posts", "Previewed", postID); } catch (exdate) { }
		} else {
			$("#" + prefix + "PostE" + postID).slideToggle(300);
			$("#" + prefix + "PostC" + postID).slideToggle(600);
		}
	} catch (ex) { alert("SwapNewsPostViewMode: " + ex.message); }
}

var FeaturedRelatedItems = new Array();
function AddFeaturedRelatedItem(featuredID, postID, type, subHidden, hasMoreLink) {
	FeaturedRelatedItems[FeaturedRelatedItems.length] = { FeaturedID: featuredID, PostID: postID, Type: type, IsSubHidden: subHidden, HasMoreLink: hasMoreLink };
}
function ShowRelatedStories(featuredID) {
	$("#divMainFeatured" + featuredID).slideToggle(300);
	ES('divMainFeaturedC' + featuredID).display = 'none';
	for (i = 0; i < FeaturedRelatedItems.length; i++) {
		if (FeaturedRelatedItems[i].FeaturedID != featuredID) continue;
		if (FeaturedRelatedItems[i].HasMoreLink) ES("divMore" + featuredID + "_" + FeaturedRelatedItems[i].PostID).display = "block";
		if (FeaturedRelatedItems[i].IsSubHidden) continue;
		if (FeaturedRelatedItems[i].Type == "PHOTO") ES("imgFeatured" + featuredID + "_" + FeaturedRelatedItems[i].PostID).display = "inline";
		if (FeaturedRelatedItems[i].Type == "VIDEO") ES("divVideoFeatured" + featuredID + "_" + FeaturedRelatedItems[i].PostID).display = "block";
		if (FeaturedRelatedItems[i].Type == "RELATED") ES("divRelated" + featuredID + "_" + FeaturedRelatedItems[i].PostID).display = "block";
		}
}
function ShowMoreStories(featuredID) {
	for (i = 0; i < FeaturedRelatedItems.length; i++) {
		if (FeaturedRelatedItems[i].FeaturedID != featuredID) continue;
		if (FeaturedRelatedItems[i].HasMoreLink) ES("divMore" + featuredID + "_" + FeaturedRelatedItems[i].PostID).display = "none";
		if (!FeaturedRelatedItems[i].IsSubHidden) continue;
		if (FeaturedRelatedItems[i].Type == "RELATED") ES("divRelated" + featuredID + "_" + FeaturedRelatedItems[i].PostID).display = "block";
	}
}
function ShowFeaturedNewsPhotos(featuredID, photoNumber, rval) {
	url = "req/FeaturedGallery.swf?FeaturedID=" + featuredID + "&PhotoNumber=" + photoNumber + "&RVAL=" + Date.UTC();
	//alert(url);
	html = '';
	html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
	html += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"';
	html += 'width="640" height="580" id="FeaturedGallery" align="middle">';
	html += '<param name="allowScriptAccess" value="sameDomain" />';
	html += '<param name="allowFullScreen" value="false" />';
	html += '<param name="movie" value="' + url + '" />';
	html += '<param name="quality" value="high" />';
	html += '<param name="bgcolor" value="#f5f5f5" />';
	html += '<embed src="' + url + '"';
	html += 'quality="high" bgcolor="#f5f5f5" width="640" height="580" name="FeaturedGallery" align="middle"';
	html += ' allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash"';
	html += ' pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	html += '</object>';
	E("divFeaturedNewsPhotosContent").innerHTML = html;
	Pop("divFeaturedNewsPhotos");
}
function HideVideo() {
	E("divVideoBox").innerHTML = "";
	E("divVideoTitle").innerHTML = "";
	E("divVideoDescription").innerHTML = "";
	ES("divVideo").display = "none";
}

function ShowMoreNews() {
	ES("lnkNewsMore").display = "none";
	$("#divNewsMore").slideToggle(500);
}
function ShowFeaturedNewsVideo(featuredID) {
	E(ClientID.FeaturedNewsVideo_txtFeaturedID).value = featuredID;
	E(ClientID.FeaturedNewsVideo_txtAuthor).value = "";
	E(ClientID.FeaturedNewsVideo_txtCaption).value = "";
	E(ClientID.FeaturedNewsVideo_txtVideoURL).value = "";
	Pop("divFeaturedNewsVideoAdmin");
}
function ShowFeaturedNewsRelated(featuredPostID, relatedPostID) {
	E(ClientID.FeaturedNewsRelated_txtFeaturedPostID).value = featuredPostID;
	E(ClientID.FeaturedNewsRelated_txtRelatedPostID).value = relatedPostID;
	E(ClientID.FeaturedNewsRelated_chkHidden).checked = false;
	Pop("divFeaturedNewsRelatedAdmin");
}
function ToggleHideRelatedPost(relatedID) {
	E(ClientID.hdnBackgroundTaskName).value = "HIDE_NEWS_RELATED_POST";
	E(ClientID.hdnBackgroundTaskArgument).value = relatedID;
	E(ClientID.btnBackgroundTasks).click();
}
function ShowFeaturedNewsPhoto(featuredID) {
	E(ClientID.FeaturedNewsPhoto_txtFeaturedID).value = featuredID;
	Pop("divFeaturedNewsPhotoAdmin");
}

function MarkRead(id) {
	if (id == 0) return;
	try {
		if (E("PostC" + id)) {
			ES("PostC" + id).color = "#888888";
		}
		if (E("icoPostRead" + id)) ES("icoPostRead" + id).display = "inline";
		document.cookie = "PostsRead=" + GetCookie("PostsRead").replace("," + id + ",", ",") + id + "," + ";expires=" + exdate.toGMTString();
	} catch (ex) { alert("MarkRead: " + ex.message); }
}

function MarkPreviewed(id) {
	try {
		if (E("PostC" + id)) {
			ES("PostC" + id).fontWeight = "normal";
			ES("PostC" + id).color = "#888888";
		}
		document.cookie = "PostsPreviewed=" + GetCookie("PostsPreviewed").replace("," + id + ",", ",") + id + "," + ";expires=" + exdate.toGMTString();
	} catch (ex) { alert("MarkPreviewed: " + ex.message); }
}

function MarkAnalyticsRead(postID) {
	try { pageTracker._trackPageview('/News-Details.aspx?PostID=' + postID); } catch (ex) { }
}

function CloseReadingPost() {
	HideFullPost();
	if (CurrentPost <= 0) return;
	ShowContent();
	//MarkRead(CurrentPost);
	SwapNewsPostViewMode(CurrentPost);
	CurrentPost = 0;
}

function SetDesc(postID, desc) {
	if (!E("Post" + postID + "_Description")) return;
	E("Post" + postID + "_Description").innerHTML = desc;
}


var addthis_pub = "vkshrestha";
var addthis_brand = "";
var addthis_header_color = "#FFFF00";
var addthis_header_background = "#000000";
var addthis_options = 'facebook,delicious,digg,twitter,email,favorites,more';

function AddThisOpen(p1, p2, p3, p4) {
	try { addthis_open(p1, p2, p3, p4); } catch (ex) { }
}
function AddThisClose() {
	try { addthis_close(); } catch (ex) { }
}


function GetCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return ",";
}

function MarkReadPostsOnLoad() {
	var arr = GetCookie("PostsPreviewed").split(",");
	for (i = 0; i < arr.length; i++) {
		if (arr[i] == "") continue;
		MarkPreviewed(arr[i]);
	}
	var arr1 = GetCookie("PostsRead").split(",");
	for (i = 0; i < arr1.length; i++) {
		if (arr1[i] == "") continue;
		MarkRead(arr1[i]);
	}
}

function CallBack(name, arg) {
	E(ClientID.hdnBackgroundTaskName).value = name;
	E(ClientID.hdnBackgroundTaskArgument).value = arg;
	E(ClientID.btnBackgroundTasks).click();
}


function ChangeNewsFontSize(size) {
	var fs = ((size == 'LARGE') ? "14px" : ((size == "MEDIUM") ? "12px" : "11px"));
	ChangeCSS("IGPanel_Heading", "font-size", fs);
	ChangeCSS("IGPanel_SnipTitle", "font-size", fs);
	ChangeCSS("IGPanel_SnipDesc", "font-size", fs);
	ChangeCSS("GRPanel_Heading", "font-size", fs);
	ChangeCSS("GRPanel_SnipTitle", "font-size", fs);
	ChangeCSS("GRPanel_SnipDesc", "font-size", fs);
	ChangeCSS("HPanel_Heading", "font-size", fs);
	if (size == 'LARGE') ChangeCSS("IGPanel_Heading", "height", "22px");
	if (size == 'MEDIUM') ChangeCSS("IGPanel_Heading", "height", "18px");
	if (size == 'SMALL') ChangeCSS("IGPanel_Heading", "height", "16px");
	if (size == 'LARGE') ChangeCSS("HPanel_Heading", "height", "26px");
	if (size == 'MEDIUM') ChangeCSS("HPanel_Heading", "height", "22px");
	if (size == 'SMALL') ChangeCSS("HPanel_Heading", "height", "20px");
	ES("spnFontSizeSmall").backgroundColor = "transparent";
	ES("spnFontSizeMedium").backgroundColor = "transparent";
	ES("spnFontSizeLarge").backgroundColor = "transparent";
	if (size == "SMALL") ES("spnFontSizeSmall").backgroundColor = "orange";
	if (size == "MEDIUM") ES("spnFontSizeMedium").backgroundColor = "orange";
	if (size == "LARGE") ES("spnFontSizeLarge").backgroundColor = "orange";
	try { pageTracker._trackEvent("Links", "FontSize", size); } catch (exdate) { }
}


function ChangeCSS(theClass, element, value) {
	var cssRules = isIE ? 'rules' : 'cssRules';
	var added = false;
	theClass = "." + theClass;
	for (var S = 0; S < 1; S++) {
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
				if (document.styleSheets[S][cssRules][R].style[element]) {
					document.styleSheets[S][cssRules][R].style[element] = value;
					added = true;
					break;
				}
			}
		}

		if (!added) {
			if (document.styleSheets[S].insertRule) {
				document.styleSheets[S].insertRule(theClass + ' { ' + element + ': ' + value + '; }', document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(theClass, element + ': ' + value + ';');
			}
		}
	}
}

var CurrentPage = "";
function OnPageLoad() {
	return;
	try {
		switch (CurrentPage) {
			case "NEWS":
				E(ClientID.btnGetDescription).click();
				MarkReadPostsOnLoad();
				setInterval(FixPopup, 8000);
				break;

			case "BLOGS":
				MarkReadPostsOnLoad();
				setInterval(FixPopup, 8000);
				break;
				
			default:
		}
	} catch (ex) { alert("NewsPageLoad: " + ex.message); }
}

function OnWindowResize() {
	var id = "divFullPost";
	if (ES(id).display != "block") return;
	document.body.style.overflow = "hidden";
	ES(id).display = "block"; // need to do this here otherwise offsetWidth would be 0 below
	var pp = new PageProperties();
	ES(id).position = "absolute";
	ES(id).left = 0;
	ES(id).top = pp.Scroll.Y;
	ES(id).display = "block";
	ES(id).zIndex = NewHighestZIndex();
	ES("ifrmFullPost").height = document.body.clientHeight - 72;
}

function ShowRegisterLogin(hide) {
	if (hide) {
		ES("divLogin").display = "none";
	} else {
		ES("divLogin").display = "block";
		PutAtCenter("divLogin");
		ES("divLogin").zIndex = NewHighestZIndex();
		setTimeout(function() { E(ClientID.txtLEmail).focus(); }, 300);
	}
	HideComments();
	ES("divLinkUs").display = "none";
}
function CheckForgotPassword() {
	if (E(ClientID.txtLEmail).value == "") {
		email = prompt("Enter your email address", "");
		if (!email) return false;
		E(ClientID.txtLEmail).value = email;
	}
	return true;
}

function ShowComments(postID) {
	ShowRegisterLogin(true);
	ES("divLinkUs").display = "none";
	ES("divComments").display = "block";
	ES("divComments").zIndex = NewHighestZIndex();
	PutAtCenter("divComments");
	E(ClientID.hdnCommentPostID).value = postID;
	E(ClientID.lblCommentsMessage).innerHTML = "";
	ES("imgCommentsLoader").display = "block";
	ES("divCommentsList").display = "none";
	CallBack("BIND_COMMENTS", postID);
	FixCommentsPostForLogin();
	if (CurrenUser_LoggedIn) setTimeout(function() { E(ClientID.txtComment).focus(); }, 300);
}

function ShowLinkUs() {
	ShowRegisterLogin(true);
	HideComments();
	ES("divLinkUs").display = "block";
	ES("divLinkUs").zIndex = NewHighestZIndex();
	PutAtCenter("divLinkUs");
}

function ShowContactUs(hide) {
	HideComments();
	ShowRegisterLogin(true);
	if (hide) {
		ES("divContactUs").display = "none";
	} else {
		ES("divContactUs").display = "block";
		PutAtCenter("divContactUs");
		setTimeout(function() { E(ClientID.txtCUName).focus(); }, 300);
	}
}

function FixCommentsPostForLogin() {
	ES("divCommentsInput").display = CurrenUser_LoggedIn ? "block" : "none";
}

function HideComments() {
	ES("divComments").display = "none";
}

function SaveComments() {
	ES("imgCommentsLoader").display = "block";
}

function UpdateCommentsCount(postID, count) {
	if (E("PostComments" + postID)) E("PostComments" + postID).innerHTML = count;
	if (E("H_PostComments" + postID)) E("H_PostComments" + postID).innerHTML = count;
}

function UpdateViewCount(postID, count) {
	if (E("PostViews" + postID)) E("PostViews" + postID).innerHTML = count + " views";
	if (E("H_PostViews" + postID)) E("H_PostViews" + postID).innerHTML = count + " views";
}

function UpdateThumbsUpCount(postID, count) {
	if (E("PostThumbsUp" + postID)) E("PostThumbsUp" + postID).innerHTML = count;
	if (E("H_PostThumbsUp" + postID)) E("H_PostThumbsUp" + postID).innerHTML = count;
}

function UpdateThumbsUp(postID) {
	if (!CurrenUser_LoggedIn) {
		ShowRegisterLogin();
		alert("You need to login to perform this action.");
		return;
	}
	ShowLoader();
	CallBack("THUMBS_UP", postID);
}

function ShowVideoFromVideoPage(postID, videoID) {
	ShowVideo(videoID, E("Title" + postID).innerHTML, E("PostDescription" + postID).innerHTML, E("PostAuthor" + postID).innerHTML);
}
function ShowVideo(videoID, title, desc, author) {
	var html = "";
	html += '<object width="450" height="350">';
	html += '<param name="movie" value="http://www.youtube.com/v/' + videoID + '&hl=en&fs=1&rel=0&color1=0x006699&color2=0x54abd6&autoplay=1"></param>';
	html += '<param name="allowFullScreen" value="true"></param>';
	html += '<param name="allowscriptaccess" value="always"></param>';
	html += '<embed width="450" height="350"';
	html += 'src="http://www.youtube.com/v/' + videoID + '&hl=en&fs=1&rel=0&color1=0x006699&color2=0x54abd6&autoplay=1" ';
	html += 'type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true">';
	html += '</embed>';
	html += '</object>';
	E("divVideoBox").innerHTML = html;
	E("divVideoTitle").innerHTML = title;
	E("divVideoDescription").innerHTML = desc;
	E("divVideoAuthor").innerHTML = "Video uploaded by: <a href='http://www.youtube.com/user/" + author + "' target='_blank'>" + author + "</a>";
	ES("divVideo").display = "block";
	ES("divVideo").zIndex = NewHighestZIndex();
	PutAtCenter("divVideo");
	try { pageTracker._trackEvent("Videos", "Watched", videoID); } catch (exdate) { }
}

function LoadSnip(postID, layerID, ldrID) {
	if (E(layerID).innerHTML != "") return;
	ES(ldrID).display = "inline"
	E(ClientID.hdnBackgroundTaskName).value = "LOAD_SNIP";
	E(ClientID.hdnBackgroundTaskArgument).value = postID + "," + layerID + "," + ldrID;
	E(ClientID.btnBackgroundTasks).click();
}

function GenerateSnip(postID, blogID, blogTitle, postTitle, desc, postDateRelative, hasImage, urlKey, viewCount, commentsCount, likes, remoteURL, isAdmin, layerID, ldrID) {
	html = ""
	html += '<div class="IGPanel_SnipTitle" id="Post' + postID + 'Title" onclick="SwapNewsPostViewMode(' + postID + ');">';
	html += '<img src="img/logo/logo_' + blogID + '.png" title="' + E(ClientID.hdnPostDetailsBlogTitle).value + '" style="height:15px;" />';
	html += E(ClientID.hdnPostDetailsPostTitle).value + '</div>';
	html += '<table class="IGPanel_SnipTable" cellspacing="0" cellpadding="0"><tr>';
	html += '<td class="IGPanel_SnipTools" id="Post' + postID + '_SnipToolsUp">';
	if (isAdmin) {
		html += '<img src="img/design/add.gif" onclick="StartFeaturePost(' + postID + ');" title="Feature Post" style="cursor:pointer;" /> ';
		html += '<img src="img/design/edit.gif" onclick="EditPost(' + postID + ');" title="Edit Post" style="cursor:pointer;" /> ';
		html += '<img src="img/design/trash.gif" onclick="DisablePost(' + postID + ');" title="Disable Post" style="cursor:pointer;" /> ';
		html += '<img src="img/design/related.gif" onclick="ShowFeaturedNewsRelated(\'\', ' + postID + ');" title="Add Related" style="cursor:pointer;" /> ';
	}
	html += '<span id="Post' + postID + '_Date">posted ' + postDateRelative + '</span>';
	html += '<span id="PostViews' + postID + '" style="margin-left:50px;">' + viewCount + ' views</span>';
	html += '<img src="img/design/comments.gif" align="absmiddle" style="margin-left:50px;" /> <a href="javascript:void(0);" onclick="ShowComments(' + postID + ');">Comments</a>';
	html += ' <span id="PostComments' + postID + '">' + commentsCount + '</span>';
	html += '</td></tr><tr><td class="IGPanel_SnipDesc" id="Post' + postID + '_Description">';
	if (hasImage) html += '<img src="img/posts/' + postID + '.jpg" style="float:left;margin:3px;" />' + E(ClientID.hdnPostDetailsPostDescription).value;
	html += '</td></tr><tr><td class="IGPanel_SnipTools" id="Post' + postID + '_SnipTools">';
	html += '<img src="img/design/read.png" align="absmiddle" /> ';
	html += '<a id="Post' + postID + '_LocalURL" href="' + postID + '-FullNews-' + urlKey + '.aspx" onclick="ShowFullPost(event, ' + postID + ', \'\');return false;">Read Full Post</a>';
	html += '<img src="img/design/facebook.png" align="absmiddle" style="margin-left:40px;" /> ';
	html += '<a href="javascript:void(0);" onmouseout="AddThisClose();" onclick="return AddThisOpen(this, \'\', \'http://www.nepalupclose.com/' + postID + '-FullNews-' + urlKey + '.aspx\', \'\');">Share in facebook</a>';
	html += '<img src="img/design/thumbs_up.gif" onclick="UpdateThumbsUp(' + postID + ');" title="Click here to like this post." alt="like" class="imgLike" align="absmiddle" style="margin-left:25px;" />';
	html += ' <span id="PostThumbsUp' + postID + '">' + likes + ' people liked this post.</span>';
	html += '</td></tr></table>';
	html += '<span style="display:none;" id="Post' + postID + '_RemoteUrl">' + remoteURL + '</span>';
	if (E(layerID)) {
		E(layerID).innerHTML = html;
		ES(layerID).display = "block";
		}
	if (E(ldrID)) ES(ldrID).display = "none";
}

function GenerateSnipTools(postID, mode, commentsCount, viewCount, likes, postDate) {
	var html = "";
	var prefix = "";
	if (mode == 'Highlights') prefix = 'H_';

	if (!E(prefix + "Post" + postID + "_SnipTools")) return;

	html += '<span id="' + prefix + 'Post' + postID + '_Date">posted ' + postDate + '</span>';

	html += '<span id="' + prefix + 'PostViews' + postID + '" style="margin-left:50px;">' + viewCount + ' views</span>';
	
	html += '<img src="img/comments.gif" align="absmiddle" style="margin-left:50px;" />';
	html += '<a href="javascript:void(0);" onclick="ShowComments(' + postID + ');">Comments</a> ';
	html += '<span id="' + prefix + 'PostComments' + postID + '">' + commentsCount + '</span>';

	E(prefix + "Post" + postID + "_SnipToolsUp").innerHTML += html;

	html = "";

	//html += '<img src="img/read.png" align="absmiddle" /> ';
	//html += '<a id="' + prefix + 'Post' + postID + '_LocalURL" href="News-Details.aspx?PostID=' + postID + '" onclick="ShowFullPost(event, ' + postID + ', \'' + mode + '\');return false;">';
	//html += 'Read Full Post</a>';

	html += '<img src="img/facebook.png" align="absmiddle" style="margin-left:40px;" /> ';
	html += '<a href="javascript:void(0);" onmouseout="addthis_close();" onmouseover="return addthis_open(this, \'\', hostURL + \'News-Details.aspx?PostID=' + postID + '\', E(\'Post' + postID + '_Title\').innerHTML);">';
	html += 'Share in facebook</a>';

	html += '<img src="img/thumbs_up.gif" onclick="UpdateThumbsUp(' + postID + ');" title="Click here to like this post." alt="like" class="imgLike" align="absmiddle" style="margin-left:25px;" />';
	html += '<span id="' + prefix + 'PostThumbsUp' + postID + '">' + likes + ' people liked this post.</span>';
	
	E(prefix + "Post" + postID + "_SnipTools").innerHTML += html;
}


function NewsPage_ChangeMode(pageMode) {
	if (pageMode == "MAIN") ES("imgNavLdrMain").visibility = "visible";
	if (pageMode == "SOCIETY-SAMAJ") ES("imgNavLdrSociety").visibility = "visible";
	if (pageMode == "ECONOMY-BUSINESS") ES("imgNavLdrBusiness").visibility = "visible";
	if (pageMode == "PAGE3") ES("imgNavLdrPage3").visibility = "visible";
	if (pageMode == "SPORTS") ES("imgNavLdrSports").visibility = "visible";
	if (pageMode == "INTERVIEW") ES("imgNavLdrInterview").visibility = "visible";
	if (pageMode == "OPINION-VIEWS") ES("imgNavLdrOpinion").visibility = "visible";
	if (pageMode == "WORLD") ES("imgNavLdrWorld").visibility = "visible";
	E(ClientID.hdnCommandName).value = "CHANGE_MODE";
	E(ClientID.hdnCommandArgs).value = pageMode;
	E(ClientID.btnCommand).click();
}
function NewsPage_ChangePaging(pageMode, blogCode, blogID, pageNumber) {
	E(ClientID.hdnCommandName).value = pageMode;
	E(ClientID.hdnCommandArgs).value = "CHANGE_PAGE_NUMBER," + blogCode + "," + pageNumber;
	E(ClientID.btnCommand).click();
	ES("News" + pageMode + "_Loader_" + blogID).display = "block";
}
function NewPage_CloseAllModes() {
	ES('tblNewsMain').display = 'none';
	ES('tblNewsPage3').display = 'none';
	ES('tblNewsSports').display = 'none';
	ES('tblNewsWorld').display = 'none';
	ES('tblNewsOpinion').display = 'none';
	ES('tblNewsSociety').display = 'none';
	ES('tblNewsInterview').display = 'none';
	ES('tblNewsBusiness').display = 'none';
	ES("NewsNavLinkMain").color = "#604020";
	ES("NewsNavLinkPage3").color = "#604020";
	ES("NewsNavLinkBusiness").color = "#604020";
	ES("NewsNavLinkSports").color = "#604020";
	ES("NewsNavLinkInterview").color = "#604020";
	ES("NewsNavLinkOpinion").color = "#604020";
	ES("NewsNavLinkWorld").color = "#604020";
	ES('NewsNavLinkSociety').color = "#604020";
	ES('NewsNavLinkInterview').color = "#604020";
	ES("imgNavLdrMain").visibility = "hidden";
	ES("imgNavLdrSociety").visibility = "hidden";
	ES("imgNavLdrBusiness").visibility = "hidden";
	ES("imgNavLdrPage3").visibility = "hidden";
	ES("imgNavLdrSports").visibility = "hidden";
	ES("imgNavLdrInterview").visibility = "hidden";
	ES("imgNavLdrOpinion").visibility = "hidden";
	ES("imgNavLdrWorld").visibility = "hidden";
}
var NewsPage_MainTimer;
var NewsPage_MouseMovement = false;
function NewsPage_SetMainTimer() {
	if (NewsPage_MouseMovement) return;
	NewsPage_MainTimer = setTimeout(function() { NewsPage_ChangeMode("MAIN"); }, 10 * 60 * 1000);
}
function NewsPage_ResetMainTimer() {
	clearTimeout(NewsPage_MainTimer);
}
document.onmousemove = function() { NewsPage_MouseMovement = true; }
setTimeout(function() { NewsPage_MouseMovement = false; }, 3 * 60 * 1000);

function NavBar_MouseOver(obj, category) {
	if (NewsCategory == category) return;
	obj.style.color = "#2222EE";
}

function NavBar_MouseOut(obj, category) {
	if (NewsCategory == category) return;
	obj.style.color = "#3030B0";
}

var CurrentPhotoFeature = 1;
var CurrentPhotoFeature_Timer = 0;
function PhotoFeature_Rotate() {
	ES("divPhotoFeature1").display = "none";
	ES("divPhotoFeature2").display = "none";
	ES("divPhotoFeature3").display = "none";
	ES("divPhotoFeature4").display = "none";
	ES("divPhotoFeature5").display = "none";
	ES("lnkPhotoFeature1").backgroundColor = "transparent";
	ES("lnkPhotoFeature2").backgroundColor = "transparent";
	ES("lnkPhotoFeature3").backgroundColor = "transparent";
	ES("lnkPhotoFeature4").backgroundColor = "transparent";
	ES("lnkPhotoFeature5").backgroundColor = "transparent";
	ES("lnkPhotoFeature1").color = "#444444";
	ES("lnkPhotoFeature2").color = "#444444";
	ES("lnkPhotoFeature3").color = "#444444";
	ES("lnkPhotoFeature4").color = "#444444";
	ES("lnkPhotoFeature5").color = "#444444";
	ES("lnkPhotoFeature1").padding = "2px";
	ES("lnkPhotoFeature2").padding = "2px";
	ES("lnkPhotoFeature3").padding = "2px";
	ES("lnkPhotoFeature4").padding = "2px";
	ES("lnkPhotoFeature5").padding = "2px";
	ES("divPhotoFeature" + CurrentPhotoFeature).display = "block";
	ES("lnkPhotoFeature" + CurrentPhotoFeature).backgroundColor = "#D0D0D0";
	ES("lnkPhotoFeature" + CurrentPhotoFeature).color = "#000000";
	ES("divPhotoFeaturePager").display = "block";
	CurrentPhotoFeature++;
	if (CurrentPhotoFeature > 5) CurrentPhotoFeature = 1;
	CurrentPhotoFeature_Timer = setTimeout(PhotoFeature_Rotate, 20 * 1000);
}
function PhotoFeature_RotateTo(id) {
	clearTimeout(CurrentPhotoFeature_Timer);
	CurrentPhotoFeature = id;
	PhotoFeature_Rotate();
}
function GetCurrentPhotoFeatureImage() {

}
function EditPost(postID) {
	E(ClientID.EditPost_hdnPostID).value = postID;
	E(ClientID.EditPost_btnEdit).click();
}
function ShowEditPost() {
	ES("divEditPost").display = "block";
	PutAtCenter("divEditPost");
}
function DisablePost(postID) {
	if (!confirm('Are you sure to disable the post?')) return;
	ES("divEditPost").display = "none";
	E(ClientID.EditPost_hdnPostID).value = postID;
	E(ClientID.EditPost_btnDisable).click();
}
function StartFeaturePost(postID) {
	ES("divFeaturePost").display = "none";
	E(ClientID.FeaturePost_txtPostID).value = postID;
	E(ClientID.FeaturePost_btnEdit).click();
}
function ShowFeaturePost() {
	ES("divFeaturePost").display = "block";
	PutAtCenter("divFeaturePost");
}

var CurrentPlaylistTitle = "";
function ShowMusicPlayer(playlist, divID, title, img) {
	var html = "";
	CurrentPlaylistTitle = title;
	if (!img) img = '';
	html += '<object width="480" height="300" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
	html += '<param name="allowScriptAccess" value="sameDomain">';
	html += '<param name="movie" value="http://www.dhakatopi.com/include/flash/xspf_player.swf?playlist_url=' + playlist + '&main_image=' + img + '&image=' + img + '&autoload=true&autoplay=true&playlist_title=Site+Playlist&repeat_playlist=true">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#E6E6E6">';
	html += '<param name="player_title" value="' + title + '">';
	html += '<param name="info_button_text" value="NepalUpclose.com - Music from Dhakatopi.com">';
	html += '<embed quality="high" bgcolor="#E6E6E6" name="dhakatopi.com" allowscriptaccess="sameDomain"';
	html += ' info_button_text="NepalUpclose.com - Music from Dhakatopi.com" player_title="' + title + '"';
	html += ' src="http://www.dhakatopi.com/include/flash/xspf_player.swf?playlist_url=' + playlist + '&main_image=' + img + '&image=' + img + '&autoload=true&autoplay=true&playlist_title=Site+Playlist&repeat_playlist=true"';
	html += ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"';
	html += ' width="480" height="300" align="center"></embed></object>';
	E(divID).innerHTML = html;
	E(divID + "_NowPlaying").innerHTML = title;
	try { pageTracker._trackEvent("Music", "Listened", title); } catch (exdate) { }
}
function ShowMusicPlayerRaaga(playlist, divID, title) {
	var html = "";
	CurrentPlaylistTitle = title;

	html += '<object width="480" height="300" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0">';
	html += '<param name="movie" value="http://www.raaga.com/player4/std-embed/embed-pl.swf?idsnew=' + playlist + '&mode=100&q=1&a=1" />';
	html += '<param name="quality" value="high" /><param name="wmode" value="transparent" />';
	html += '<embed play="false" swliveconnect="true" id="raagaswf" wmode="transparent" ';
	html += 'src="http://www.raaga.com/player4/std-embed/embed-pl.swf?idsnew=' + playlist + '&mode=100&q=1&a=1"';
	html += ' quality="high" bgcolor="#000000" width="480" height="300" type="application/x-shockwave-flash"></embed></object>';
	
	E(divID).innerHTML = html;
	E(divID + "_NowPlaying").innerHTML = title;
	try { pageTracker._trackEvent("Music", "Listened", title); } catch (exdate) { }
}
function ShowFMStation(station, divID, title) {
	var html = "";
	CurrentPlaylistTitle = title;

	html += '<object width="480" height="300" id="Player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Loading..."  type="application/x-oleobject">';
	html += '<param name="uiMode" value="full" />';
	html += '<param name="URL" value="http://www.mazzako.nepalnews.com/FM/hits.php" />';
	html += '<param name="autoStart" value="true" />';
	html += '<param name="enableContextMenu" value="false" />';
	html += '<param name="playCount" value="9999" />';
	html += '<embed type="application/x-mplayer2" src="http://www.mazzako.nepalnews.com/FM/hits.php" id="Player2" showcontrols="1" ';
	html += 'showdisplay="0" autostart="1"  showstatusbar="1" height="63" width="230" class="wmnbav"  />'
	html += '</embed></object> ';
	
	E(divID).innerHTML = html;
	E(divID + "_NowPlaying").innerHTML = title;
	try { pageTracker._trackEvent("Music", "Listened", title); } catch (exdate) { }
}


function ChangePage(changeTo) {
	E(ClientID.hdnChangePageTo).value = changeTo;
	E(ClientID.btnChangePage).click();
}


/* SUSHIL WORKS */


function ShowPostAdDiv(divName, hide) {
	if (hide) {
		ES(divName).display = "none";
	} else {
		ES(divName).display = "block";
		PutAtCenter(divName);
		setTimeout(function() { E(ClientID.txtTitle).focus(); }, 300);
	}
}

function ShowAdCommentDiv(divName, hide) {
	if (hide) {
		ES(divName).display = "none";
	} else {
		ES(divName).display = "block";
		PutAtCenter(divName);
	}
}


function hdnButtonClick(adID, action) {

	E(ClientID.hdnEAdID).value = adID;
	E(ClientID.hidCommandName).value = action;
	E(ClientID.btnExecuteCommand).click();
}

function clearAddPostDiv() {
	E(ClientID.txtTitle).value = "";
	E(ClientID.txtAdDescription).value = "";
}

function changePreview(changeName) {
	ES("tdAdPreview").fontSize = E(ClientID.ddlFontSize).value;
	E("tdAdPreview").innerHTML = E(ClientID.txtTitle).value;
	ES("tdAdPreview").backgroundColor = '#' + E(ClientID.ddlBackGroundColor).value;
}

function validateAdPost() {
	if (E(ClientID.ddlCountry).options.selectedIndex == 0) {
		alert('Please select the country.');
		return false;
	}
	else if (E(ClientID.ddlCategory).options.selectedIndex == 0) {
		alert('Please select the category.');
		return false;
	}
	else if (E(ClientID.txtAdDescription).value.length < 10) {
		alert('Please post the meaningful description for advertisement.');
		return false;
	}
	else if (E(ClientID.txtTitle).value == "") {
		alert("Title for advertisement is mandetory.");
		return false;
	}
	else if (E(ClientID.txtTitle).value.length > 50) {
		alert("Title is way too long.\n\nPlease limit advertisement title to 50 characters.");
		return false;
	}
	else if (E(ClientID.txtAdDescription).value.length > 500) {
		alert("Description is too long.\n\nPlease limit advertisement description to 500 characters.");
		return false;
	}

	return true;
}

function validateCommentPost() {
	if (E(ClientID.txtPostAdComments).value.length > 500) {
		alert('Please select the country.');
		return false;
	}
	else if (E(ClientID.txtPostAdComments).value.length < 10) {
		alert('Please post the meaningful comment.');
		return false;
	}
	return true;
}

function ShowDiv(divName, hide) {
	if (hide) {
		ES(divName).display = "none";
	} else {
		ES(divName).display = "block";
		PutAtCenter(divName);
		setTimeout(function() { E(ClientID.txtBlogCode).focus(); }, 300);
	}
}






