﻿

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]; }

}



/* Bookmark website */
function BookMarkWebsite()
{
    if (window.sidebar) // firefox
    {
        window.sidebar.addPanel('VoucherCodes.Net - ' + document.title, location.href,'');
    }
    else if(window.opera && window.print)  // opera
    {
        var elem = document.createElement('a');
        elem.setAttribute('href', location.href);
        elem.setAttribute('title', document.title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if(document.all)// ie
    {
        window.external.AddFavorite(location.href,'VoucherCodes.Net - ' + document.title);
    }
}

/* Set as Home page */
function SetAsHomePage(control)
{
    var thePageVCNet='http://www.vouchercodes.net'
    control.style.behavior='url(#default#homepage)';
    var isSetHome = control.setHomePage(thePageVCNet);
    
    if(isSetHome)
    {
        window.location.href=window.location.href;
        return false;
    }
    else
    {
        return false;
    }
}

/* Check whether the email address is a vaild one */
function checkEmailAddress(inputEmail) 
{
    if(inputEmail)
    {
        var isEmailValid = inputEmail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
        
        return isEmailValid; 
    }
    else
    {
        return false;
    }
}    

/* Tell a friend about the site */
function SendMail()
{
    var isEmailValid = false;
    var inputEmail = document.getElementById('textBoxEmailAddress');
    
    if(inputEmail != null)
    {
        isEmailValid = checkEmailAddress(inputEmail);
    }
    	        
    if (isEmailValid) 
    {
        var subject = "Take a look at this site";
        var message = "Hi,<br\> You may want to check out this site:<br\>  <a href=" + window.location + ">VoucherCodes.Net</a>";
        window.location = "mailto:" + inputEmail.value + "?subject=" + subject + "&body=" + message;
    }
    else
    {
        	alert('Please enter a valid Email Address.');
            inputEmail.focus();
            inputEmail.select();
    }
}

function RemoveText()
{
    var textBoxSearchRetailer = document.getElementById("ctl00_textBoxSearchRetailer");
    if(textBoxSearchRetailer != null)
    {
        if(textBoxSearchRetailer.value != '')
        {
            textBoxSearchRetailer.value = '';
        }
    }
    
    return false;
}

function ValidateRetailerSearch()
{
    var textBoxSearchRetailer = document.getElementById("ctl00_textBoxSearchRetailer");
     
    if(textBoxSearchRetailer != null)
    {
        if(textBoxSearchRetailer.value == null || textBoxSearchRetailer.value == '' || textBoxSearchRetailer.value == 'Enter Retailer Name')
        {
            alert("Please enter a retailer name.");
            textBoxSearchRetailer.select();
            return false;
        }
        else
        {
             var text = textBoxSearchRetailer.value;
             var trimmed = text.replace(/^\s+|\s+$/g, '') ; 
             
             if(trimmed.length == 0)  
             {
                alert("Please enter a retailer name.");
                textBoxSearchRetailer.select();
                return false;
             }
        }
    }   
    
    return true;  
}

/*select the price comparision search engine*/
function SelectPriceComparisionSearchEngine(selectedSearchEngine)
{
    if(selectedSearchEngine != '')
    {
        document.getElementById("ctl00_contentPlaceHolderUser_hiddenFieldSelectedSearchEngineName").value = selectedSearchEngine;
    }
    
    selectedSearchEngine = document.getElementById("ctl00_contentPlaceHolderUser_hiddenFieldSelectedSearchEngineName").value;
    
    var searchString = document.getElementById("ctl00_contentPlaceHolderUser_textBoxSearchString").value;
    
    switch(selectedSearchEngine)
    {
        case "Amazon":
            var sourceURLAmazon = "http://www.amazon.co.uk/gp/search?ie=UTF8&keywords=" + searchString.replace("&", "+") + "&tag=pricebargain-21&index=blended&linkCode=ur2&camp=1634&creative=6738";
            document.getElementById("iFrameSearchResult").src = sourceURLAmazon;
            break;
        case "BuyCentral":
            var sourceURLBuyCentral = "http://being.successfultogether.co.uk/click.asp?site=3941&ref=288935&type=html&ent=1&hnb=1&subid=&prd=yes&linkID=affilinet&diurl=http://www.buycentral.co.uk/query.html?qry=" + searchString.replace("&", "+");
            document.getElementById("iFrameSearchResult").src = sourceURLBuyCentral;
            break;
        case "DealTime":
            var sourceURLDealTime = "http://www.amazon.co.uk/gp/search?ie=UTF8&keywords=" + searchString.replace("&", "+") + "&tag=pricebargain-21&index=blended&linkCode=ur2&camp=1634&creative=6738";
            document.getElementById("iFrameSearchResult").src = sourceURLDealTime;
            break;
        case "Kelkoo":
            var sourceURLKelkoo = "http://clkuk.tradedoubler.com/click?p=3431&a=1243725&g=978406&url=http://www.kelkoo.co.uk/ctl/do/search?siteSearchQuery=" + searchString + "&kpartnerid=8902247&popups=no";
            document.getElementById("iFrameSearchResult").src = sourceURLKelkoo;
            break;
        case "PriceRunner":
            var sourceURLPriceRunner = "http://www.anrdoezrs.net/9r75zw41w3JMKMSOSSJLKNSPOKN?URL=http%3A%2F%2Fwww.pricerunner.co.uk%2Fsearch?q=" + searchString;
            document.getElementById("iFrameSearchResult").src = sourceURLPriceRunner;
            break;
        case "Tesco":
            var sourceURLTesco = "http://clkuk.tradedoubler.com/click?p=898&a=1371404&g=19971&url=http://direct.tesco.com/search/default.aspx?search=" + searchString.replace(" ", "+");
            document.getElementById("iFrameSearchResult").src = sourceURLTesco;
            break;
        default:
            var sourceDefaultURLKelkoo = "http://clkuk.tradedoubler.com/click?p=3431&a=1243725&g=978406&url=http://www.kelkoo.co.uk/ctl/do/search?siteSearchQuery=" + searchString + "&kpartnerid=8902247&popups=no";
            document.getElementById("iFrameSearchResult").src = sourceDefaultURLKelkoo;
            break;
    }
    
    
}

/*Open new window*/
function OpenNewWindow(url)
{
    if(url != '')
    {
       window.open(url, '_blank', 'channelmode=no, directories=yes, fullscreen=no, , height=700px, left=10px, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, top=10px, width=750px',false ); 
       window.focus(); 
    }

}

/* Copy to Clipboard */
function CopyToClipBoard(discountCode)
{
    if(discountCode != '' && discountCode != null)
    {
        try
        {
            if (window.clipboardData) 
            {
                window.clipboardData.setData("Text",discountCode);
                alert('Discount code '+ discountCode +' copy to clip board');
            }
        }
        catch(err)
        {
            //alert(err);    
        
        }
    }
    else
    {
        alert('no code in this section');
    }
}

/*Set cookie*/
function SetCookie(c_name, value, expiredays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toUTCString());
}

/*Get cookie*/
function GetCookie(c_name)
{
    if (document.cookie.length > 0)
    {
        c_start = document.cookie.indexOf(c_name + "=");
        
        if (c_start != -1)
        {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            
            if (c_end == -1) 
            {
                c_end = document.cookie.length;
            }
            
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    
    return "";
}     

function pageLoad()
{
   //onItemSelected funtion to be called when 
   //itemSelected event of AutoCompleteExtender 
   //for Retailer Search is fired.
   $find("AutoCompleteExHomeSearch").add_itemSelected(onItemSelected);
   
   if(!IsNewsletterSubscriptionModelPopedup())
   {
        ShowModelPopupNewsletterSubscription();
   }
}


function onItemSelected()
{
    //var linkButtonClick = $get("ctl00_linkButtonClick");
    var linkButtonClick = document.getElementById("ctl00_userControlSearch_linkButtonClick");
    
    if(linkButtonClick != null)
    {
        //Fire the click event of "linkButtonClick".
        try
        {
           __doPostBack('ctl00$userControlSearch$linkButtonClick','');
        }
        catch(err)
        {
           
           alert(err.message)
        }
        
    }
}    


function ClientPopulated(source, eventArgs)
{
    if (source._currentPrefix != null)
    {
        var list = source.get_completionList();
        var search = source._currentPrefix.toLowerCase();
        for (var i = 0; i < list.childNodes.length; i++)
        {
            var text = list.childNodes[i].innerHTML;
            text = text.replace('&amp;', '&');
            var index = text.toLowerCase().indexOf(search);
                                
            if (index != -1)
            {
                var value = text.substring(0, index);
                value += '<span class="autoComplete_ListItemHiliteText">';
                value += text.substr(index, search.length);
                value += '</span>';
                value += text.substring(index + search.length);
                list.childNodes[i].innerHTML = value;
            }
        }
    }
}


function ClientItemSelected(source, e)
{
    var selectedString = e._item.textContent;
    
    if(selectedString == null)
    {
        selectedString = e.get_value();
    }
    
    if(selectedString == null)
    {
        selectedString = e.get_text();
    }
    
    source.get_element().value = selectedString;
}
//  
function ShowModelPopupNewsletterSubscription()
{
    setTimeout('$find("behaviorIDModalPopupExtenderNewsletterSubscription").show();',10000);
    
    SetCookie('VCNetNewsletterSubscriptionModelPopup', 'true', 1);
}

function IsNewsletterSubscriptionModelPopedup()
{
    newsletter = GetCookie('VCNetNewsletterSubscriptionModelPopup');
    
    if (newsletter != null && newsletter != "")
    {
        return true
    }
    
    return false;
}    
/*Changed by JK dated 6/04/2011*/ /*Modified by Vineetha on 16/12/2011*/
function ShowDiscountCode(discountCodeId,isExpired)
{   
    var divR = document.getElementById("divDiscountCodeRevealed_" + discountCodeId);
    var divH =  document.getElementById("divDiscountCodeHidden_" + discountCodeId);
    var span = document.getElementById("spanDiscountCode_" + discountCodeId);
    var divRate = document.getElementById("divRatingHidden_" + discountCodeId);
    if(span.innerHTML.toUpperCase() !='<B>NO CODE</B>')
    {
        if(divR != null)
        {
            divR.style.display = 'block';
        }
          if(divH != null)
        {
            divH.style.display = 'none';
        }
    }
    else
    {
       var codemask = document.getElementById("divDiscountCode_" + discountCodeId);   
      
    if (codemask != null)     
    {
        codemask.className = 'coderelease_bg';
    }
    
    if(span != null)
    {
        span.style.display = 'block';
    } 
    }

if (divRate != null) {
    divRate.style.display = 'block';
}
}
/*Added by JK dated 6/04/2011 Modified by Vineetha on 28/12/2011*/ 
function ShowDiscountCodeDiv(isExpired)
{   
    var divR = document.getElementById("divDiscountCodeRevealed_Main");
    var divH =  document.getElementById("divDiscountCodeHidden_Main");
    var span = document.getElementById("ctl00_contentPlaceHolderUser_spanDiscountCode_Main");
    var divRate = document.getElementById("divRatingHidden");     
    if(span.innerHTML.toUpperCase() !='<B>NO CODE</B>' && isExpired !='True')
    {
        if(divR != null)
        {
            divR.style.display = 'block';
        }
          if(divH != null)
        {
            divH.style.display = 'none';
        }
    }
    else
    {
       var codemask = document.getElementById("ctl00_contentPlaceHolderUser_divDiscountCode_Default");   
      
    if (codemask != null)     
    {
        codemask.className = 'coderelease_bg';
    }
    
    if(span != null)
    {
        span.style.display = 'block';
    } 
    }

if (divRate != null) {
    divRate.style.display = 'block';
}
}
/*Added by JK dated 6/04/2011*/
function ShowThanksDiv(discountCodeId)
{      
    var divR = document.getElementById("divtnks_" + discountCodeId);
     if(divR != null)
        {
            divR.style.display = 'block';
        }
}


function HideDiscountCode(discountCodeId, IsCodeVisible)
{
    var codemask = document.getElementById("divDiscountCode_" + discountCodeId);
    var span =  document.getElementById("spanDiscountCode_" + discountCodeId);
    
    if(IsCodeVisible == "False")
    {
        if (codemask != null)     
        {
            codemask.className = 'codemask_bg';
        }
        
        if(span != null)
        {
            span.style.display = 'none';
        }
    }
    
}

function ShowAllDiscountCodes()
{
    var allDivs = document.getElementsByTagName("div");
    var allSpans = document.getElementsByTagName("span");
    
    if(allDivs != null)
    {
        for(i = 0; i < allDivs.length; i++)
        {
            if(allDivs[i].id.match("divDiscountCode_"))
            {
                if(allDivs[i].className != 'coderelease_bg' )
                {
                    allDivs[i].className = 'coderelease_bg';
                }
            }
        }
    }
    
    if(allSpans != null)
    {
        for(i = 0; i < allSpans.length; i++)
        {
            if(allSpans[i].id.match("spanDiscountCode_"))
            {
                if(allSpans[i].style.display != 'block' )
                {
                    allSpans[i].style.display = 'block';
                }
            }
        }
    }
    
    return false;
}
/*Open new in window added by Vineetha*/
function NewWindowForCitydeal(url) {
    if (url != '') {
        window.open(url, 'NewWindow', 'channelmode=no, directories=yes, fullscreen=no, , height=700px, left=10px, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, top=10px, width=750px', false);
        NewWindow.focus();
    }
}

/*Open new window*/
function NewWindowOfRetailer(returl) {
    if (returl != '') {
        window.open(returl, '_blank', 'channelmode=no, directories=yes, fullscreen=no, , height=700px, left=10px, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, top=10px, width=750px', false);
        window.focus();
    }
}



    /*Jquery section Begin */
    /*Added by JK dated 6/04/2011*/
$(document).ready(function () {
    /* Open new window & change text in ViewRetailerDiscountCodeDetails.aspx
    $(".code_vc_s2").click(function(event)
    {       
    var new_win = window.open( $(this).attr("href") ,'_blank','toolbar=1,height=300, width=600,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
    new_win.moveTo(0,0);
    $(this).text('Scroll Down To View Codes');
    $(this).removeClass("code_vc_s2"); 
    return false;
    });*/

    /* Opend new window*/
    $(".code_vc_s").click(function (event) {
        var new_win = window.open($(this).attr("href"), '_blank', 'toolbar=1,height=300, width=600,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
        new_win.moveTo(0, 0);
        return false;
    });

    $('div.expandable').expander({
        slicePoint: 650,  // default is 100
        expandPrefix: '... ', // default is '... ' 
        expandText: 'Read more',
        userCollapseText: 'Read less'
    });

    // NewletterPopUp Section Start Added on 05-01-2012 by JK

    //select all the a tag with name equal to modal
    $('a[name=newsletter_modal]').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();

        // Clearn  Messges
        $('.newsletter_warningbg p').empty();
        $('.newsletter_success p').empty();
        

        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#newslettermask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#newslettermask').fadeIn(1000);
        $('#newslettermask').fadeTo("slow", 0.9);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(2000);

    });

    //if close button is clicked
    $('.newsletter_window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();

        $('#newslettermask').hide();
        $('.newsletter_window').hide();
    });

    //if mask is clicked
    $('#newslettermask').click(function () {
        $(this).hide();
        $('.newsletter_window').hide();
    });


    $("#OkButton").click(function () {
        var email = $(".newslettertxtemail").val();

        $('.newsletter_warningbg p').empty();
        $('.newsletter_success p').empty();

        $.ajax({
            type: 'POST',
            url: 'http://www.vouchercodes.net/WebServices/Newsletter.asmx/AddNewItem',
            data: '{"email":"' + email + '"' + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d) {
                    if (msg.d.indexOf('An Email') >= 0) {
                        $('.newsletter_success p').text(msg.d);
                    }
                    else {
                        $('.newsletter_warningbg p').text(msg.d);
                    }
                }
            },
            error: function () {
                alert("Error! Try again later...");
            }
        });
    });

    // NewletterPopUp Section End 


    // Carousel  Added by JK dated 11 Jan 2012  - Start

/*$("#carousel").rcarousel(
	{
		visible: 1,
		step: 1,
		speed: 700,
		auto: {
			enabled: true
		},
		width: 642,
		height: 70
	}
);

$("#ui-carousel-next")
	.add("#ui-carousel-prev")
	.add(".bullet")
	.hover(
		function () {
			$(this).css("opacity", 0.7);
		},
		function () {
			$(this).css("opacity", 1.0);
		}
	);*/
    
	// Carousel Section End 

});
/*Added by vineetha on 22/12/2011 for Retailer page Terms and Conditions*/
function ToggleDiv(discountCodeId) {
    var divR = document.getElementById("divTerms_" + discountCodeId);
    if (divR != null) {
        $(divR).slideToggle("slow");
    }
}
function ToggleDivMoreInfo() {
    var divR = document.getElementById("divTermsMoreInfo");
    if (divR != null) {
        $(divR).slideToggle("slow");
    }
}
     /*Jquery section End */


/*Added by vineetha on 21/12/2011 for More info in retailer's description section*/
function ShowDescription() {
    document.getElementById('divMoreInfo').style.display = 'none';
    document.getElementById('divDescription').style.display = 'inline';
    document.getElementById('divLessInfo').style.display = 'inline';
    document.getElementById('divPageDescription').style.display = 'inline';    
}
function HideDescription() {
    document.getElementById('divMoreInfo').style.display = 'inline';
    document.getElementById('divDescription').style.display = 'none';
    document.getElementById('divLessInfo').style.display = 'none';
    document.getElementById('divPageDescription').style.display = 'none';
}



$(document).ready(function () {

   


});


