function MM_findObj(n, d) { //v4.01
  var p,i,x;if(!d) d=document;if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);return x;
}
function MM_preloadImages() { //v3.0
  var d=document;if(d.images){if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];}
}
function setStarAgain(giftid)
{
    recordStar(parseInt(document.getElementById('starUser'+giftid).value),giftid);
}
function recordStar(imgid,id){
for(var i=0;i<imgid;i++)
        document.getElementById('img'+(i+1)+''+id).src='images/star2.gif';
    for(i=imgid;i<5;i++)
        document.getElementById('img'+(i+1)+''+id).src='images/star1.gif';
}
function setStarValue(imgid,id){
    document.getElementById('starUser'+id).value=imgid;
}
function search(){
    var data="";
    if(document.searchform.searchcategory.value!='')
        data+=((data==''?'':'/')+"category:"+document.searchform.searchcategory.value);
    if(document.searchform.searchoccassion.value!='')
        data+=((data==''?'':'/')+"occassion:"+document.searchform.searchoccassion.value);
    if(document.searchform.searchprice.value!='')
        data+=((data==''?'':'/')+"price:"+document.searchform.searchprice.value);
    if(document.searchform.searchtext.value!='')
        data+=((data==''?'':'/')+"search:"+document.searchform.searchtext.value);
    data=base_path+"gifts/search/"+data;
    document.location.href=data;
}
function showhide(id)
{
    if(document.getElementById(id).style.display=='none')
            document.getElementById(id).style.display='';
    else
            document.getElementById(id).style.display='none';
}
function submitreview(id){
    var obj=document.getElementById('review'+id);
    var star=document.getElementById('starUser'+id).value;
    if(obj.username.value=='')
    {
        alert("Please Enter Your Name");
        obj.username.focus();
        return false;
    }
    if(obj.useremail.value=='')
    {
            alert("Please Enter Your Email");
            obj.useremail.focus();
            return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.useremail.value)))
    {
            alert("Please Enter Valid Email");
            obj.useremail.focus();
            return false;
    }
    if(obj.content.value.length>1000)
    {
        alert("Review Text exceeds the permitted no of characters");
        obj.content.focus();
        return false;
    }
        jQuery.ajax({
        type: "POST",
        url: "gifts/addreview.html",
        data:"star="+star+"&useremail="+obj.useremail.value+"&username="+obj.username.value+"&userphone="+obj.userphone.value+"&content="+obj.content.value+"&giftid="+obj.giftid.value,
        success: function(msg){
            alert(msg);
            obj.reset();
            obj.style.display='none';
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function removefromcart(giftid)
{
    jQuery.ajax({
        type: "POST",
        url: "gifts/removefromcart.html",
        data: "giftid="+giftid,
        success: function(msg){
            if(msg=="success"){
                alert("Remove from cart successfully.");
                document.location.reload();
            }
            else
                alert("Couldn't remove from cart");
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
}
function addtocart(id)
{
    var topups=document.getElementsByName("topups"+id+"[]");
    var topupids="";
    for(var i=0;i<topups.length;i++){
        if(topups[i].checked)
            topupids+=(topupids==""?"":",")+topups[i].value;
    }
    var newurl="gifts/addtocart/"+id+(topupids==""?"":"/"+topupids);
    document.location.href=base_path+newurl;
}
function isNumber(evt)
{
        var charCode = (evt.which) ? evt.which : event.keyCode

        if (charCode > 31 &&( charCode < 48 || charCode > 57))
                return false;

        return true;
}
function isPhoneNumber(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 &&( charCode < 48 || charCode > 57))
    {
        if(charCode != 45 && charCode != 43)
            return false;
    }
    return true;
}
function calculatePrice(giftid,giftprice,giftquantity)
{
   jQuery.ajax({
        type: "POST",
        url: "gifts/updatecart.html",
        data: "prodid="+giftid+"&quantity="+giftquantity,
        success: function(msg){
            var price=parseFloat(giftprice*giftquantity);
            var currentPrice=document.getElementById('price'+giftid).innerHTML;
            var totalPrice=document.getElementById('pricetotal').innerHTML;
            var tprice=parseFloat((parseFloat(totalPrice)-parseFloat(currentPrice))+price);
            document.getElementById('price'+giftid).innerHTML=price;
            document.getElementById('pricetotal').innerHTML=tprice;
            document.getElementById('totalamount').innerHTML=tprice;
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
}
function deleteorder(orderid)
{
    jQuery.ajax({
    type: "POST",
    url: "gifts/deleteorder.html",
    data: "orderid="+orderid,
    success: function(msg){
        if(msg=="success"){
            alert("Order deleted successfully.");
            document.location.reload();
        }
        else
            alert("Couldn't delete order");
    },
    error: function(){
            alert("Request couldn't be processed. Please try again later.");
    }
    });
}
function checkLogin(obj){
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    if(obj.password.value=='')
    {
        alert("Password is mandatory");
        obj.password.focus();
        return false;
    }
    return true;
}
function checkForgotPassword(obj){
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    return true;
}
function checkChangePassword(obj){
    if(obj.currentPassword.value=='')
    {
        alert("Current Password is mandatory");
        obj.currentPassword.focus();
        return false;
    }
    if(obj.newPassword.value=='')
    {
        alert("New Password is mandatory");
        obj.newPassword.focus();
        return false;
    }
    return true;
}
function checkRegister(obj){
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    if(obj.password.value=='')
    {
        alert("Password is mandatory");
        obj.password.focus();
        return false;
    }
    if(obj.firstName.value=='')
    {
        alert("First Name is mandatory");
        obj.firstName.focus();
        return false;
    }
    if(obj.lastName.value=='')
    {
        alert("Last Name is mandatory");
        obj.lastName.focus();
        return false;
    }
    return true;
}
function checkProfile(obj){
    if(obj.firstName.value=='')
    {
        alert("First Name is mandatory");
        obj.firstName.focus();
        return false;
    }
    if(obj.lastName.value=='')
    {
        alert("Last Name is mandatory");
        obj.lastName.focus();
        return false;
    }
    return true;
}
function checkoutWithCard(){
    var obj=document.forms['order'];
    if(obj.firstName.value=='')
    {
        alert("Please Provide First Name");
        obj.firstName.focus();
        return;
    }
    if(obj.lastName.value=='')
    {
        alert("Please Provide Last Name");
        obj.lastName.focus();
        return;
    }
    if(obj.emailAddress.value=='')
    {
        alert("Please Provide Email Address");
        obj.emailAddress.focus();
        return;
    }else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
            alert('Please Provide Valid Email Address.');
            obj.emailAddress.focus();
            return;
    }
    if(obj.phoneNo.value=='')
    {
        alert("Please Provide Phone no");
        obj.phoneNo.focus();
        return;
    }
    if(obj.addressLine1.value=='')
    {
        alert("Please Provide Address Line 1");
        obj.addressLine1.focus();
        return;
    }
    if(obj.city.value=='')
    {
        alert("Please Provide City");
        obj.city.focus();
        return;
    }
    if(obj.state.value=='')
    {
        alert("Please Provide State/region");
        obj.state.focus();
        return;
    }
    if(obj.country.value=='')
    {
        alert("Please Provide Country");
        obj.country.focus();
        return;
    }
    else
        obj.countryName.value=obj.country.options[obj.country.selectedIndex].text;

    if(obj.zipcode.value=='')
    {
        alert("Please Provide Zip code");
        obj.zipcode.focus();
        return;
    }
    if(obj.paymentMethod.value=='')
    {
        alert("Please Select Payment Method");
        obj.paymentMethod.focus();
        return;
    }
    //if(confirm("Proceeding for checkout will remove all the items stored in the cart. Do you want to submit your order?"))
    obj.submit();
}
function paymentMethod(type){
    if(type=='PAYPAL')
    	document.getElementById('creditdcarddata').style.display='none';
    else
        document.getElementById('creditdcarddata').style.display='block';
}
function continuecheckout()
{
    var obj=document.order;
    var success=true;
    if(obj.payment[0].checked==false)
    {
        if(obj.creditcardno.value=="")
        {
            alert("Please Enter Credit Card No");
            obj.creditcardno.focus();
            success=false;
        }
        else if(obj.creditcardcvvno.value=="")
        {
            alert("Please Enter Credit Card CVV No");
            obj.creditcardcvvno.focus();
            success=false;
        }
        else if(obj.creditcardname.value=="")
        {
            alert("Please Enter Name as on Credit Card");
            obj.creditcardname.focus();
            success=false;
        }
        if(success)
        	obj.action="gifts/paywithcard.html";
    }
    else
        obj.action='gifts/paywithpaypal.html';
    if(success)
    	obj.submit();
}
function paymentwithvoucher(){
    var obj=document.order;
    obj.action='gifts/paymentwithvoucher.html';
    obj.submit();
}
function wishfordisp(value){
    if(value=='yes'){
        document.getElementById('wishforemail').style.display='none';
    }
    else{
      document.getElementById('wishforemail').style.display='';
    }
}
function createwishlist(){
    var obj=document.wishlist;
    if(obj.name.value=='')
    {
        alert("Please Enter Name");
        obj.name.focus();
        return false;
    }
    if(obj.wishfor[1].checked==true)
    {
        if(obj.emailAddress.value=='')
        {
            alert("Please enter email addreess on behalf of whom wou want to create he wishlist");
            obj.emailAddress.focus();
            return false;
        } else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
        {
                alert("Please Enter Valid Email");
                obj.emailAddress.focus();
                return false;
        }
    }
      jQuery.ajax({
        type: "POST",
        url: "gifts/addwishlist.html",
        data:"emailAddress="+obj.emailAddress.value+"&name="+obj.name.value+"&wishfor="+(obj.wishfor[1].checked?'no':'yes')+"&type="+(obj.type[1].checked?'public':'private'),
        success: function(msg){
            alert(msg);
            document.location.reload();
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function sharewishlistf(){
    var obj=document.sharewishlist;
    if(obj.emailAddress.value=='')
    {
        alert("Please enter email addreess");
        obj.emailAddress.focus();
        return false;
    } else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
            alert("Please Enter Valid Email");
            obj.emailAddress.focus();
            return false;
    }
      jQuery.ajax({
        type: "POST",
        url: "gifts/sharewishlist.html",
        data:"emailAddress="+obj.emailAddress.value+"&wishid="+obj.wishid.value,
        success: function(msg){
            alert(msg);
            obj.reset();
            obj.style.display='none';
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function sharewithfriendf(){
    var obj=document.sharewithfriend;
    if(obj.fromName.value=='')
    {
        alert("Please enter your name");
        obj.fromName.focus();
        return false;
    }    
    else if(obj.fromEmailAddress.value=='')
    {
        alert("Please enter your email address");
        obj.fromEmailAddress.focus();
        return false;
    } else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.fromEmailAddress.value)))
    {
        alert("Please Enter Valid Email");
        obj.fromEmailAddress.focus();
        return false;
    }
    var emailAddresses="";
    if(obj.toEmailAddress.value=='')
    {
        alert("Please enter your friend's email addresses");
        obj.toEmailAddress.focus();
        return false;
    }
    else
    {
        var emails=obj.toEmailAddress.value.split(",");
        for(var i=0;i<emails.length;i++)
        {        
            if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emails[i])))
            {
                alert(emails[i]+" is invalid email address");
                return false;
            }
            else if(emailAddresses.indexOf(emails[i])!=-1){
                alert(emails[i]+" has been entered more than one time. Please remove the duplicate email address.");
                return false;
            }
            else
            {
                if(obj.fromEmailAddress.value=="keertikumari@xpressmyway.com")
                {
                    if(existingemailaddress.indexOf(emails[i])!=-1)
                        return confirm("Hi Keerti!!! you have already sent an invitation to \""+emails[i]+"\". Do you want to send this invitation again.")
                }
            }
            emailAddresses+=(emailAddresses==""?"":"~~")+emails[i];
        }
    }
    obj.submitbtn.disabled=true;
      jQuery.ajax({
        type: "POST",
        url: "gifts/sharewithfriend.html",
        data:"fromName="+obj.fromName.value+"&names="+name+"&emailAddress="+emailAddresses+"&fromEmailAddress="+obj.fromEmailAddress.value,
        success: function(msg){
            alert(msg);
            obj.reset();
            obj.submitbtn.disabled=false;
            document.location.reload();
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
            obj.submitbtn.disabled=false;
        }
    });
    return true;
}
function removewishlist(wishid){
      jQuery.ajax({
        type: "POST",
        url: "gifts/removewishlist.html",
        data: "wishid="+wishid,
        success: function(msg){
            alert(msg);
            document.location.reload();
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
}
function addtowishlist(giftid,wishlistid){
if(wishlistid==''){
    document.location.href=base_path+'gifts/wishlist.html';
}
else
{
   jQuery.ajax({
        type: "POST",
        url: "gifts/addtowishlist.html",
        data: "wishlistid="+wishlistid+"&giftid="+giftid,
        success: function(msg){
            alert(msg);
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
}
}
function removefromwishlist(giftid,wishlistid){
   jQuery.ajax({
        type: "POST",
        url: "gifts/removefromwishlist.html",
        data: "wishlistid="+wishlistid+"&giftid="+giftid,
        success: function(msg){
            alert(msg);
            document.location.reload();
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
}
function contactus(){
    var obj=document.contact;
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    if(obj.username.value=='')
    {
        alert("Name is mandatory");
        obj.username.focus();
        return false;
    }
    if(obj.query.value=='')
    {
        alert("Query is mandatory");
        obj.query.focus();
        return false;
    }
    jQuery.ajax({
        type: "POST",
        url: "gifts/contactus.html",
        data:"emailAddress="+obj.emailAddress.value+"&name="+obj.username.value+"&phone="+obj.phone.value+"&query="+obj.query.value,
        success: function(msg){
            alert(msg);
            obj.reset();
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function submitfeedback(){
    var obj=document.feedback;
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    if(obj.username.value=='')
    {
        alert("Name is mandatory");
        obj.username.focus();
        return false;
    }
    if(obj.content.value=='')
    {
        alert("Feedback is mandatory");
        obj.content.focus();
        return false;
    }
    jQuery.ajax({
        type: "POST",
        url: "gifts/feedback.html",
        data:"emailAddress="+obj.emailAddress.value+"&name="+obj.username.value+"&content="+obj.content.value,
        success: function(msg){
            alert(msg);
            obj.reset();
            showhide('newfeedback');
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function submitexp(){
    var obj=document.feedback;
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    if(obj.username.value=='')
    {
        alert("Name is mandatory");
        obj.username.focus();
        return false;
    }
    if(obj.content.value=='')
    {
        alert("Experience is mandatory");
        obj.content.focus();
        return false;
    }
    jQuery.ajax({
        type: "POST",
        url: "gifts/shareexperience.html",
        data:"emailAddress="+obj.emailAddress.value+"&name="+obj.username.value+"&content="+obj.content.value,
        success: function(msg){
            alert(msg);
            obj.reset();
            obj.style.display='none';
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function makeawish(obj){
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    if(obj.username.value=='')
    {
        alert("Name is mandatory");
        obj.username.focus();
        return false;
    }
    if(obj.description.value=='')
    {
        alert("Description is mandatory");
        obj.description.focus();
        return false;
    }
    return true;
}
function redeemgift(){
    var obj=document.redeem;
    var location=''
    if(document.getElementById('preferredLocation').innerHTML!=''){
        if(obj.selectLocation.value==''){
            alert("Please select preferred location.");
            obj.selectLocation.focus();
            return false;
        }
        location=obj.selectLocation.value;
    }
    if(obj.username.value=='')
    {
        alert("Name is mandatory");
        obj.username.focus();
        return false;
    }
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    if(obj.redemptionCode.value=='')
    {
        alert("Redemption Code is mandatory");
        obj.redemptionCode.focus();
        return false;
    }
    if(obj.firstdate.value==''){
        alert("Please Provide First Preferred Date.")
        obj.firstdate.focus();
        return false;
    }
    if(obj.seconddate.value==''){
        alert("Please Provide Second Preferred Date.")
        obj.seconddate.focus();
        return false;
    }
    if(obj.thirddate.value==''){
        alert("Please Provide Third Preferred Date.")
        obj.thirddate.focus();
        return false;
    }
    if(obj.firstdate.value==obj.seconddate.value){
        alert("First And Second Date Can not be identical.")
        return false;
    }
    if(obj.thirddate.value==obj.seconddate.value){
        alert("Second And Third Date Can not be identical.")
        return false;
    }
    if(obj.thirddate.value==obj.firstdate.value){
        alert("First And Third Date Can not be identical.")
        return false;
    }
    if(obj.timehr.value==''){
        alert("Please Select Preferred Time.")
        obj.timehr.focus();
        return false;
    }
    jQuery.ajax({
        type: "POST",
        url: "gifts/redeem.html",
        data:"location="+location+"&emailAddress="+obj.emailAddress.value+"&name="+obj.username.value+"&phone="+obj.phone.value+"&query="+obj.query.value+"&redemptionCode="+obj.redemptionCode.value
        +"&firstdate="+obj.firstdate.value+"&seconddate="+obj.seconddate.value+"&thirddate="+obj.thirddate.value+"&timepreffered="+obj.timehr.value+":"+obj.timemnt.value+" "+obj.timeduration.value,
        success: function(msg){
            alert(msg);
            obj.reset();
            document.getElementById('preferredLocation').innerHTML=msg;
            document.getElementById('preferredLocationRow').style.display='none';
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function subscribe(){
    var obj=document.subscription;
    if(obj.subname.value=='')
    {
        alert("Name is mandatory");
        obj.subname.focus();
        return false;
    }
    if(obj.subemail.value=='')
    {
        alert("Email Address is mandatory");
        obj.subemail.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.subemail.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.subemail.focus();
        return false;
    }

    jQuery.ajax({
        type: "POST",
        url: "gifts/subscribetonewsletters.html",
        data:"emailAddress="+obj.subemail.value+"&name="+obj.subname.value+"&phone="+obj.subphone.value,
        success: function(msg){
            alert(msg);
            obj.reset();
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function processRedemption(id)
{
    jQuery.ajax({
        type: "POST",
        url: "gifts/processRedemption.html",
        data: "redemptionCode="+document.getElementById('vouchercodes'+id).value,
        success: function(msg){
            if(msg!="success"){
                alert("Invalid Code.");
                document.getElementById('vouchercodes'+id).value="";
            }
            else
                document.location.reload();
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
}
function addCode()
{
    var tbl=document.getElementById('vouchers');
    var numrows=tbl.rows.length;
    var trow=tbl.insertRow(numrows);
    var tcell=trow.insertCell(0);
    tcell.setAttribute("width","100%");
    tcell.setAttribute("bgColor","#efe6e6");
    tcell.innerHTML="<input type=\"text\" onchange=\"processRedemption("+(numrows+1)+");\" name=\"vouchercodes"+(numrows+1)+"\" id=\"vouchercodes"+(numrows+1)+"\" maxlength=\"20\" style=\"width:65%\"/>&nbsp;<a href='javascript:void(0)' onclick='removeCodeEntry("+numrows+");' title='Click To Remove Code Entry'>Remove</a>";
}
function removeCode(id)
{
    jQuery.ajax({
    type: "POST",
    url: "gifts/removeRedemption.html",
    data: "redemptionCode="+id,
    success: function(msg){
        if(msg!="success"){
            alert("Couldn't Remove the code.");
        }
        else
            document.location.reload();
    },
    error: function(){
        alert("Request couldn't be processed. Please try again later.");
    }
    });
}
function removeCodeEntry(id)
{
    var tbl=document.getElementById('vouchers');
    tbl.deleteRow(id);
}
function checkLocationPreferences(code){
    document.getElementById('redemptionSubmitButton').disabled=true;
    jQuery.ajax({
        type: "POST",
        url: "gifts/checkLocation.html",
        data: "redemptionCode="+code,
        success: function(msg){
            if(msg!=''){
                document.getElementById('preferredLocation').innerHTML=msg;
                document.getElementById('preferredLocationRow').style.display='';
            }
            else
            {
                document.getElementById('preferredLocation').innerHTML=msg;
                document.getElementById('preferredLocationRow').style.display='none';
            }
            document.getElementById('redemptionSubmitButton').disabled=false;
        },
        error: function(){
        }
    });
}
function forwardvoucher(){
    var obj=document.redeem;
    if(obj.username.value=='')
    {
        alert("Name is mandatory");
        obj.username.focus();
        return false;
    }
    if(obj.emailAddress.value=='')
    {
        alert("Email Address is mandatory");
        obj.emailAddress.focus();
        return false;
    }
    else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value)))
    {
        alert('Please Provide Valid Email Address.');
        obj.emailAddress.focus();
        return false;
    }
    jQuery.ajax({
        type: "POST",
        url: "gifts/forwardvoucher/"+obj.voucherid.value,
        data:"emailAddress="+obj.emailAddress.value+"&name="+obj.username.value,
        success: function(msg){
            alert(msg);
            obj.reset();
            history.go(-1);
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
        }
    });
    return true;
}
function importcontacts(){
    if(document.getElementById("provider_box").value==''){
        alert("Please select mail provider");
        document.getElementById("provider_box").focus();
        return false;
    }
    if(document.getElementById("email_box").value==''){
        alert("Please provide user name");
        document.getElementById("email_box").focus();
        return false;
    }
    if(document.getElementById("password_box").value==''){
        alert("Please provide password");
        document.getElementById("password_box").focus();
        return false;
    }
    document.getElementById('msg1').style.display='';
    document.getElementById('importbtn').disabled=true;
    jQuery.ajax({
        type: "POST",
        url: base_path+"gifts/importContactsFromEmails.html",
        data:"provider_box="+document.getElementById("provider_box").value+"&email_box="+document.getElementById("email_box").value+"&password_box="+document.getElementById("password_box").value,
        success: function(msg){
            if(msg=="invalidlogin")
                alert("Login failed. Please check the email and password you have provided and try again later.");
            else if(msg=="nocontact")
                alert("No contacts found in your account.");
            else if(msg=="failure")
                alert("Some error occurred while importing contacts. Try again and if the problem persists, Please contact us.");
            else{
                document.sharewithfriend.toEmailAddress.value=(document.sharewithfriend.toEmailAddress.value==""?"":document.sharewithfriend.toEmailAddress.value+",")+msg;
                document.getElementById("provider_box").value="";
                document.getElementById("email_box").value="";
                document.getElementById("password_box").value="";
                showhide('mailimporter');
            }
            document.getElementById('msg1').style.display='none';
            document.getElementById('importbtn').disabled=false;
        },
        error: function(){
            alert("Request couldn't be processed. Please try again later.");
            document.getElementById('msg1').style.display='none';
            document.getElementById('importbtn').disabled=false;
        }
    });
}
