function openWin(url, codeBoxID) {
	win = window.open(url, '_blank', 'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
	win.blur();
	
	if (browserName=navigator.appName == "Microsoft Internet Explorer") {
	
	} else {
		var codeBox = document.getElementById(codeBoxID + 'codeBox');
		codeBox.focus();
		codeBox.select();
   }


	
    trackConv('','coupon',id);
}

function reveal(id)
{
	if (document.getElementById(id).style.marginRight != "2px")
	{
		document.getElementById(id).style.display = "none";
	}
}

function hide(id)
{
	if (document.getElementById(id).style.marginRight != "2px")
	{
		document.getElementById(id).style.display = "block";
	}
}

function clicked(id, url, code,input)
{
	document.getElementById(id).style.display = "none";
    document.getElementById(id).style.marginRight = "2px";
    document.getElementById('c'+id).style.overflow = "visible";
	document.getElementById('r'+id).style.height = "105px";
	
    var theInput = document.getElementById(input);
    copy(code);
	openWin(url);
	trackConv('','coupon',id);
    theInput.focus();
    theInput.select();

}

//this is the click function for expired codes which don't have the covering button to hide the code
function clickedNoId(url, code,input)
{
    var theInput = document.getElementById(input);
    copy(code);
		
	openWin(url);
    trackConv(url,'front-page-coupon',code);
    theInput.focus();
    theInput.select();
}

function copy(code) 
{
  if (code.createTextRange) {
    var range = code.createTextRange();
    if (range && BodyLoaded==1)
      range.execCommand('Copy');
    } 
    else 
    {
        ///for firefox?
    }
}
function trackConv(merchant,zone,vid) {
    
    var google_conversion_id = 1041045776;
    var google_conversion_language = "en_GB";
    var google_conversion_format = "3";
    var google_conversion_color = "ffffff";
    var google_conversion_label = "NQwrCMbVZRCQsrTwAw";
    var myimg =  "<img src='http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?label="+google_conversion_label+"&script=0'/>";
    document.getElementById("gtracking").innerHTML = myimg; 
    //alert('help');
    
    var track = '/outgoing/'+merchant+'/'+zone+'/'+vid;
    pageTracker._trackPageview(track);
   //alert(track);
} 

            var shownCodes = new Array();
            
            function showCode(voucherID) {
                $("#" + 'voucherID' + voucherID).show();
            }
        
            function hideCode(voucherID) {
                if (shownCodes[voucherID + 'shown'] != 1) {
                    $("#" + 'voucherID' + voucherID).hide();
                    $("#" + 'copyCode' + voucherID).hide();
                }
            }

            function bookmark_us(url, title){
                if (window.sidebar) {                           // firefox
                    window.sidebar.addPanel(title, url, "");
                } else if (window.opera && window.print) {      // opera
                    var elem = document.createElement('a');
                    elem.setAttribute('href',url);
                    elem.setAttribute('title',title);
                    elem.setAttribute('rel','sidebar');
                    elem.click();
                } else if(document.all) {                       // ie
                    window.external.AddFavorite(url, title);
                }
            }  
            
            function codeBlock(tracked, vid) {
                $("#" + vid + 'codeHover').removeClass("block_rollover");  
                $("#" + vid + 'codeHover').addClass("block_rollover2");
                $("#" + vid).show();
                $("#" + 'copyCode' + vid).show();   
                
                shownCodes[vid + 'shown'] = 1;
                
                openWin(tracked, vid);
                
                return false;
            }
