﻿// JScript File
function ChangeURLsent(url)
{
    ShowOriginal();
    document.getElementById('txtURLToSend').value = url;
    
}
// JScript File
var OriginalDiv;
var FlagCounter = 0 ;
function closeDiv()
{
    document.getElementById('EmailFriendDiv').style.display='none';
    ShowOriginal();
}function ShowOriginal()
{
    if(FlagCounter > 0)
    {
           var Fdiv = document.getElementById('EmailFriendDiv');
            Fdiv.innerHTML = OriginalDiv;
             FlagCounter = 0;
           
    }
}

function FriendValidate()
{
   var  obj = document.getElementById('txtTo');
   if(!(chkEmpty(obj,"To: address") && chkPattern(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('txtYourName');
    if(!chkEmpty(obj,"Your Name"))
   {
    
        return false;
   } 
   obj = document.getElementById('txtYourEmail');
   if(!(chkEmpty(obj,"email address") && chkPattern(obj,"email address",/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)))
   {
        return false;
   }
   
   sendEmail('/myAccount/formPost.aspx');
   return false;         
}

function OfferValidate()
{
   var  obj = document.getElementById('txtNameAds');
   if(!chkEmpty(obj,"your name"))
        return false;
   obj = document.getElementById('txtYourEmailAds');
   if(!(chkEmpty(obj,"email address") && chkPattern(obj,"email address",/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)))
        return false;
   obj = document.getElementById('txtTelephoneAds');
    if(!(chkEmpty(obj,"telephone no") )) //&& chkPattern(obj,"telephone no", /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/)
        return false;
   obj = document.getElementById('captchaAds');
   if(!(chkEmpty(obj,"verification code"))) //
        return false;
   
   var name = jQuery('#txtNameAds').val();
   var email = jQuery('#txtYourEmailAds').val();
   var telephone = jQuery('#txtTelephoneAds').val();
   var partner =jQuery('#txtSubjectAds').val() ;
   var message=jQuery('#messageAreaAds').val() ;
   var captcha = jQuery("#captchaAds").val();
      
   jQuery.post("/myAccount/formPost.aspx",
        {type:"Partner Offer", name: name, email: email, telephone: telephone, partner: partner, message: message, captcha: captcha},
        function(data){
            if(data == "")
            {
                jQuery("#adsformwalidiv").fadeOut("fast");
                jQuery("#adsthankswalidiv").fadeIn("slow");
                jQuery("#adsdiv").fixedCenter();
                jQuery("#adsform")[0].reset();
                jQuery("#adsclosebottom").click(function(){
                    jQuery("#adsdiv").fadeOut();
                });
                jQuery("#adsdiv").fixedCenter();
            }
            else{
                if(data == "unauthorized" && (!jQuery("#codeerrorwalidiv").length))
               {
                    jQuery("#captchadiv").after("<div class='clear'></div><div style='color:#C60074;font-size:11px;padding-bottom:3px;' id='codeerrorwalidiv'>Please enter correct verification code</div>");
                }
            }
        }
   );
   return false;  
}


function OfferValidateMain()
{
   var  obj = document.getElementById('txtNameAds');
   if(!chkEmpty(obj,"your name"))
        return false;
   obj = document.getElementById('txtYourEmailAds');
   if(!(chkEmpty(obj,"email address") && chkPattern(obj,"email address",/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)))
        return false;
   obj = document.getElementById('txtTelephoneAds');
    if(!(chkEmpty(obj,"telephone no") )) //&& chkPattern(obj,"telephone no", /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/)
        return false;
   
   
   return true;  
}

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;
    
    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);
}
function emailSend()
{
    if(request.readyState == 4)
    {
        if(request.status == 200)
        {
         try{
            document.getElementById('txtTo').value = "";
            document.getElementById('Message').value= "";
            document.getElementById('cbCopy').checked= "";
            document.getElementById('txtURLToSend').value= "";
            document.getElementById('captchaImage').src = "/Captcha/JpegImage.aspx?cacheId=" + (new Date().getMilliseconds());
            document.getElementById('CaptchaCode').value = "";
            }catch(err){};
            ResetDiv('Thanks');   
            FlagCounter++;                             
        }
        else
        {
            alert(request.status);
        }
    }
}

function ResetDiv(whichone)
{
    if(whichone == "Thanks")
    {
 
        var div = document.getElementById('EmailFriendDiv');
       
        var divid= document.getElementById('ThanksDiv');
       
       OriginalDiv = div.innerHTML;
       div.innerHTML = "";
       div.innerHTML = divid.innerHTML;
           
     }    
     else 
     {
       var div = document.getElementById('EmailFriendDiv');
       div.innerHTML = OriginalDiv;
       FlagCounter = 0;
     }
}
