// JavaScript Document
function createRequestObject()
{
	//alert("welcome");
	var request_o;
	var browser = navigator.appName;

	if (browser == "Microsoft Internet Explorer")
	{
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		request_o = new XMLHttpRequest();
	}
	return request_o;

}	//	End of createRequestObject()

var http = createRequestObject();

function checkchar(mystr,invalidChars1)
{
	
	for (i=0; i<invalidChars1.length; i++) // does it contain any invalid characters?
		{
			badChar1 = invalidChars1.charAt(i)
			if (mystr.indexOf(badChar1,0) > -1) 
				{
					return false;
				}
		}

return true;
} 

function LTrim( value ) 
{
 
 var re = /\s*((\S+\s*)*)/;
 return value.replace(re, "$1");
 
}

// Removes ending whitespaces
function RTrim( value ) 
{
 
 var re = /((\s*\S+)*)\s*/;
 return value.replace(re, "$1");
 
}

// Removes leading and ending whitespaces
function trim( value ) 
{
 
 return LTrim(RTrim(value));
 
}
function checkEmail( emailAddress )
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddress))
	{
		return true;
	}
		//alert("Invalid E-mail Address! Please re-enter.");
		return false;
}


function updateCommentStatus(cid, divid, status, pgType)
{	
	if(cid != "" && cid != 0)
	{
		http.open('POST','http://www.power2thepets.ie/ul/pets_profiles/ajax_request.php?option=upd_cmt_status');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = update_updateCommentStatus;
		http.send('cid='+cid+'&stdiv='+divid+'&status='+status+'&pgType='+pgType);
	}
}// closing updateCommentStatus
function update_updateCommentStatus()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		//alert(response);
		var results = response;		
		if(results.indexOf('failed') != 0 )
		{
			var tokens = results.split("%$%");
			if(tokens[2] == 1)
			{			
				document.getElementById(tokens[1]).innerHTML = '<a href="javascript:updateCommentStatus(\''+tokens[0]+'\',\''+tokens[1]+'\' ,\''+tokens[2]+'\')">De-Activate</a><span style="padding-left:3px; color:#009966;">Comments have been activated<span>';				
			}
			else if(tokens[2] == 0)
			{
				document.getElementById(tokens[1]).innerHTML = '<a href="javascript:updateCommentStatus(\''+tokens[0]+'\',\''+tokens[1]+'\' ,\''+tokens[2]+'\')">Activate</a><span style="padding-left:5px; color:#009966;">Comments have been de-activated<span>';
			}
		
		}
		else
		{
			alert("Commens status could not be updated.");
		}
	}	
}// closing update_updateCommentStatus




