//
// Main js functions
//


//
// Menu Set-Up
//
var mainPostsMenuForSuperUsers=new Array();
mainPostsMenuForSuperUsers[0]='<a href="/news/wp-login.php" target="_blank">WordPress Login</a>';
mainPostsMenuForSuperUsers[1]='<a href="/site/main/newsIndustryEvents.php">Industry Events Archive</a>';
mainPostsMenuForSuperUsers[2]='<a href="/site/main/newsIndustryEventsAdd.php">Add Industry Event</a>';
mainPostsMenuForSuperUsers[3]='<a href="/site/main/updateLog/updateLog.php">System Update Archive</a>';
mainPostsMenuForSuperUsers[4]='<a href="/site/main/updateLog/updateLogAdd.php">Add System Update</a>';

var mainPostsMenu=new Array();
mainPostsMenu[0]='<a href="/site/main/newsIndustryEvents.php">Industry Events Archive</a>';
mainPostsMenu[1]='<a href="/site/main/updateLog/updateLog.php">System Update Archive</a>';

var mainAccountsMenu=new Array();
mainAccountsMenu[0]='<a href="/site/main/accountsView.php">Accounts Listing</a>';
mainAccountsMenu[1]='<a href="/site/main/addTrialAccount.php">Add New Account</a>';


var mainToolsMenu=new Array();
mainToolsMenu[0]='<a href="/site/openx-2.8.1/index.php">Banner Ad Management</a>';
mainToolsMenu[1]='<a href="/site/AdManagement/">Banner Ad Management (old)</a>';
mainToolsMenu[2]='<a href="/site/main/defaultWorkPlan/defaultWorkPlanManagement.php">Default Work Plan Mgmt.</a>';
mainToolsMenu[3]='<a href="/site/main/testimonials/testimonials.php">Testimonial Management</a>';




//
// Functions
//

// remove news post
function removeNewsPost(id) {
	var answer = confirm('Are you sure you wish to delete post?');
	if(answer == true) {
		window.location='/site/main/newsDelete.php?id='+id;
	}
}


// remove news post
function removeIndustryEventPost(id) {
	var answer = confirm('Are you sure you wish to delete post?');
	if(answer == true) {
		window.location='/site/main/newsIndustryEventsDelete.php?id='+id;
	}
}




//===============================
//
// Default Work Plan Management
//
function addDefaultWorkPlanItem() {
	var selectedIndex = window.document.workPlanForm.categoryTypeToAdd.options.selectedIndex;
	var category = window.document.workPlanForm.categoryTypeToAdd.options[selectedIndex].value;
	if(category > 0) {
		window.location = '/site/main/defaultWorkPlan/defaultWorkPlanAdd.php?cat=' + category;
	} else {
		alert("Choose category before adding item.");	
	}
}

function updateDefaultWorkPlan(wpID,field) {
	var answer = true;
	var elementName = "workPlan" + field + "_" + wpID;
	if(field != "Delete") {
		var element = window.document.getElementsByName(elementName);
		if(field == "Status") {
			var selectedIndex = element[0].options.selectedIndex;
			var newValue = element[0].options[selectedIndex].value;
		} else {
			var newValue = element[0].value;
		}
	} else {
		answer = confirm("Are you sure you wish to delete this item?");
		if(answer == false) {
			return false;	
		}
	}
	if(field != "") {
		var action = "/site/main/defaultWorkPlan/defaultWorkPlanUpdate.php?field=" + field + "&id=" + wpID;
		window.document.workPlanForm.action = action;
		window.document.workPlanForm.target = "hiddenFrame";
		window.document.workPlanForm.submit();
	} else {
		alert("Invalid data entered.");	
	}

}


//==================================
//
// Testimonials
//
//==================================


//
// Toggle Testimonial Visible
//
function toggleTestimonialVisible(id) {

	var myForm = addFormToWindow(window,'myForm');
	
	// Get text
	var text = window.document.getElementsByName("testimonialText_" + id)[0].value;
	
	// Get image
	var imageObj = window.document.getElementsByName("visibleImage_" + id)[0];
	var imageValueObj = window.document.getElementsByName("visible_" + id)[0];
	var imageValue = imageValueObj.value;

	// Flip Image
	if(imageValue == "No") {
		var newImage = "/site/images/yes.png";
		var visible = 'Yes';
		imageValueObj.value = visible; 
	} else {
		var newImage = "/site/images/no.png";
		var visible = 'No';
		imageValueObj.value = visible;
	}
	imageObj.src = newImage;
	
	addPostToForm(myForm,'visible',visible);
	addPostToForm(myForm,'id',id);
	addPostToForm(myForm,'text',text);
	addPostToForm(myForm,'refresh','No');
	
	myForm.method = 'POST';
	myForm.target = 'hiddenFrame';
	myForm.action = '/site/main/testimonials/updateTestimonials.php';
	myForm.submit();
}

//
// Update Testimonial
//
function updateTestimonial(id) {
	var myForm = window.document.getElementsByName("myForm")[0];
	addPostToForm(myForm,'id',id);
	addPostToForm(myForm,'refresh','Yes');
	
	myForm.method = 'POST';
	myForm.target = '_top';
	myForm.action = '/site/main/testimonials/updateTestimonials.php';
	myForm.submit();
	
}

//=====================================
//
// Update Log
//

// Update Update Log (uhh... yeah... whatever...)
function updateLogEdit(id,visible) {
	
	var myForm = addFormToWindow(window,'myForm');
	addPostToForm(myForm,'id',id);
	addPostToForm(myForm,'visible',visible);
	
	if(visible == 'No') {
		var answer = confirm('Are you sure you wish to permanently delete this log entry?');
		if(answer == false) {
			return;	
		}
	}
	
	myForm.target = '_top';
	myForm.action = '/site/main/updateLog/updateLogEdit.php';
	myForm.method = 'post';
	myForm.submit();
}

