﻿// JScript File
function emailValidation()
{

var fromEmail = document.getElementById("txtFromEmail");
var toEmail = document.getElementById("txtTo");

            
       
             if(fromEmail.value == "")
		    {
		        alert("Please Enter Your Valid Email ID and Continue");
			    fromEmail.select();
			    return false;
		    }
             if (isEmail(fromEmail.value)==false)
		    {
			    alert("Please Enter Your Valid Email ID and Continue");
			    fromEmail.select();
			    return false;
		    }
		     if(toEmail.value == "")
		    {
		        alert("Please Enter Friend's Valid Email ID and Continue");
			    toEmail.select();
			    return false;
		    }
		    
		    if (isEmail(toEmail.value)==false)
		    {
			    alert("Please Enter Friend's Valid Email ID and Continue");
			    toEmail.select();
			    return false;
		    }
		    
		    
		
		    SendMail(toEmail.value,document.getElementById('txtComments').value, fromEmail.value,document.getElementById('ctl00_hid_FileId').value);
}


function sendmailonet()
{

    var id = document.getElementById('ctl00$hid_FileId').value;
    document.getElementById('ctl00_postbackreason').value = "Send Mail";
    
    var sendData =  document.getElementById('txtTo').value + "," + document.getElementById('txtFromEmail').value  + "," +"\n " +  document.getElementById('txtComments').value  + "," + id;
    + id;
    
    
    CallServer(sendData);
   
    
}


//Function to check Email valiadtion starts here
//Starts here
function isEmail (ls_str)
{   if (isEmpty(ls_str)) 
       if (isEmail.arguments.length == 1) return "Invalid Email ID!";
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(ls_str)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var li_Cnt = 1;
    var sLength = ls_str.length;

    // look for @
    while ((li_Cnt < sLength) && (ls_str.charAt(li_Cnt) != "@"))
    { li_Cnt++
    }

    if ((li_Cnt >= sLength) || (ls_str.charAt(li_Cnt) != "@")) return false;
    else li_Cnt += 2;

    // look for .
    while ((li_Cnt < sLength) && (ls_str.charAt(li_Cnt) != "."))
    { li_Cnt++
    }

    // there must be at least one character after the .
    if ((li_Cnt >= sLength - 1) || (ls_str.charAt(li_Cnt) != ".")) return false;
    else return true;
}
function isEmpty(ls_str)
{   
    return ((ls_str == null) || (ls_str.length == 0))
}


// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";

/****************************************************************/

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (ls_str)

{   var li_cnt; 

    // Is ls_str empty?
    if (isEmpty(ls_str)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (li_cnt = 0; li_cnt < ls_str.length; li_cnt++)
    {   
	// Check that current character isn't whitespace.
	var ls_chr = ls_str.charAt(li_cnt);

	if (whitespace.indexOf(ls_chr) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


 function ReceiveServerData(result, context)
    {
       
       if(context == "Send Mail")
        {
            alert(result);
        }
        
    }
    
    