
function onMouseChangeColor(event, highlightcolor, ajaxaction, ajaxdiv, timeout)
{		
	// source is element which was selected b4
	source=document.getElementById('row'+readCookie('id2')); 		
	// change the colour back b4 change actual object
	if(source)	
		source.style.backgroundColor='#D0D0D0';	
	// change colour of the selected row
	changeto(event, highlightcolor);	
	// write the ID to cookie
	createCookie('id2', readCookie('id1'));			
	// call ajax and replace detail div		
	ajax('ajax.php?'+ajaxaction+'='+readCookie('id1'), ajaxdiv, '', timeout);
}

function changeColorOver(row_id)
{	
	// if row not equals to selected ID then
	if ( row_id!=readCookie('id2') )
	{
		source=document.getElementById('row'+row_id);
		
		if(source)	
			source.style.backgroundColor='#E0FFFF';	
	}
}

function changeColorOut(row_id)
{	
	// if row not equals to selected ID then
	if ( row_id!=readCookie('id1') )
	{
		source=document.getElementById('row'+row_id);
		
		if(source)	
			source.style.backgroundColor='#D0D0D0';	
	}
}

function Update_Record(record_id, form_name)
{
	if(ShowAjax == 1)
	{		
		switch (form_name)
		{
			case 'amemberdetails':
				// Username is required field
				if(document.amemberdetails.username.value=="")
					alert('Username is required field!');	
				// Check empty spaces
				else if(trimAll(document.amemberdetails.username.value)=="")
					alert('Username is required field! Check empty spaces!');
				// Email is required field
				else if(document.amemberdetails.email.value=="")
					alert('Email is required field!');	
				// Check empty spaces
				else if(trimAll(document.amemberdetails.email.value)=="")
					alert('Email is required field! Check empty spaces!');
				else
				{				
					// Check if username doesn't exists in db
					if(record_id==0)
						ajax('ajax.php?check_username='+trimAll(document.getElementById("username").value),'check_username','check_username', 900);			
					else				
						ajax('ajax.php?check_username='+trimAll(document.getElementById("username").value)+'&member_id='+record_id,'check_username','check_username', 900);
				}
				break;			
			case 'alinkdetail':
				// Username is required field
				if(document.alinkdetail.link.value=="")
					alert('Link is required field!');	
				// Check empty spaces
				else if(trimAll(document.alinkdetail.link.value)=="")
					alert('Link is required field! Check empty spaces!');
				else
					document.alinkdetail.submit()
				break;
			case 'anoticeboarddetail':
			case 'noticeboarddetail':			
				// Username is required field
				if(document.getElementById('notice').value=="")
					alert('Notice is required field!');	
				// Check empty spaces
				else if(trimAll(document.getElementById('notice').value)=="")
					alert('Notice is required field! Check empty spaces!');
				else				{						
					if(form_name=='anoticeboarddetail')				
						document.anoticeboarddetail.submit()
					else
						document.noticeboarddetail.submit()
				}
				break;
			case 'askilldetail':
				// Username is required field
				if(document.askilldetail.display.value=="")
					alert('Display is required field!');	
				// Check empty spaces
				else if(trimAll(document.askilldetail.display.value)=="")
					alert('Display is required field! Check empty spaces!');
				else
					document.askilldetail.submit()
				break;
			case 'apaymentdetail':
				// Username is required field
				if(document.apaymentdetail.payment_date.value=="")
					alert('Payment date is required field!');	
				// Check empty spaces
				else if(trimAll(document.apaymentdetail.payment_date.value)=="")
					alert('Payment Date is required field! Check empty spaces!');
				else if(document.apaymentdetail.payment_amount.value<=0)
					alert('Amount must be greater than 0!');	
				else
					document.apaymentdetail.submit()
				break;
			case 'apoptiondetail':
				// Username is required field
				if(document.apoptiondetail.name.value=="")
					alert('Description is required field!');	
				// Check empty spaces
				else if(trimAll(document.apoptiondetail.name.value)=="")
					alert('Description is required field! Check empty spaces!');
				else
					document.apoptiondetail.submit()
				break;
		}
	}
}

function Delete_Record(delUrl)
{		
	if (confirm("Are you sure you want to delete this record?"))  
    		document.location = delUrl;
}

function Delete_Skill(member_id)
{		
	if (confirm("Are you sure you want to delete this record?"))  
    		ajax('ajax.php?del_skill_member_id='+member_id, 'amemberdetail', '', 900);
}

function Delete_email_list(member_id)
{		
	if (confirm("Are you sure you want to delete this record?")) 
	{		
		newsletter_id=document.getElementById('newsletter_ajax_id').value;		
    		ajax('ajax.php?del_email_member_id='+member_id+'&newsletter_id='+newsletter_id, 'emaildiv', '', 900);
    	}
}

function New_Record(a_id,form_name)
{
	if(ShowAjax == 1)
	{	
		// source is element which was selected b4
		source=document.getElementById('row'+readCookie('id2')); 		
		// change the colour back b4 change actual object
		if(source)	
			source.style.backgroundColor='#D0D0D0';	
		ajax('ajax.php?'+a_id+'=0',form_name,'',900);
	}
}

function Cancel_New_Record(a_id,form_name)
{
	if(ShowAjax == 1)
	{
		// source is element which was selected b4
		source=document.getElementById('row'+readCookie('id1')); 		
		// change the colour back b4 change actual object
		if(source)
		{	
			source.style.backgroundColor='#9999FF';	
			// write the ID to cookie
			createCookie('id2', readCookie('id1'));			
			// call ajax and replace detail div	
			ajax('ajax.php?'+a_id+'='+readCookie('id1'),form_name,'',900);		
		}
	}
}

function Member_Skills(a_id,m_id,form_name)
{
	if(ShowAjax == 1)
	{	
		// source is element which was selected b4
		source=document.getElementById('row'+readCookie('id2')); 		
		// change the colour back b4 change actual object
		if(source)	
			source.style.backgroundColor='#D0D0D0';	
		ajax('ajax.php?'+a_id+'='+m_id,form_name,'',900);
	}
}

function New_Record_pay(a_id,form_name,m_id)
{
	if(ShowAjax == 1)
	{	
		// source is element which was selected b4
		source=document.getElementById('row'+readCookie('id2')); 		
		// change the colour back b4 change actual object
		if(source)	
			source.style.backgroundColor='#D0D0D0';	
		ajax('ajax.php?'+a_id+'=0&member_id='+m_id,form_name,'',900);
	}
}

/***********************************************
* Highlight Table Cells Script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Specify highlight behavior. "TD" to highlight table cells, "TR" to highlight the entire row:
var highlightbehavior="TR"

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor)
{
	source=ie? event.srcElement : e.target	
	if (source.tagName=="TABLE")
		return
	while(source.tagName!=highlightbehavior && source.tagName!="HTML")
		source=ns6? source.parentNode : source.parentElement
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
		source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave)
{ //check if slave is contained by master
		while (slave.parentNode)
		if ((slave = slave.parentNode) == master)
			return true;
		return false;
}

function changeback(e,originalcolor)
{
	if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
		return
	else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
		return
	if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
		source.style.backgroundColor=originalcolor
}

function createCookie(name, value, days)
{
	if (days)
	{
		var date = new Date();
    		date.setTime(date.getTime()+(days*24*60*60*1000));
    		var expires = "; expires="+date.toGMTString();
	}
  	else
  		var expires = "";
  		
  	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for(var i=0; i < ca.length; i++)
	{
		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
  	return null;
}

function eraseCookie(name)
{
	createCookie(name, "", -1);
}

function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}