//resubmits a form after changing the offset to  the
// new desired offset
function formOffsetSubmit(offset,formName){

	document.all.offsetForForm.value=offset;

	document.getElementById(formName).submit();

}


function notesAction(obj){

intIndex=obj.selectedIndex;

noteAction=obj[intIndex].value;



switch (noteAction)
			{
			case 'move':

// if the action is move then open up the project selector
				document.all.notesActionSpan.innerHTML='<a href="javascript: show_projects(1)">Choose project to move selected notes to.</a>';
		

			break;

			case 'delete':
				document.all.notesActionSpan.innerHTML='selected notes.';

			break;
			default :

				// blank the selector
			document.all.notesActionSpan.innerHTML='';
			
			break;
			}



}



function notesActionProjectSelector(){


//actionMoveProjectId  gets the value from the project selector

}
function  selectAllNotes(){

//alert('test');
	objSelectAll=document.all.selectAll;
//objSelectAll=document.getElementById('selectAll');


isChecked=objSelectAll.checked;
	
	objNoteIdCheckbox=document.all.noteIdCheckbox;



if (objNoteIdCheckbox){
	if (objNoteIdCheckbox.length==1)
	{


	objNoteIdCheckbox.checked=isChecked;
	}

	if(objNoteIdCheckbox.length > 1 ){
//alert('hh');
			for(i=0;i<=(objNoteIdCheckbox.length-1);i++){				


				objNoteIdCheckbox[i].checked=isChecked;
					
			}

	}

}



//noteIdCheckbox

}

function doNoteId(){

	objNoteIdCheckbox=document.all.noteIdCheckbox;
if (objNoteIdCheckbox)
	{

		objNoteId=document.all.form1.noteId;
objNoteId.value='';
			if (objNoteIdCheckbox.length==1)
			{

				objNoteId.value=objNoteIdCheckbox.value;

			}else if(objNoteIdCheckbox.length > 1 ){

					for(i=0;i<=(objNoteIdCheckbox.length-1);i++){


						if (objNoteIdCheckbox[i].checked==true)
						{
							objNoteId.value=objNoteId.value  + objNoteIdCheckbox[i].value + ',';
						}
							
					}

					if (objNoteId.value.length>1)
					{objNoteId.value=objNoteId.value.substr(0,objNoteId.value.length-1);
					}

			}else
			{objNoteId.value=objNoteIdCheckbox.value;
			}


	}

	//alert(noteId.value)

}

function doAction(){


//error checking needs to go in here

// have we choosen an action/

// have we selected some notes

// have we selected a project (in the case of a move)


// then the confirmations
theAction=document.all.noteAction[document.all.noteAction.selectedIndex].value;

if(theAction=='delete'){ 

		if (!confirm ('Are you sure you want to\n delete the selected notes'))
		{return false;
		}

}
if(theAction=='move'){ 


		if(!document.all.actionProjectId.value){
			
			alert('You need to choose a project.');
			return false;
		}

			
		if (!confirm ('Are you sure you want to\n move the selected notes\nto '+document.all.actionProjectName.value))
		{return false;
		}

}

// if its all confirmed, go ahead.
document.all.doAction.value='true';
doNoteId();

document.all.form1.submit();


}
function deleteNote(){


	if(check_delete()){
		
	document.all.form2.submit();

	}

	else
		{return false;}



}
// standard are you sure dialog
function check_delete(){


	if(confirm("Are you sure?")){
		return true;
	}
	else
	{
		return false;
	}
}


function selectProject(intProjectId,projectName,myMode){

	
	if (myMode==1)
	{

		window.opener.form1.actionProjectId.value=intProjectId;
	window.opener.notesActionSpan.innerHTML='selected notes&nbsp;to '+projectName + '.<a href="javascript: show_projects(1)">change.</a>';
		;
	window.opener.form1.actionProjectName.value=projectName;
	}
	else{


	window.opener.form1.projectId.value=intProjectId;
	window.opener.projectNameSpan.innerHTML=projectName;
	window.opener.form1.projectName.value=projectName;}



self.close();


}




function show_projects(myMode){

//alert(document.all.projectId.name);

//alert(document.all.projectNameSpan.name);

//alert(document.getElementById('projectId').name);
//check that the selected value of  teh radio boxes

//doWhatWithNotes  is "moveToAnother

//  then do a popup with the names of all projects except teh one to be deleted

// choose which one and then close the window and have the name of the project 
//that the notes are being moved to appear on screen
myURL='show_projects.php';

if(myMode==1){myURL='show_projects.php?mode=1';}
msgWindow=open(myURL,'window2','dependent=yes,status=yes,titlebar=yes,resizable=yes,scrollbars=yes,width=250,height=450,screenx=500,screeny=50,top=50,left=500');
 // msgWindow.location.href = file;
    if (msgWindow.opener == null) msgWindow.opener = self;

}
function check_value(checkWhat,name){
	


	if(document.all(checkWhat).value==''){

		alert('You need to enter a ' + name);

		return false;
	}
	else
	{
		return true;
	}


}

// sets the date search range to various predifined periods on the 
// private notes search page
function setDate(){

	//var	myLen=(document.all.dateSearch.length)-1;

	var myDate=new Date();

dateSearch=document.all.dateSearch.selectedIndex;

dateSearch=document.all.dateSearch[dateSearch].value;




					switch (dateSearch)
								{
								case 'dd':
								// do nothing, as we just your the drop down dates
								disableDate(false);
								break;

								case 'nl':
								//do nothing,  but we are not using the drop downs
											
											disableDate(true);
									

								break;
								case 'w':
								// set fromMonth, fromDay, fromYear to 1 week ago, set to  to today
								disableDate(false);
								myDate=myDate.setDate(myDate.getDate()-7 );										
								
								myDate2= new Date(myDate);								
								
								myMonth=myDate2.getMonth()+1;// the months start at 0
								myYear=	myDate2.getYear() ;
								myDay=	myDate2.getDate();
							
								document.all.fromMonth.selectedIndex=myMonth-1;
								makeDaysInMonth('from')
								document.all.fromYear.selectedIndex=myYear-2008;
								document.all.fromDay.selectedIndex=myDay-1;
								ddToToday();
											




								break;
								case '2w':
									disableDate(false);
								// set fromMonth, fromDay, fromYear to 2 weeks ago, set to  to today

									myDate=myDate.setDate(myDate.getDate()-14 );										
								
								myDate2= new Date(myDate);								
								
								myMonth=myDate2.getMonth()+1;// the months start at 0
								myYear=	myDate2.getYear() ;
								myDay=	myDate2.getDate();
					



								document.all.fromMonth.selectedIndex=myMonth-1;

								makeDaysInMonth('from')
								document.all.fromYear.selectedIndex=myYear-2008;
								document.all.fromDay.selectedIndex=myDay-1;
								ddToToday();
								break;

								case 'm':
									disableDate(false);
								// set fromMonth, fromDay, fromYear to 1 month ago, set to  to today

									myDate=myDate.setMonth(myDate.getMonth()-1 );										
								
								myDate2= new Date(myDate);								
								
								myMonth=myDate2.getMonth()+1;// the months start at 0
								makeDaysInMonth('from')
								myYear=	myDate2.getYear() ;
								myDay=	myDate2.getDate();
							
								document.all.fromMonth.selectedIndex=myMonth-1;
								document.all.fromYear.selectedIndex=myYear-2008;
								document.all.fromDay.selectedIndex=myDay-1;

								ddToToday();
								break;
								}
				

	
		
	


}

function disableDate(disableIt){
/*
document.all.fromMonth.disabled=disableIt;
									document.all.fromDay.disabled=disableIt;
									document.all.fromYear.disabled=disableIt;
									document.all.toMonth.disabled=disableIt;
									document.all.toDay.disabled=disableIt;
									document.all.toYear.disabled=disableIt;

*/
}


function ddToYesterDay(){

	var myDate=new Date();
				myDate=myDate.setDate(myDate.getDate()-1 );										
								
				myDate2= new Date(myDate);								
								
				myMonth=myDate2.getMonth()+1;// the months start at 0
				myYear=	myDate2.getYear() ;
				myDay=	myDate2.getDate();
							
				document.all.fromMonth.selectedIndex=myMonth-1;
				document.all.fromYear.selectedIndex=myYear-2008;
				document.all.fromDay.selectedIndex=myDay-1;

}
function ddToToday(){


	var myDate=new Date();		
							
		myMonth=myDate.getMonth()+1;// the months start at 0
		myYear=	myDate.getYear() ;
		myDay=	myDate.getDate();
							
		document.all.toMonth.selectedIndex=myMonth-1;
		document.all.toYear.selectedIndex=myYear-2008;
		document.all.toDay.selectedIndex=myDay-1;
		
}


// basic validation on the account creation and change details pages
function check_pass(){

	var username=document.all('sUsername');	
	var pass=document.all('sPassword');
		var pass_confirm=document.all('sPasswordConfirm');

	var email=document.all('sEmail');

	if(pass.value.length<=4  ||username.value.length<=4){

			document.all('passwordErrors').innerHTML='<FONT color="RED"><B>Username and Password must be 5 or more letters.</B></FONT>';
			return false;
		}
	if(email.value.length==0){

		document.all('passwordErrors').innerHTML='<FONT color="RED"><B>You Have not filled in your Email address.</B></FONT>';
		return false;
		}




		if (email.value.indexOf('.')==-1){
					
			document.all('passwordErrors').innerHTML='<FONT color="RED"><B>Your email address does not appear to be correct.</B></FONT>';	
		return false;		
				}

		if (email.value.indexOf('@')==-1){
					
			document.all('passwordErrors').innerHTML='<FONT color="RED"><B>Your email address does not appear to be correct.</B></FONT>';	
		return false;		
				}



		if( pass.value==pass_confirm.value){
			
			document.all('passwordErrors').innerHTML='';
			return true;
			}
		else{

			document.all('passwordErrors').innerHTML='<FONT color="RED"><B>Password and Confirm do not match.</B></FONT>';
			pass_confirm.value='';

			return false;
		}	

	
}





function getDaysInMonth(month,year)  {

	var days;
	if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)  days=31;
	else if (month==4 || month==6 || month==9 || month==11) days=30;
	else if (month==2)  {
	if (isLeapYear(year)) { days=29; }
	else { days=28; }
	}
	return (days);
}



function isLeapYear (Year) {
	if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
		return (true);
		}
	else 
		
	{ return (false); }
}



function makeDaysInMonth(what){



	var month = document.getElementById(what+'Month').selectedIndex +1;
	var year = document.getElementById(what+'Year').selectedIndex +2008;

	var days = getDaysInMonth(month,year)
	//alert(days);

	var currentDays= document.getElementById(what+'Day').length;


	if (days>currentDays)
	{// add some extra rows

			for (i=(currentDays);i<=days ;i++ )
			{

				document.getElementById(what+'Day').options[i-1]=new Option(i,i);


			}

	}


	if (days<currentDays)
	{// loose some rows

			for (i=(currentDays-1);i>=days  ;i-- )
			{
				document.getElementById(what+'Day').options[i]=null;
			}
	}




}



function tag_search(tag){


document.all.form2.searchVars.value=tag;
document.all.form2.submit();

}

function moreOrLess(divName){

var text='';
var textlink='more...';


if(document.all(divName).innerHTML==''){

//background-color: #CCCCCC; 

switch (divName)
			{
			case 'divOne':

			text='<B>Public Notes.</B><P>'
			+'You can use public notes ot make comment about any web page, on the page itself. '
			+'These can be for your own use,  to highlight good, bad or interesting web pages to other pagenotes users,'
			+'and to enter into online discussions with other pagenotes users.'
			+'pageNotes is unmodified, which means you can leave comments on a web page that the website owners have no control over,'
			+'be honest with your comments without fear of censorship.'
			+'&nbsp;&nbsp;All users can see a public note.<P>'
			+'<B>Private Notes.</B><P>'
			+'Private notes are notes that you make on a website that only you can see.'
			+'These can be used as a bookmarking system or for your own research.'
			+'Only the author of a private note can read it.<P>'
			+'Making extensive notes about web pages you visit,  '
			+'good for when you need to sort information when researching a subject.<p>'
			+'You can also use pagenotes for Web based bookmarking, again these can be private or public.<P>'
			+'<b>Projects</B> -  these are an extension of private notes. '
			+'Projects allows you to organise your private notes to make them easier to use.'
			+'';

			break;

			case 'divTags':

			text='<B>What are Tags.</B><P>Tags are Keywords that are used to describe the information on a web page.'
			+'<BR>You can use these keywords to search or browser for other similar pages or web content.'
			+'<P>You may want to check out this <a href="http://en.wikipedia.org/wiki/Tag_(metadata)" target="_blank">Wikipedia entry</a> for more infomation.';

			break;

			}
			textlink='less...';

text='<table class="moreOrLess"><tr><td>' + text + '</td></tr></table>' ;
}





document.all(divName+'Link').innerHTML=textlink;	
document.all(divName).innerHTML=text;


}

function adVars(obj){



obj.action=obj.action + '?' + obj.searchVars.value;




}


