
function textCounter(field,cntfield,maxlimit) {
		if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
		else
		cntfield.value = maxlimit - field.value.length;
	}
function isURL(s) {
 	var regexp = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
 		return regexp.test(s);
	}

	function insertText(element, text) {
		// Put focus on the element so IE doesn't insert the text in
		// another part of the page.
		element.focus();
		
		// IE supports document.selection.
		if (document.selection) {
			// Create a textRange object.
			var range = document.selection.createRange();
			
			// Add text to the textRange text property.
			range.text += text;
			
			// Scroll inserted text into view.
			range.scrollIntoView();
			
			return;
		}
	 
		// Find the end of the current selection. If there is not text
		// selected then selectionEnd is the location of the cursor.
		var position = element.selectionEnd;
	
		// Insert text after the end of the selection.
		var beforeText = element.value.substring(0, position);
		var afterText = element.value.substring(position,
			element.value.length
		);
		
		element.value = beforeText + text + afterText;
		
		// Select inserted text, element already has focus.
		element.setSelectionRange(position + ((text.length/2)), position + ((text.length/2)));
		
	}
	function addLink()
		{
			var url=prompt("Enter URL of Link \n Example: http://www.domain.com","")	
			if(	isURL(url)){
				insertText(document.getElementById('contents'), '{LINK}' + url + '{/LINK}')
			}else {alert ("Please enter correct URL with this format \n http://www.domain.com")}
		}
	function addImage()
		{
			var url=prompt("Enter Image Location \n Example: http://www.domain.com/myimage.jpg","")
			if(	isURL(url)){
				insertText(document.getElementById('contents'), '{IMAGE}' + url + '{/IMAGE}')
			}else {alert ("Please enter correct Image URL with this format \n http://www.domain.com/myimage.jpg")}
			
		}
	function duplicate(){
			alert("duplicate");
			var content=document.editor.contents.value
			var new_content=content.replace("{IMAGE}","<img src='")
			new_content=new_content.replace("{B}","<b>")
			new_content=new_content.replace("{/B}","</b>")
			new_content=new_content.replace("{I}","<i>")
			new_content=new_content.replace("{/I}","</i>")
			new_content=new_content.replace("{U}","<u>")
			new_content=new_content.replace("{/U}","</u>")
			new_content=new_content.replace("{/IMAGE}","'></img>")
			new_content=new_content.replace("{LINK}","<a href='")
			new_content=new_content.replace("{/LINK}","'>Link Here</a>")
			document.editor.duplicate.value=new_content
			return true;
		
		}
	
	function VerifyForm(){
		if(document.editor.contents.value==""){
			alert ("Message Content no Value!");
			return false;
		}
		if(document.editor.code.value!=document.editor.securitycode.value){
			alert ("Security Code does not match!");
			return false;
		}
	}
	function UserForm(){
		if(document.pass.oldpassword.value!=document.pass.oldpass.value){
			alert ("Password does not match to your current password!");
			return false;
		}
		if(document.pass.upassword.value==""){
			alert ("Please enter your new password!");
			return false;
		}
		
		if(document.pass.upassword.value!=document.pass.confirm.value){
			alert ("Please confirm again your new password!");
			return false;
		}
		return true;
	
	}
	function InfoForm(){
		
		var emailID=document.info.email
		//alert ("djhdsjhdj");
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please enter valid email address")
			emailID.focus()
			return false
		}
		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}
		return true;
		
		
	}
	
	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 address")
		   return false
		}

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

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

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

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

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

 		 return true					
	}
