function wordwrap( str, width, brk, cut ) {

	brk = brk || '\n';
	width = width || 75;
	cut = cut || false;
 
	if (!str) { return str; }
 
	var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\\S+?(\\s|$)');
 
	return str.match( RegExp(regex, 'g') ).join( brk );
 
}
function showPreview()
{
	//alert(document.postReply.desc.value);
	document.getElementById('preview').style.visibility = 'visible';
	document.getElementById("preview").style.height = 'auto';
	document.getElementById('subDiv').innerHTML = document.postReply.desc.value;
	
	document.getElementById('subDiv').innerHTML = wordwrap(document.postReply.desc.value,133,"<br>\n",true);
}
function hidePreview()
{
	//alert(document.postReply.desc.value);
	document.getElementById('preview').style.visibility = 'hidden';
	document.getElementById("preview").style.height = '0px';
	

}
/////Show Post
function showPreviewPost()
{
	document.getElementById('preview').style.visibility = 'visible';
	document.getElementById("preview").style.height = 'auto';
	document.getElementById('subDiv').innerHTML = document.postReply.title.value + "<br />" + document.postReply.desc.value;
	document.getElementById('divTitle').innerHTML = document.postReply.title.value;
	var str =document.postReply.desc.value;
	
	document.getElementById('subDiv').innerHTML = wordwrap(str,133,"<br>\n",true);
}
function hidePreviewPost()
{
	document.getElementById('preview').style.visibility = 'hidden';
	document.getElementById("preview").style.height = '0px';
	

}

////

function showSub(id)
{
	//alert(document.postReply.desc.value);
	if(document.getElementById(id).style.visibility == 'visible')
	{
		document.getElementById(id).style.visibility = 'hidden';
		document.getElementById(id).style.height = '0px';
	}
	else
	{
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById(id).style.height = 'auto';
	}
}


///////////////Email Validation
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

//////////////////////////
