// JavaScript Document
var ooDv=document.createElement("div");
var myDv=document.createElement("div");
var mydvHdr=document.createElement("div");
var mydvBdy=document.createElement("div");
var x=0;
var id;
var filter;
var key;

// constants to define the title of the alert and button text.
var ALERT_BLOG_TITLE = "Delete The Blog";
var ALERT_NEWS_TITLE=  "Delete The News";
var ALERT_POLL_TITLE=  "Delete The Poll";
var ALERT_VIDEO_TITLE=  "Delete The Video";
var ALERT_BUTTON_TEXT = "Ok";




	function deleteblog(header_text,blog_id){
		createCustomAlert(header_text,'blog');
		id=blog_id;
	}

	function deleteNews(header_text,news_id){
		createCustomAlert(header_text,'news');
		id=news_id;
		
	}

	function deletePoll(header_text,poll_id){
		createCustomAlert(header_text,'poll');
		id=poll_id;
	}

	
	
	function deleteVideo(header_text,video_id,video_key){
		createCustomAlert(header_text,'video');
		id=video_id;
		key=video_key;
	}

	function createCustomAlert(txt,title) {
		customAlert();
		// create an H1 element as the title bar
		h1 = alertObj.appendChild(d.createElement("h1"));
		switch(title)
		{
			case 'blog':
				h1.appendChild(d.createTextNode(ALERT_BLOG_TITLE));
				break;
			case 'news':
				h1.appendChild(d.createTextNode(ALERT_NEWS_TITLE));
				break;
			case 'poll':
				h1.appendChild(d.createTextNode(ALERT_POLL_TITLE));
				break;
			case 'video':
				h1.appendChild(d.createTextNode(ALERT_VIDEO_TITLE));
				break;

		}
					
		// create a paragraph element to contain the txt argument
		msg = alertObj.appendChild(d.createElement("p"));
		msg.appendChild(d.createTextNode(txt));

		// create an anchor element to use as the confirmation button.
		btn = alertObj.appendChild(d.createElement("a"));
		btn.id = "okBtn";
		btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	
		// create an anchor element to use as the confirmation button.
		btncan = alertObj.appendChild(d.createElement("a"));
		btncan.id = "closeBtn";
		btncan.appendChild(d.createTextNode('Cancel'));
		
		// set up the onclick event to remove the alert when the anchor is clicked
		btn.onclick = function() { removeAlert(title); }
		btncan.onclick = function() { removeCustomAlert();return false; }
	}

	function customAlert()
	{
		// shortcut reference to the document object
		d = document;
		// if the modalContainer object already exists in the DOM, bail out.
		if(d.getElementById("modalContainer")) return;
		// create the modalContainer div as a child of the BODY element
		mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
		mObj.id = "modalContainer";
		 // make sure its as tall as it needs to be to overlay all the content on the page
		mObj.style.height = document.documentElement.scrollHeight + "px";
		//mObj.style.height = "200px";	
		// create the DIV that will be the alert 
		alertObj = mObj.appendChild(d.createElement("div"));
		alertObj.id = "alertBox";
		// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
		//if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
		// center the alert box
		alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
	}

	// removes the element
	function removeAlert(title) {
		document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
		switch(title)
		{
			case 'blog':
				del_user_blog();
				break;
			case 'news':
				del_user_news();
				break;
			case 'poll':
				del_user_poll();
				break;
			case 'video':
				del_user_video();
				break;

		}

		
			
		return false;
	}

	function del_user_blog(){
		document.location.href="/user/account/blog_delete/"+id;
	}

	function del_user_news(){
		url="/user/account/news_delete/?news_id="+id;
		
		document.location.href=url;
	}

	function del_user_poll(){
		url="/user/account/poll_delete/?poll_id="+id;
		document.location.href=url;
	}

	function del_user_video(){
		url="/user/account/video_remove/?vid="+id+"&video_key="+key;
		
		document.location.href=url;
	
	}





	function show(){
		ooDv.style.width='100%';
		ooDv.style.height='1000px';
		ooDv.style.top='0%';
		ooDv.style.left='0%';
		ooDv.style.zIndex='1001';
		ooDv.style.backgroundColor='#FFFFFF';
		ooDv.style.visibility='visible';
		myDv.style.visibility='visible';
		ooDv.style.filter='alpha(opacity=90)'; // IE
		ooDv.style.opacity='0.90'; // FF
		myDv.style.left='35%';
		myDv.style.top='25%';
		ooDv.setAttribute('id','ooDv');
		ooDv.setAttribute('name','ooDv');
		//document.body.appendChild(ooDv);
		//ooDv.focus();
	}

	function hide(){
		ooDv.style.visibility='hidden';
		myDv.style.visibility='hidden';
	}

	function del(id){
		document.location.href="/blog/delete/?blog_id="+id;
	}

	function setdeletecontent(id){
		//mydvBdy.innerHTML="<input style=\"margin-left:25%;\" type=button value=Yes onclick=javascript:del_user_blog("+id.toString()+"); /> <input type=button value=No onclick=hide() />";
	}

	function setsavecontent(){
		createCustomAlertSave('By Saving this post as a draft, it will be accessible from the blog management area. Until you click Publish, your posting will not be seen by visitors to your profile');
	}

	// removes the custom alert from the DOM
	function removeCustomAlert() {
		document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
		return false;
	}

	function createCustomAlertSave(txt) {
		customAlert();
		// create an H1 element as the title bar
		h1 = alertObj.appendChild(d.createElement("h1"));
		h1.appendChild(d.createTextNode("Save"));
		// create a paragraph element to contain the txt argument
		msg = alertObj.appendChild(d.createElement("p"));
		msg.appendChild(d.createTextNode(txt));
		// create an anchor element to use as the confirmation button.
		btn = alertObj.appendChild(d.createElement("a"));
		btn.id = "okBtn";
		btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
		// create an anchor element to use as the confirmation button.
		btncan = alertObj.appendChild(d.createElement("a"));
		btncan.id = "closeBtn";
		btncan.appendChild(d.createTextNode('Cancel'));
		// set up the onclick event to remove the alert when the anchor is clicked
		btn.onclick = function() { javascript:document.blog_form.submit();return true; }
		btncan.onclick = function() { removeCustomAlert();return false; }
	}



function createMultipleFileBrowse(formId,fileBrowserId)
{
     var ni = document.getElementById(formId);
     var array_size=document.getElementsByName('img1[]');
		if(array_size!=null)
		{
			var size_field=array_size.length
			if(array_size.length<5)
			{
				
				var addBrowseDiv=document.createElement("div");
				addBrowseDiv.id="new_browse"+size_field;
				
				var temp="<input type=\"file\" id=\"f"+size_field+"\" name=\"img1[]\" />";
				temp=temp+"<input type=\"button\" value=\"Remove\" onclick=\"remove_browse('"+formId+"','new_browse"+size_field+"');$('#AddMoreFiles').show();\" />";
				addBrowseDiv.innerHTML=temp;
				ni.appendChild(addBrowseDiv);
				return true;
			}
			
			if(array_size.length>=5) {
				$('#AddMoreFiles').hide();	
			} else {
				$('#AddMoreFiles').show();	
			}
			
		}

}

function remove_browse(formId,item_id)
{
	var ni=document.getElementById(formId);
	var divtoremove=document.getElementById(item_id);
	ni.removeChild(divtoremove);


}
function remove_photo(count){
			var dv_remove='user_photo'+count;
			document.getElementById(dv_remove).innerHTML="";
			if(document.getElementById('txt_remove_photo').value==""){
				document.getElementById('txt_remove_photo').value=count;
			}
			else{
				document.getElementById('txt_remove_photo').value=document.getElementById('txt_remove_photo').value +","+count;
			}
		}
