﻿// JScript File

var UserID="";
var PageLink="";

function ShowEmailFriendModalPopup(PageUrl) 
{ 
    var modal = $find(ModalPopupEmailFriendID); 
    modal.show();
    PageLink=PageUrl;
    invokeXML(handlerURL+"xml/GetLoginEmail.ashx", EmailFriend_GetLoginXml);
    void(0);
    
}
function EmailFriend_GetLoginXml(xml)
{
    var fieldNodes = xml.getElementsByTagName("StartChecking");
	for(var i = 0; i < fieldNodes.length; i++)
	{
		var valueNodes = fieldNodes[i].childNodes;
		try
		{
		    for(var j = 0; j < valueNodes.length; j++)
		    {
			    var node = valueNodes[j];
			    UserID=node.getAttribute("UserName");
		    }
		}
		catch(e)
		{
		}
	}
    document.getElementById(txtfromemailID).value=UserID;
}
function HideEmailFriendModalPopup() 
{ 
    var modal = $find(ModalPopupEmailFriendID); 
    modal.hide();     
    document.getElementById(tblEmailFriend).style.display='';
    document.getElementById(tblEmailFriendConfirmMessage).style.display='none';
    void(0);
}
function CloseEmailFriendWindow()
{
    HideEmailFriendModalPopup();
}
function SendMail()
{
    //alert(handlerURL);
    var fr='',e1='',e2='',e3='',e4='',e5='',e6='';
    if(document.getElementById(txtfromemailID).value=='')
    {
        document.getElementById(tblEmailFriend).style.display='';
        document.getElementById(tblEmailFriendConfirmMessage).style.display='none';
        alert("Please Enter Your Email");
        return false;
    }
    else
    {
        if(emailcheck(document.getElementById(txtfromemailID).value))
        {
            fr = document.getElementById(txtfromemailID).value;
        }
        else
        {
            alert("Your email is invalid.");
            return false;
        }
    }
    var em="";
    if(document.getElementById(txte1ID).value != '')
    {
        em="1";
        if(emailcheck(document.getElementById(txte1ID).value))
        {
            e1=document.getElementById(txte1ID).value;
        }
        else
        {
            alert("Please enter correct email 1.");
            return false;
        }
    }
    if(document.getElementById(txte2ID).value != '')
    {
        em="1";
        if(emailcheck(document.getElementById(txte2ID).value))
        {
            e2=document.getElementById(txte2ID).value;
        }
        else
        {
            alert("Please enter correct email 2.");
            return false;
        }
    }
    if(document.getElementById(txte3ID).value != '')
    {
        em="1";
        if(emailcheck(document.getElementById(txte3ID).value))
        {
            e3=document.getElementById(txte3ID).value;
        }
        else
        {
            alert("Please enter correct email 3.");
            return false;
        }
    }
    if(document.getElementById(txte4ID).value != '')
    {
        em="1";
        if(emailcheck(document.getElementById(txte4ID).value))
        {
            e4=document.getElementById(txte4ID).value;
        }
        else
        {
            alert("Please enter correct email 4.");
            return false;
        }
    }
    if(document.getElementById(txte5ID).value != '')
    {
        em="1";
        if(emailcheck(document.getElementById(txte5ID).value))
        {
            e5=document.getElementById(txte5ID).value;
        }
        else
        {
            alert("Please enter correct email 5.");
            return false;
        }
    }
    if(document.getElementById(txte6ID).value != '')
    {
        em="1";
        if(emailcheck(document.getElementById(txte6ID).value))
        {
            e6=document.getElementById(txte6ID).value;
        }
        else
        {
            alert("Please Enter correct Email 6.");
            return false;
        }
    }
   
    if(em == '')
    {
        alert("Please enter atleast one of your friends email.");
        return false;
    }
    invokeXML(handlerURL+"xml/SendFriendEmail.ashx?PageUrl="+PageLink+"&frid="+fr+"&e1=" + e1+"&e2=" + e2+"&e3=" + e3+"&e4=" + e4+"&e5=" + e5+"&e6=" + e6, SendFriendEmail);
    document.getElementById(tblEmailFriend).style.display='none';
    document.getElementById(tblEmailFriendConfirmMessage).style.display='';
    document.getElementById(txte1ID).value='';
    document.getElementById(txte2ID).value='';
    document.getElementById(txte3ID).value='';
    document.getElementById(txte4ID).value='';
    document.getElementById(txte5ID).value='';
    document.getElementById(txte6ID).value='';
    ShowLastConfirmMessage(DIVEmailFriendConfirmMessage,"Mail has been sent to your friend.");
    setTimeout('HideEmailFriendModalPopup()',3000);
}
function SendFriendEmail(xml)
{

}
function ShowLastConfirmMessage(objDIV, Message)
{
    document.getElementById(objDIV).innerHTML=Message;
}
function emailcheck(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false
	 }
	 return true					
}
