function writeDate() 
{
	var monthNames = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var dayNames = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var now = new Date();
	var amPm = (now.getHours() < 12) ? "am" : "pm";
	var hour = (now.getHours() > 12) ? (now.getHours() - 12) : (hour == 0) ? "12" : now.getHours();
	var min = (now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes());
	document.write (now.getDate()+" - "+monthNames[now.getMonth()] + " - " +now.getYear() );
}
function checkLogin() {
	document.forms[0].username.value = trimSpaces(document.forms[0].username.value);
	if(document.forms[0].username.value.length <= 0) {
		alert("Please enter the username");
		document.forms[0].username.focus();
		return false;
	}
	document.forms[0].password.value = trimSpaces(document.forms[0].password.value);
	if(document.forms[0].password.value.length <= 0) {
		alert("Please enter password");
		document.forms[0].password.focus();
		return false;
	}
}
function checkPassword() {
	document.forms[0].password.value = trimSpaces(document.forms[0].password.value);
	if(document.forms[0].password.value.length <= 0) {
		alert("Please enter the current password");
		document.forms[0].password.focus();
		return false;
	}
	document.forms[0].newPassword.value = trimSpaces(document.forms[0].newPassword.value);
	if(document.forms[0].newPassword.value.length <= 0) {
		alert("Please enter the new password");
		document.forms[0].newPassword.focus();
		return false;
	}
	document.forms[0].retypePassword.value = trimSpaces(document.forms[0].retypePassword.value);
	if(document.forms[0].newPassword.value != document.forms[0].retypePassword.value) {
		alert("Passwords does not match");
		document.forms[0].retypePassword.focus();
		return false;
	}
}
function checkPhotos(frmType) {
	category = trimSpaces(document.forms[0].category.value);
	caption = trimSpaces(document.forms[0].caption.value);
	icon = trimSpaces(document.forms[0].icon.value);
	photograph = trimSpaces(document.forms[0].photograph.value);
	description = trimSpaces(document.forms[0].description.value);
	
	if(category.length <= 0) {
		alert("Plese select a category");
		document.forms[0].category.focus();
		return false;
	}
	if(caption.length <= 0) {
		alert("Plese add a caption");
		document.forms[0].caption.focus();
		return false;
	}
	if(frmType != "modify") {
		if(icon.length <= 0) {
			alert("Plese select an icon image");
			document.forms[0].icon.focus();
			return false;
		}
		if(photograph.length <= 0) {
			alert("Plese select a photograph");
			document.forms[0].photograph.focus();
			return false;
		}
	}
	document.forms[0].frmAction.value = "update";
}
function showPhotoCategory(linkid) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 450;
	winHeight = 400;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	window.open("managePhotoCategory.php?linkid=" + linkid,"photoCategory","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
function updatePhotoCategory(frmAction) {
	dataAvailable = document.forms[0].dataAvailable.value;
	
	anyContents = false;
	itemLength = document.forms[0].elements["photoCategorynew[]"].length;
	for(newItems = 0; newItems < itemLength; newItems ++) {
		itemValue = trimSpaces(document.forms[0].elements["photoCategorynew[]"][newItems].value);
		if(itemValue.length > 0) {
			anyContents = true;
		}
	}
	
	if(dataAvailable == 1) {
		itemLength = document.forms[0].elements["photoCategory[]"].length;
		if(itemLength > 0) {
			for(newItems = 0; newItems < itemLength; newItems ++) {
				itemValue = trimSpaces(document.forms[0].elements["photoCategory[]"][newItems].value);
				if(itemValue.length > 0) {
					anyContents = true;
				}
			}
		}
		else {
			itemValue = trimSpaces(document.forms[0].elements["photoCategory[]"].value);
			if(itemValue.length > 0) {
				anyContents = true;
			}
		}
	}
	
	if(!anyContents) {
		alert("Please enter at least one category");
		return;
	}
	
	if(frmAction == "delete") {
		anySelected = false;
		itemLength = document.forms[0].elements["photoCategoryid[]"].length;
		if(itemLength > 0) {
			for(newItems = 0; newItems < itemLength; newItems ++) {
				if(document.forms[0].elements["photoCategoryid[]"][newItems].checked) {
					anySelected = true;
				}
			}
		}
		else {
			if(document.forms[0].elements["photoCategoryid[]"].checked) {
				anySelected = true;
			}
		}
		if(anySelected) {
			if(!confirm("Do you really want to delete the selected categories and all photos in that category?")) {
				return;
			}
		}
		else {
			alert("Nothing selected for deletion");
			return;
		}
	}

	document.forms[0].frmAction.value = frmAction;
	document.forms[0].submit();
}
function showIcon(iconUrl) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 300;
	winHeight = 300;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	window.open("showIcon.php?iconUrl=" + iconUrl,"iconURL","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=0,resizable=0");
}
function showPhoto(photoUrl) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	window.open("showIcon.php?iconUrl=" + photoUrl,"photoURL","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
function removePhoto(photoUrl, photoField) {
	if(photoUrl.length > 0) {
		if(confirm("Do you really want to delete this photo?")) {
			document.forms[0].frmAction.value = "removePhoto";
			document.forms[0].photoURL.value = photoUrl;
			document.forms[0].photoField.value = photoField;
			document.forms[0].submit();
		}
		else {
			return;
		}
	}
}
function checkPhotoModify(frmAction) {
	if(frmAction == "remove") {
		anySelected = false;
		itemLength = document.forms[0].elements["galleryid[]"].length;
		if(itemLength > 0) {
			for(photos = 0; photos < itemLength; photos ++) {
				if(document.forms[0].elements["galleryid[]"][photos].checked) {
					anySelected = true;
				}
			}
		}
		else {
			if(document.forms[0].elements["galleryid[]"].checked) {
				anySelected = true;
			}
		}
		if(anySelected) {
			if(!confirm("Do you really want to delete the selected photos?")) {
				return false;
			}
		}
		else {
			alert("Nothing selected for deletion");
			return false;
		}
	}
}
function closeWindow() {
	parent.window.opener.window.focus();
	parent.window.close();
}


function showPhotos(lid) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 550;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	window.open("showPhotos.php?lid=" +lid,"Photos","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
function selectAllSubscribers(frmObject) {
	if(frmObject.checked) {
		itemCount = document.forms[0].elements["subscriberid[]"].length;
		if(itemCount > 0) {
			for(ids = 0; ids < itemCount; ids ++) {
				document.forms[0].elements["subscriberid[]"][ids].checked = true;
			}
		}
		else {
			document.forms[0].elements["subscriberid[]"].checked = true;
		}
	}
	return;
}

function chkUser()
{
	user_name = trimSpaces(document.forms[0].userid.value);
	password = trimSpaces(document.forms[0].password.value);
	cpassword = trimSpaces(document.forms[0].cpassword.value);
	if(user_name == "")
	{
		alert("Please enter user name");
		document.forms[0].userid.focus();
		return false;
	}
	if(password == "")
	{
		alert("Please enter password");
		document.forms[0].password.focus();
		return false;
	}
	if(cpassword != password)
	{
		alert("The passwords are not matching");
		document.forms[0].cpassword.select();
		return false;
	}
	
	document.forms[0].frmAction.value="Update";
}

function checkDelete(frmElement,toDo) 
{
	if(toDo == "remove")
	{
		rowSelected = false;
		if(document.forms[0].elements[frmElement].length > 0) 
		{
			for(itemCount = 0; itemCount < document.forms[0].elements[frmElement].length; itemCount++) 
			{
				if(document.forms[0].elements[frmElement][itemCount].checked) 
				{
					rowSelected = true;
				}
			}
		}
		else 
		{
			if(document.forms[0].elements[frmElement].checked)
			{
					rowSelected = true;
			}
		}
		if(!rowSelected) 
		{
			alert("No item selected for deletion");
			return false;
		}
		else 
		{
			if(!confirm("Do you really want to delete these item(s)?")) 
			{
				return false;
			}
		}
		
		document.forms[0].frmAction.value = "Delete";
		return true;
	}
}

function deleteItem(fldName){
	if(ChkBoxSelected(fldName)){
		if(confirm("Are you sure you want to delete the selected item(s)?")){
			document.forms[0].frmAction.value = "delete";
			document.forms[0].submit();
			return true;
		}else{
			return false;
		}
	 }else{
		 return false;
	 }
}
function ChkBoxSelected(fldName){
	var elementLength = 0;
	var totalElements = 0;

	totalElements = document.forms[0].elements.length;var p="";
	//alert(totalElements);
	for(i = 0; i < totalElements; i++){	
		if(document.forms[0].elements[i].name == fldName){
			if(document.forms[0].elements[i].checked != 0){
				p += document.forms[0].elements[i].value + ",";   	
				elementLength++;
			}
		}			
	 }
	document.forms[0].id.value = p;
	if(elementLength <= 0){
		alert("Please select at least one checkBox.");
		return false;
	}
	return true;		
}
