// JavaScript Document
function storeState()
{
	var txt="";
//	try{
	if (document.getElementById("idemailcontent")!= null)
		if (document.getElementById("idemailcontent").value!="")
			document.getElementById("idauxemailcontent").value=document.getElementById("idemailcontent").value;
	if (document.getElementById("idemailsubject")!= null)
		if ((document.getElementById("idemailsubject").value!=""))
			document.getElementById("idauxemailsubject").value=document.getElementById("idemailsubject").value;	
//	}
/*	catch(err){
		txt = "Error in function storeState() with description:";
		alert(txt);
	}*/
	return true;
}

function setAction(action)
{
	var txt="";
	try{
		document.getElementById('email').action = action;
	}catch(err){
		txt = "Error in function setAction() with description:" . err.description;
		alert(txt);
		}
	return true;
}

function init() {
 try{
	var elemId = "idemailcontent";
 	var caretPos = '0';
 	var elem = document.getElementById(elemId);
	var txt = "";
    if(elem != null) {
        if(elem.createTextRange) {
           		var range = elem.createTextRange();
	            range.move('character', caretPos);
    	        range.select();
        		}
        else {
            if(elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            	}
            else
                elem.focus();
        	}
    	}
	else
	{
		txt="";
	}
	}catch(err){
		txt = "Error in function setCaretPosition() with description:" . err.description;
		alert(txt);	
	}
}


function resetea()
{

 try{
	var txt="";
	document.getElementById('idemailcontent').value='';
	document.getElementById('idemailsubject').value='';
	}catch(err){
		txt = "Error in function setCaretPosition() with description:" . err.description;
		alert(txt);	
	}
	
}

function ismaxlength(obj){
try{
	var txt="";	
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength);
	}catch(err){
		txt = "Error in function ismaxlength() with description:" . err.description;
		alert(txt);	
}
}

function echeck(str,$alert) {

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

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert($alert)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert($alert)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert($alert)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert($alert)
		    return false
		 }

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

 		 return true					
	}

function ValidateForm($alert1, $alert2){
	var emailID=document.getElementById('idemailsender');
	var ret;
	ret = true;
	if ((emailID.value==null)||(emailID.value=="")){
		alert($alert1);
		emailID.focus();
		ret = false;
	}
	else if (echeck(emailID.value,$alert2)==false){
		emailID.value="";
		emailID.focus();
		ret = false;
	}
	return ret;
 }
