function textCounterAdSpot() {
	var field = document.getElementById("description").value;		
	var maxlimit = 30;
	if (field.length > maxlimit) // if too long...trim it!
	{
		field = field.substring(0, maxlimit);
		document.getElementById("description").value = field;
	}		
}
//--------------------------------------- 10_03_2010------------------------------------
function textCounter() {
	var field = document.getElementById("description").value;	
	var cntfield = document.getElementById("remLen").value;
	var maxlimit = 250;
	if (field.length > maxlimit) // if too long...trim it!
	{
		field = field.substring(0, maxlimit);
		document.getElementById("description").value = field;
	}	
	else// otherwise, update 'characters left' counter
	{
		cntfield = maxlimit - field.length;//alert(cntfield);
		document.getElementById("remLen1").innerHTML = cntfield;
	}
}

function enterKeyPressed(evt, val) 
{
	  var evt = (evt) ? evt : event;
	  var charCode = (evt.which) ? evt.which : evt.keyCode;
	  if (charCode == 13) 
	  {
		  if(val=='review')
			  addReview();
	  }
}

function reseReviewForm()
{//alert("a")
	document.getElementById("name").value = '';
	document.getElementById("nameErr").className ='msgOff';
	document.getElementById("description").value = '';
	document.getElementById("descripErr").className='msgOff';
}

function addReview()
{
	var name = document.getElementById("name").value.replace(/^\s+|\s+$/g, '');
	var description = document.getElementById("description").value.replace(/^\s+|\s+$/g, '');
	var postId = document.getElementById("post").value;//alert(postId);
	if(name!="" && description!="")
	{
		document.getElementById("nameErr").className = 'msgOff';
		document.getElementById("descripErr").className ='msgOff';
		ajx=new AJAXHandler();
		ajx.setTarget('insReviewAjx.php');
		ajx.sendRequest('name='+name+'&description='+description+'&postId='+postId,'POST',10);
	}
	else
	{
		if(name == "")
			document.getElementById("nameErr").className = 'msgFieldOn';
		else
			document.getElementById("nameErr").className = 'msgOff';
		
		if(description == "")
			document.getElementById("descripErr").className = 'msgFieldOn';		
		else
			document.getElementById("descripErr").className ='msgOff';		
		
	}
}

function closeAbuseDiv(id,abusedDivId)
{
	document.getElementById(abusedDivId).innerHTML = 'Loading........';
	document.getElementById(abusedDivId).innerHTML = '';
	document.getElementById(abusedDivId).style.display = "none";
}

function showAbuse(id,totReview,abusedDivId)
{	
	for(var i=1;i<=totReview;i++)
	{		
		if(i==abusedDivId)
		{
			setOpacity(abusedDivId,1);			
			document.getElementById(i).style.display = 'block';
			document.getElementById(i).innerHTML = '<table style="height:145px; width:200px;"><tr><td style="vertical-align:middle;text-align:center;">Loading....</td></tr></table>';
		}
		else
		{
			document.getElementById(i).style.display = 'none';
			document.getElementById(i).innerHTML = '';
		}
	}
	mainId = document.getElementById("main").value;
	subId = document.getElementById("sub").value;
	postId = document.getElementById("post").value;
	
	ajx=new AJAXHandler();
	ajx.setTarget('showAbuseAjx.php');
	ajx.sendRequest('abusedDivId='+abusedDivId+'&id='+id,'POST',11,'');
}

function insAbuse(userId,abusedDivId)
{
	var id = userId;
	var name = document.getElementById("nameAbuse").value.replace(/^\s+|\s+$/g, '');
	var email = document.getElementById("emailAbuse").value.replace(/^\s+|\s+$/g, '');
	var report = document.getElementById("reportAbused").value.replace(/^\s+|\s+$/g, '');
	var validEmail =isValidEmail(email);
	//var stateChk = abusedDivId;
	if(name!="" && email!="" && validEmail && report!="")
	{
		   var serverUri = document.getElementById("serverUri").value;
	  	   var mainId = document.getElementById("main").value;
	  	   var subId = document.getElementById("sub").value;
	  	   var postId = document.getElementById("post").value;
	  	   document.getElementById("nameErr").className = 'msgOff';
		   //document.getElementById("emailErr").className = 'msgOff';
		   document.getElementById("reportErr").className = 'msgOff';	
	  	   if(validEmail)
	  	   {  
	  		 document.getElementById("reportErr").className = 'msgOff';
	  		 document.getElementById("nameErr").className = 'msgOff';
	  		 document.getElementById("emailErr").className = 'msgOff';	 
		  	  ajx=new AJAXHandler();
			  ajx.setTarget('sendMailAjx.php');
		  	  ajx.sendRequest('name='+name+'&email='+email+'&report='+report+'&serverUri='+serverUri+'&mainId='+mainId+'&subId='+subId+'&postId='+postId+'&id='+id+'&abusedDivId='+abusedDivId,'POST',12,abusedDivId);
			  document.getElementById(abusedDivId).innerHTML = "<table style='height:145px; width:200px;'><tr><td style='vertical-align:middle;text-align:center;'>Sending....</td></tr></table>";
	  	   }
	  	   else
	  	   {//alert("else1222")  
	  		 document.getElementById("emailErr").className = 'msgFieldOn';
	  	   }  	 
		
	}
	else
	{	//alert("else")  		  
		if(name=="")
			document.getElementById("nameErr").className = 'msgFieldOn';
		else
			document.getElementById("nameErr").className = 'msgOff';
		
		if(email=="")
			document.getElementById("emailErr").className = 'msgFieldOn';
		else
			document.getElementById("emailErr").className = 'msgOff';
		
		if(report=="")
			document.getElementById("reportErr").className = 'msgFieldOn';
		else
			document.getElementById("reportErr").className = 'msgOff';
		if(!validEmail)
			document.getElementById("emailErr").className = 'msgFieldOn';
		else
			document.getElementById("emailErr").className = 'msgoff';
	}
	
}

function resetAbuseDiv()
{
	document.getElementById("nameErr").className = 'msgOff';
	document.getElementById("emailErr").className = 'msgOff';
	document.getElementById("reportErr").className = 'msgOff';
	document.getElementById("nameAbuse").value = '';
	document.getElementById("emailAbuse").value = '';
	document.getElementById("reportAbused").value = '';
}

function isValidEmail(val)
{
	var emailVal = val;
	apos=emailVal.indexOf("@");
	dotpos=emailVal.lastIndexOf(".");
	if (apos<1||dotpos-apos<2 || !(emailVal.match(/^[\w\d!#$%&'*+-\/=?^`{|}~]+(\.[\w\d!#$%&'*+-\/=?^`{|}~]+)*@([a-z\d][-a-z\d]*[a-z\d]\.)*[a-z][-a-z\d]*[a-z]$/)))
	{		
		return false;
	}
	else
   	{
        return true;
   	}
}


function pop_window(url)
{
  window.open(url,'new_window','height=540,width=450,left=0,top=0');
}

function AJAXHandler()
{
	var target=null;
   var respVal=null;
       	
  	this.setTarget=function(target)
	{
		this.target=target;
	}
	
	this.createRequestObject=function(){
		
		var httpRequest=false;
		if(window.XMLHttpRequest){
			httpRequest=new XMLHttpRequest();
		}
		else if(window.ActiveXObject){
			httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else{
			alert("This page will not work as desired, lack of support from browser");
		}
		
		return httpRequest;
	}

	var xmlhttp=this.createRequestObject();
	var flag=null;
	var divId=null;
	this.sendRequest=function(paramslist,method,flagPrm,nameDiv)
	{
		params=paramslist; 	
		divId=nameDiv;
		flag=flagPrm;
				 
		if(method=='POST')
		{
			xmlhttp.open("POST",this.target,true);
		 	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        xmlhttp.setRequestHeader("Content-length", params.length);
	        xmlhttp.setRequestHeader("Connection", "close");
	        xmlhttp.onreadystatechange=this.handleResponce;
	        xmlhttp.send(params);
		}
		else if(method=='GET')
		{
			
			xmlhttp.open("GET",this.target+params,true);
			xmlhttp.onreadystatechange=this.handleResponce;
		    xmlhttp.send(null);
		}
		 		    
	}

	this.handleResponce=function()
	{
		optTitle=document.getElementById('subId');
		projectList = document.getElementById("projectsList");
		projectPages = document.getElementById("pages");
		sLinkImg = document.getElementById("sampleLinkImg");
		sLinkTxt = document.getElementById("sampleLinkTxt");
		countyIdD = document.getElementById("countyId");
		countyIdDSub = document.getElementById("countyIdSub");
		countyIdDBen = document.getElementById("beneficiaryCountyId");
		
		if(xmlhttp.readyState==4)
		{
		
		responce=xmlhttp.responseText;
		
      if(flag==1)
      {
//      	alert(responce)
        	document.getElementById("postList").innerHTML = responce;
      }
      else if(flag == 2)
      {
      	items=responce.split('<sep>')
			catList=items[0].split('<elem>')
			optTitle.options.length=0;				
			optTitle.options.length=catList.length;
	
			for(i=0;i<catList.length;i++)
			{				
			  if(catList[i])
			  {
			   	newsattr=catList[i].split('<attr>')
			   	if(newsattr[0]==null || newsattr[1]==null)
			   		continue;
			   	
			    	optTitle.options[i].value=newsattr[0];
			    	optTitle.options[i].text=newsattr[1];
			    	
			    	if(typeof selectVal != 'undefined' && optTitle.options[i].value == selectVal)
					   selIndex = i
			  }
			  else
			  {
			   	optTitle.options.length=catList.length-1;
			  }
					 		
		  }
		  if(typeof selectVal != 'undefined')
		  	optTitle.selectedIndex = selIndex
		  else
		   optTitle.selectedIndex = 0;
		   
//		   setValue('subCatVal', optTitle.options[optTitle.selectedIndex].text);
      }
      else if(flag == 3)
      {
      	projArr=responce.split('<sep>')
      	projectList.innerHTML = projArr[0]
      	projectPages.innerHTML = projArr[1]
      }
      else if(flag == 4)
      {
      	items=responce.split('<sep>')
      	showHidePaymentArea(items[0])
      	sLinkImg.href = "docs/"+items[1];
      	sLinkTxt.href = "docs/"+items[1];
      	
      }
      else if(flag == 5)
      {
      	items=responce.split('<sep>')
			catList=items[0].split('<elem>')
			optTitle.options.length=0;				
			optTitle.options.length=catList.length;
	
			for(i=0;i<catList.length;i++)
			{				
			  if(catList[i])
			  {
			   	newsattr=catList[i].split('<attr>')
			   	if(newsattr[0]==null || newsattr[1]==null)
			   		continue;
			   	
			    	optTitle.options[i].value=newsattr[0];
			    	optTitle.options[i].text=newsattr[1];
			    	
			    	if(typeof selectVal != 'undefined' && optTitle.options[i].value == selectVal)
					   selIndex = i
			  }
			  else
			  {
			   	optTitle.options.length=catList.length-1;
			  }
					 		
		  }
		  if(typeof selectVal != 'undefined' && typeof selIndex != 'undefined')
		  {
		  	if(selIndex < catList.length-1)
		  		optTitle.selectedIndex = selIndex
		  }
		  else
		   optTitle.selectedIndex = 0;
		  
//		   setValue('subCatVal', optTitle.options[optTitle.selectedIndex].text);
			toglePaymentArea(document.getElementById("subId"));
      }

      else if(flag == 6)
      {
      		items=responce.split('<sep>')
			catList=items[0].split('<elem>')
			countyIdD.options.length=0;				
			countyIdD.options.length=catList.length;
	
			for(i=0;i<catList.length;i++)
			{				
			  if(catList[i])
			  {
			   	newsattr=catList[i].split('<attr>')
			   	if(newsattr[0]==null || newsattr[1]==null)
			   		continue;
			   	
			    	countyIdD.options[i].value=newsattr[0];
			    	countyIdD.options[i].text=newsattr[1];
			    	
			    	if(typeof selectVal != 'undefined' && countyIdD.options[i].value == selectVal)
					   selIndex = i
					else
						selIndex = 0
			  }
			  else
			  {
			   	countyIdD.options.length=catList.length-1;
			  }
					 		
		  }
		  if(typeof selectVal != 'undefined')
		  	countyIdD.selectedIndex = selIndex
		  else
		   countyIdD.selectedIndex = 0;
		   
      }
      else if(flag == 7)
      {
      		items=responce.split('<sep>')
			catList=items[0].split('<elem>')
			countyIdDBen.options.length=0;				
			countyIdDBen.options.length=catList.length;
	
			for(i=0;i<catList.length;i++)
			{				
			  if(catList[i])
			  {
			   	newsattr=catList[i].split('<attr>')
			   	if(newsattr[0]==null || newsattr[1]==null)
			   		continue;
			   	
			    	countyIdDBen.options[i].value=newsattr[0];
			    	countyIdDBen.options[i].text=newsattr[1];
			    	
			    	if(typeof selectValBen != 'undefined' && countyIdDBen.options[i].value == selectValBen)
					   selIndex = i
			  }
			  else
			  {
			   	countyIdDBen.options.length=catList.length-1;
			  }
					 		
		  }
		  if(typeof selectValBen != 'undefined')
		  	countyIdDBen.selectedIndex = selIndex
		  else
		   countyIdDBen.selectedIndex = 0;
		   
      }
      else if(flag == 8)
      {
    	  sortType = responce;
    	  switch(sortType)
    	  {
	    	  case "titleAsc":
	  	  		document.getElementById("curOrder").innerHTML = "Ascending";
	  	  		document.getElementById("orderTitle").src = "images/orderTitleOn.gif";
	  	  		document.getElementById("orderLocation").src = "images/orderLocation.gif";
	  	  		document.getElementById("orderDate").src = "images/orderDate.gif";
	  	  		document.getElementById("curOrder").href = "javascript:setSortType('titleDesc')";
	  	  		document.getElementById("orderContribute").src = "images/orderContribute.gif";
	  	  		break;
	  	  	case "titleDesc":
	  	  		document.getElementById("curOrder").innerHTML = "Descending";
	  	  		document.getElementById("orderTitle").src = "images/orderTitleOn.gif";
	  	  		document.getElementById("orderLocation").src = "images/orderLocation.gif";
	  	  		document.getElementById("orderDate").src = "images/orderDate.gif";
	  	  		document.getElementById("curOrder").href = "javascript:setSortType('titleAsc')";
	  	  		document.getElementById("orderContribute").src = "images/orderContribute.gif";
	  	  		break;
    	  	case "insertDesc":
    	  		document.getElementById("curOrder").innerHTML = "Descending";
    	  		document.getElementById("orderLocation").src = "images/orderLocation.gif";
    	  		document.getElementById("orderTitle").src = "images/orderTitle.gif";
    	  		document.getElementById("orderDate").src = "images/orderDateOn.gif";
    	  		document.getElementById("curOrder").href = "javascript:setSortType('insertAsc')";
    	  		document.getElementById("orderContribute").src = "images/orderContribute.gif";
    	  		break;
    	  	case "insertAsc":
    	  		document.getElementById("curOrder").innerHTML = "Ascending";
    	  		document.getElementById("orderLocation").src = "images/orderLocation.gif";
    	  		document.getElementById("orderTitle").src = "images/orderTitle.gif";
    	  		document.getElementById("orderDate").src = "images/orderDateOn.gif";
    	  		document.getElementById("curOrder").href = "javascript:setSortType('insertDesc')";
    	  		document.getElementById("orderContribute").src = "images/orderContribute.gif";
    	  		break;
    	  	case "contributionAsc":
    	  		document.getElementById("curOrder").innerHTML = "Ascending";
    	  		document.getElementById("orderDate").src = "images/orderDate.gif";
    	  		document.getElementById("orderLocation").src = "images/orderLocation.gif";
    	  		document.getElementById("orderTitle").src = "images/orderTitle.gif";
    	  		document.getElementById("curOrder").href = "javascript:setSortType('contributionDesc')";
    	  		document.getElementById("orderContribute").src = "images/orderContributeOn.gif";
    	  		break;
    	  	case "contributionDesc":
    	  		document.getElementById("curOrder").innerHTML = "Descending";
    	  		document.getElementById("orderDate").src = "images/orderDate.gif";
    	  		document.getElementById("orderLocation").src = "images/orderLocation.gif";
    	  		document.getElementById("orderTitle").src = "images/orderTitle.gif";
    	  		document.getElementById("curOrder").href = "javascript:setSortType('contributionAsc')";
    	  		document.getElementById("orderContribute").src = "images/orderContributeOn.gif";
    	  		break;
    	  	case "locationAsc":
    	  		document.getElementById("curOrder").innerHTML = "Ascending";
    	  		document.getElementById("orderContribute").src = "images/orderContribute.gif";
    	  		document.getElementById("orderLocation").src = "images/orderLocationOn.gif";
    	  		document.getElementById("orderTitle").src = "images/orderTitle.gif";
    	  		document.getElementById("curOrder").href = "javascript:setSortType('locationDesc')";
    	  		document.getElementById("orderDate").src = "images/orderDate.gif";
    	  		break;
    	  	case "locationDesc":
    	  		document.getElementById("curOrder").innerHTML = "Descending";
    	  		document.getElementById("orderContribute").src = "images/orderContribute.gif";
    	  		document.getElementById("orderLocation").src = "images/orderLocationOn.gif";
    	  		document.getElementById("orderTitle").src = "images/orderTitle.gif";
    	  		document.getElementById("curOrder").href = "javascript:setSortType('locationAsc')";
    	  		document.getElementById("orderDate").src = "images/orderDate.gif";
    	  		break;
    	  }
    	  init();
      }
      else if(flag == 9)
      {
      		items=responce.split('<sep>')
			catList=items[0].split('<elem>')
			countyIdDSub.options.length=0;				
      		countyIdDSub.options.length=catList.length;
	
			for(i=0;i<catList.length;i++)
			{				
			  if(catList[i])
			  {
			   	newsattr=catList[i].split('<attr>')
			   	if(newsattr[0]==null || newsattr[1]==null)
			   		continue;
			   	
			   		countyIdDSub.options[i].value=newsattr[0];
			   		countyIdDSub.options[i].text=newsattr[1];
			    	
			    	if(typeof selectVal != 'undefined' && countyIdDSub.options[i].value == selectVal)
					   selIndex = i
			  }
			  else
			  {
				  countyIdDSub.options.length=catList.length-1;
			  }
					 		
		  }
		  if(typeof selectVal != 'undefined')
			  countyIdDSub.selectedIndex = selIndex
		  else
			  countyIdDSub.selectedIndex = 0;
		   
      }
      else if(flag == 10)
      {
    	  if(responce == 1)
    	  {
    		  document.getElementById("name").value = "";
    		  document.getElementById("description").value = "";
    		  document.getElementById("remLen").value = "250";
    		  
    		  setOpacity('reviewMsg',1);
    		  document.getElementById("reviewDiv").style.display = 'none';
    		  document.getElementById("reviewMsg").innerHTML = "<div class='success'>Operation successfull.</div>";    		 
			  window.setTimeout("fadeOut('reviewMsg',20,2000);", 3000);			 
			  document.getElementById("remLen1").innerHTML = 250;
			  
			  
    	  }    	  
    	  else
    	  {
    		  document.getElementById("reviewMsg").innerHTML = "<div class='unsuccess'>Error occured,please try again later.</div>";
    		  window.setTimeout("fadeOut('reviewMsg',20,2000);", 3000);
    	  }
      }
      else if(flag == 11)
      {
      	  reportId = responce.split("_");
      	  /*var ids = "abuseDiv"+reportId[1];      	 
      	  var abuseId = ids.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
      	  var report =  reportId[0];
      	  if(abuseId = abuseId)*/
      	var abuseId = reportId[1].replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
      	var report =  reportId[0];
      	  document.getElementById(abuseId).innerHTML = report;
      }
      else if(flag == 12)
      {
    	  	  reportId = responce.split("_");	      	      	 
	      	  var abuseId = reportId[1].replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
	      	  var respMail =  reportId[0].replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
	      	  //document.getElementById(abuseId).innerHTML = "<table style='height:145px; width:200px;'><tr><td style='vertical-align:middle;text-align:center;'>Sending....</td></tr></table>";
    	  if(respMail == 1)
    	  {
	    	  document.getElementById(divId).innerHTML = "<table style='height:145px; width:200px;'><tr><td style='vertical-align:middle;text-align:center;'>Report sent successfully.</td></tr></table>";	    	  
	    	  window.setTimeout("fadeOut("+divId+",20,2000);", 3000);
    		  document.getElementById(divId).style.display = 'none';
    	  }    	  
    	  else
    	  {	
    		  document.getElementById(divId).innerHTML = "<table style='height:145px; width:200px;'><tr><td style='vertical-align:middle;text-align:center;'>Report Failed.</td></tr></table>";
    		  window.setTimeout("fadeOut("+divId+",20,2000);", 3000);
    		  document.getElementById(divId).style.display = 'none';
    	  }  
      }
      else if(flag == 13)
      {
    	  ulN = document.getElementById(divId).parentNode;
    	  liN = ulN.getElementsByTagName("li");
    	  for( var i = 0; i < liN.length; i++ )
    	  {
    		  liN.item(i).className = (liN.item(i).id == divId) ? "onPage" : "";
    	  }
    	  document.getElementById("adSelectTool").innerHTML = responce;
      }
	}
	else
		{
			if(flag == 1)
			{
				document.getElementById("postList").innerHTML = '<p>Loading...</p>';
			}
			if(flag == 2)
			{
				optTitle.options.length=1;
				optTitle.options[0].text='Loading...';
			}
			if(flag == 3)
			{
				projectList.innerHTML = "<table width='410' border='0' align='center' cellpadding='2' cellspacing='0' class='projects'><tr><td>Loading...</td></tr></table>";
			}
			if(flag == 5)
			{
				optTitle.options.length=1;
				optTitle.options[0].text='Loading...';
			}
			if(flag == 6)
			{
				countyIdD.options.length=1;
				countyIdD.options[0].text='Loading...';
			}
			if(flag == 7)
			{
				countyIdDBen.options.length=1;
				countyIdDBen.options[0].text='Loading...';
			}
			if(flag == 10)
			{
				document.getElementById("reviewDiv").style.display = 'none';
				document.getElementById("reviewMsg").innerHTML = "<p>Sending...</p>";
			}
			if(flag == 12)
			{
				document.getElementById(divId).innerHTML = "<table style='height:145px; width:200px;'><tr><td style='vertical-align:middle;text-align:center;'>Sending....</td></tr></table>";
			}
			if(flag == 13)
			{
				document.getElementById("adSelectTool").innerHTML = "Loading..."
			}
		}
	
	}
	
}

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 nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}

/*
 ****************Validation begins here...*********************
 */

function validate(field, msg, elementType)
{
	with (field)
	{
		//For text or textareas...
		if(elementType=='text' || elementType=='textarea'|| elementType=='password' || elementType=='file')
		{
			if (value==null||value=="")
			{
				alert(msg);
				return false;
			}
		}
		//For drop downs...
		else if(elementType=='select-one')
		{
			if (selectedIndex==0)
			{
				alert(msg);
				return false;
			}
		}
		else if(elementType=='checkbox')
		{
			if(checkboxIsChecked == 0)
				if (checked == false)
				{
					alert(msg);
					return false;
				}
		}
		else 
		{
			return true;
		}
	}
}
//E mail validation function.
function validateEmail(field, msg)
{
	with (field)
	{
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		
		if (apos<1||dotpos-apos<2) 
		{
			alert(msg);
			value='';
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function validateConfirmation(field, msg)
{
	with (field)
	{
		if(value != document.getElementById("confirmation").value)
		{
			alert(msg);
			document.getElementById("confirmation").value='';
			document.getElementById("confirmation").focus();
			return false;
		}
		else
			return true;
	}
	
}


//----------------------------------validation-------------------------------------------
/**
 * validateForm(string form element[, string tag ids[, string flag]])
 * thisForm = Form name.
 * elementIds = Should be an element ID seperated by commas. ( Eg:'name,address' ).
 * flag = 'email' -> Validates email format.
 *		  'password' -> Validates password confirmation format.
 *		  'email+password' -> Validates email format & password confirmation.
 * Usage : validateForm(this, 'name,address') -> Validates only the 'name' & 'address'.
 *  	   validateForm(this) -> Validates all the fields.
 *		   validateForm(this,'*') -> Validates all the fields. Same as validateForm(this).
 *		   validateForm(this,'*','email+password') -> Validates email format & password confirmation.
 **/
var checkboxIsChecked = 0;
var emailFieldName = 'email';	//should give the name of the email field.
function validateForm(thisForm, elementIds, flag, needNoConfirmation, errorMsg)
{
	var alertText;
	with (thisForm)
		{
			//Checks whether the Ids were given.
			if(typeof elementIds != 'undefined' && elementIds!='*')
			{
				alertText = ( typeof(errorMsg) == 'undefined') ? 'All fields marked with º need to be complete in full.' : errorMsg;
				var tempElementIdArray = new Array();
				var tempElementsArray = new Array();
				var i;
				
				tempElementIdArray = elementIds.split(',');
				
				for(i in tempElementIdArray)
				{
					if(typeof elements[tempElementIdArray[i]] != 'undefined')
					tempElementsArray[i] = elements[tempElementIdArray[i]];
				}
				
				if(validateThis(tempElementsArray, alertText, flag , needNoConfirmation) == false)
					return false;
			}
			//Else validates all the fields.
			else
			{
				alertText='All fields need to be complete in full.';
				if(validateThis(elements, alertText, flag , needNoConfirmation) == false)
					return false;
			}
		}
}



/**
validateThis(elementObj,alertText[,Array confirm(elem1,elem2,'confirmation msg')])
last element of confirm contains the message to be displayed
**/
function validateThis(elementObj, alertText, confirm , needNoConfirmation)
{
	
	for (i=0;i<elementObj.length;i++) 
	{
		//Text field validation done here...
		if(elementObj[i].type=='text')
		{
			//Checks whether text fields are empty...
			if (validate(elementObj[i], alertText, elementObj[i].type)==false)
				{
					elementObj[i].focus();
					return false;
				}
	 			
			//E mail validation is done here...	
//			else if(elementObj[i].name == emailFieldName)
			else if(elementObj[i].name.indexOf("email")!=-1)
			{
				if(typeof confirm != 'undefined' && confirm.indexOf("email")!=-1)
					if (validateEmail(elementObj[i], "Invalid e-mail address format.", elementObj[i].type)==false)
					{
						elementObj[i].focus();
						return false;
					}
					else if(typeof needNoConfirmation == 'undefined')
					{
						if (validateConfirmation(elementObj[i], "E-mail and Confirmation and need to be identical.")==false)
						{
							return false;
						}
					}
			}
			
		}
		//Drop down validation done here...
		else if(elementObj[i].type=='select-one')
		{
			if (validate(elementObj[i], alertText, elementObj[i].type)==false)
				{
					elementObj[i].focus();
					return false;
				}
		}
		//Textarea validation done here...
		else if(elementObj[i].type=='textarea')
		{
			if (validate(elementObj[i], alertText, elementObj[i].type)==false)
			{
				elementObj[i].focus();
				return false;
			}
		}
		else if(elementObj[i].type=='password')
		{
			if (validate(elementObj[i], alertText, elementObj[i].type)==false)
			{
				elementObj[i].focus();
				return false;
			}
		}
		else if(elementObj[i].type=='checkbox')
		{
			if (validate(elementObj[i], alertText, elementObj[i].type)==false)
			{
				elementObj[i].focus();
				return false;
			}
		}
		else if(elementObj[i].type=='file')
		{
			
			if(!elementObj[i].disabled)
			if (validate(elementObj[i],alertText,elementObj[i].type)==false)
			{
				
				elementObj[i].focus();
				return false;
			}
		}
		
	}
	/*if(typeof confirm != 'undefined')
	{
		alert(confirm.length)
		for(i=0;i<(confirm.length-2);i++)
		{
			if(confirm[i]!=confirm[i+1])
			{
			lastIndex=confirm.length-1;	
			
			alert('New Password and Confirmation and need to be identical.')
			for(j=0;j<elementObj.length;j++)
			 if(elementObj[j].name==confirm[i+1])
			 {
			 elementObj[j].focus();
			 elementObj[j].value="";
			 
			 }
			
		    
			return false;
			}
			
		}
		
	}*/
		
}

// validates user input
function validChars(e, goods) {
	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();

	if (goods.indexOf(keychar) != -1)
		return true;

	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
		return true;

	return false;
}

function showConfirmation(msg)
{
	return confirm(msg);
}

function setValue(where, value)
{
	if(where == "mainCatVal")
		value = value+" : ";
	document.getElementById(where).innerHTML = value;
}

//http://www.codeproject.com/KB/ajax/Flash_user_confirmation.aspx?display=Print
function setOpacity(id, level) {
  var element = document.getElementById(id); 
  element.style.display = 'block';
  element.style.zoom = 1;
  element.style.opacity = level;
  element.style.MozOpacity = level;
  element.style.KhtmlOpacity = level;
  element.style.filter = "alpha(opacity=" + (level * 100) + ");";
}

//http://www.codeproject.com/KB/ajax/Flash_user_confirmation.aspx?display=Print
function fadeOut(id, steps, duration) {
  var fadeOutComplete;       
  for (i = 0; i <= 1; i += (1 / steps)) {
    setTimeout("setOpacity('" + id + "', "  + 
              (1 - i) + ")", i * duration);
    fadeOutComplete = i * duration;
  }
  setTimeout("hide('" + id + "')", fadeOutComplete);
}   

//http://www.codeproject.com/KB/ajax/Flash_user_confirmation.aspx?display=Print
function hide(id)
{
  document.getElementById(id).style.display = 'none';
  document.getElementById("reviewDiv").style.display = 'block';
}
