// JScript File
function ChangeURLsent(url)
{
    ShowOriginal();
    document.getElementById('txtURLToSend').value = url;
    
}
// JScript File
var OriginalDiv;
var FlagCounter = 0 ;
function closeDiv()
{
    document.getElementById('main-emailafriend').style.display='none';
    ShowOriginal();
}function ShowOriginal()
{
    if(FlagCounter > 0)
    {
           var Fdiv = document.getElementById('main-emailafriend');
            Fdiv.innerHTML = OriginalDiv;
             FlagCounter = 0;
           
    }
    
    
}

function FriendValidate()
{

               var  obj = document.getElementById('txtTo');
               if(!(chkEmptyEmail(obj,"To: address") && chkPatternEmail(obj,"To: address",/^[A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}(?:[,;][A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4})*$/i)))
               {
                
                    return false;
               }  
            
               
               
               obj = document.getElementById('txtYourEmail');
               if(!(chkEmptyEmail(obj,"email address") && chkPatternEmail(obj,"email address",/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)))
               {
                    return false;
               }
                              
               obj = document.getElementById('Message');
               if(!chkEmptyEmail(obj,"Your Message"))
               {                
                    return false;
               } 
                                             
               obj = document.getElementById('CaptchaCode');
               if(!chkEmptyEmail(obj,"Security code"))
               {
                    return false;
               }
                              
               sendEmail('/formPost.aspx');
               return false; 
         
}



function sendEmail(url)
{
        //var txt 
        var txtTo = document.getElementById('txtTo').value;
        var txtYourName = document.getElementById('txtYourName').value;        
        var txtYourEmail = document.getElementById('txtYourEmail').value;
        var Message = document.getElementById('Message').value;
        var cbCopy = document.getElementById('cbCopy').checked;
        var txtSubject = document.getElementById('txtSubject').value;
        var captchaCode = document.getElementById('CaptchaCode').value;
        
       // var UrltoSend = document.getElementById('txtURLToSend').value;
        
        var UrltoSend = escape(window.location.href);
		UrltoSend = UrltoSend.replace("+", "%2B");
		UrltoSend = UrltoSend.replace("/", "%2F");
        
        CreateXmlHttpRequest();
       
        url+="?type=email.send&txtTo="+txtTo+"&txtYourName="+txtYourName+"&txtYourEmail="+txtYourEmail+"&UrltoSend="+UrltoSend+"&Message="+Message+"&cbCopy="+cbCopy+"&txtSubject="+txtSubject+"&captchaCode="+captchaCode;
        request.onreadystatechange = emailSend;
        request.open("GET", url, true);
        request.send(null);
        
        //document.getElementById('txtURLToSend').value= "";
        
        //document.getElementById('CaptchaCode').value = "";
    
}
function emailSend()
{
    if(request.readyState == 4)
    {
        if(request.status == 200)
        {
            if(request.responseText == 'unauthorized')
            {
            var captchaImage = document.getElementById('captchaImage');
            captchaImage.src = "/Captcha/JpegImage.aspx?cacheId=" + Math.ceil(100*Math.random());
            alert('Please re-enter your captcha Code');
            FlagCounter++;
            return;
            }
           
            ResetDiv('Thanks');   
                       
            
            FlagCounter++;                             
        }
       
        else
        {
            alert(request.status);
        }
    }
}

function ResetDiv(whichone)
{
    if(whichone == "Thanks")
    {
        document.getElementById('txtTo').value = "";
        document.getElementById('Message').value= "";
        document.getElementById('cbCopy').checked= "";
        document.getElementById('CaptchaCode').value = "";
        
        var div = document.getElementById('main-emailafriend');
      
        var divid= document.getElementById('ThanksDiv');
       
        OriginalDiv = div.innerHTML;
        div.innerHTML = "";
        div.innerHTML = divid.innerHTML;
           
     }
     
     else 
    {
       
       var thanksDiv = document.getElementById('Div1');
       thanksDiv.innerHTML = '';
       thanksDiv.innerHTML = "<br /><br /><br /><br /><br /><br /><br /><br /><div style='margin:0px auto;padding:15px;'><div>Loading...</div><br /><div><img src='/images/loadingNew.gif' alt='loading'></div></div>";
       setTimeout("NewReset()",4000);
              
     }


}

        function NewReset()
        {
                   var div = document.getElementById('main-emailafriend');
                   div.innerHTML = OriginalDiv;
                   var captchaImage = document.getElementById('captchaImage');
                   captchaImage.src = "/Captcha/JpegImage.aspx?cacheId=" + Math.ceil(100*Math.random());
                   FlagCounter = 0;
        }