var pageOnLoad = false;

// for dv ajax call 
function viewComment(item_id,section) {
	var options = {asynchronous:true,
				   evalScripts:true};
	new Ajax.Updater('commentbox','/ajax/view_comment/'+item_id+'/'+section,options);
}

function commentEntry(item_id , section){
	var options = {asynchronous:true,
				   evalScripts:true};
	//alert(item_id +" - "+ section);
	new Ajax.Updater('commentbox','/ajax/comment_entry/'+item_id+'/'+section,options);
}

function selectCategory(section,category,page){
	//var category = document.getElementById('category').value;
	//alert(category);
	
	var options = {asynchronous:true,
				   evalScripts:true};
	new Ajax.Updater('dv_selection','/ajax/select_category/'+section+'/'+category+'/'+page,options);
}

function selectDv(section,item_id){
	var options = {asynchronous:true,
				   evalScripts:true};
	new Ajax.Updater('dv_content','/ajax/select_dv/'+section+'/'+item_id,options);
}

function updateThumb(section,item_id){
	//alert(section+item_id);
	var divId = 'dv_thumb_'+section+'_'+item_id;
	var field = document.getElementById(divId);
	if (field != null){
		var options = {asynchronous:true,
					   evalScripts:true};
		new Ajax.Updater(divId,'/ajax/update_thumb/'+section+'/'+item_id,options);
	}
}

// start the video after the page is loaded
function startDvVideo(){
	if (pageOnLoad){
		if (typeof flashProxy != 'undefined'){ 
			if ((typeof isDvSection != 'undefined') && (isDvSection)){
				//alert("flash proxy is exist");
				flashProxy.call('startDvVideo');
			}
		}
	}
}

function switchNav(){
	if (document.getElementById('edit_mode_div').style.display == "none"){
		document.getElementById('edit_mode_div').style.display = "inline";
	}
	else {
		document.getElementById('edit_mode_div').style.display = "none";
	}
		
	if (document.getElementById('view_mode_div').style.display == "none"){
		document.getElementById('view_mode_div').style.display = "inline";
	}
	else {
		document.getElementById('view_mode_div').style.display = "none";
	}
}

function viewMode(){
	switchNav();
	
	//alert(window.frames.commentbox_frame.viewComment);	
	window.frames.commentbox_frame.viewComment(item_id,section);	
}

function editMode(){
	switchNav();
	//document.commentbox_frame.commentEntry(item_id,section);	
	window.frames.commentbox_frame.commentEntry(item_id,section);
}

function switchDvMiniprogramme(page) {
	var options = {asynchronous:true,
				   evalScripts:true};
	
	new Ajax.Updater('miniprogramme','/ajax/update_dv_miniprogramme/'+page,options);
}

function copyDvEmbed(){
	var copyText = document.getElementById('copyText');
	r=copyText.createTextRange(); 
	r.select(); 
	r.execCommand('copy'); 
}

function copyDvLink(){
	var copyText = document.getElementById('copyLinkText');
	r=copyText.createTextRange(); 
	r.select(); 
	r.execCommand('copy'); 
}
