﻿function LoadRegistration() {
    BrowseTo(RegistrationURL);
}

function BrowseTo(url) {
    var deepLink = SWFAddress.getValue();
    url += "?DeepLink=" + URLEncode(deepLink);
    location.href= url;
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function test() {
    var flashcontent = returnObjById("flashcontent");
    DisplayCoupon("http://bricks.couponmicrosite.net/bricksweb/Index.aspx?o=1267&c=BJ&p=sam%40tundra.com.au&cpt=b56fujpgcfnF94oBu8oHy&ct=Samuel+Sperling");
}
function DisplayTCs() {
    var width =  500;
    var height = 500;
    var left = Math.floor( (screen.width - width) / 2);
    var top = Math.floor( (screen.height - height) / 2);
    window.open("tcs.html", "TCS", "width=" + width + ", height=" + height + ", scrollbars=yes"); //, left=" + left + ", top=" + top + "
}
function DisplayCoupon(url) {
    var couponDiv = returnObjById("couponDiv");
    var couponIFrame = returnObjById("couponIFrame");
    couponDiv.style.display = "block";
    couponIFrame.src = url;
}
function returnObjById(id)
{
    var returnVar;
    if (document.getElementById)
        returnVar = document.getElementById(id);
    else if (document.all)
        returnVar = document.all[id];
    else if (document.layers)
        returnVar = document.layers[id];
    return returnVar;
}
function couponContainerResize() {
    var couponContainer = returnObjById("couponContainer");
    var couponDiv = returnObjById("couponDiv");
    
    var windowWidth = document.body.offsetWidth; //parseInt(getStyle(document.body, "width"));
    var windowHeight = document.body.offsetHeight; //parseInt(getStyle(document.body, "height"));
    var couponWidth = 857;//parseInt(getStyle(couponDiv, "width"));
    var couponHeight = 625;//parseInt(getStyle(couponDiv, "height"));
    var top = (windowHeight - couponHeight) / 2;
    var left = (windowWidth - couponWidth) / 2;
    couponDiv.style.marginTop = Math.max(top, 0);
    couponDiv.style.marginLeft = Math.max(left, 0);
    
}
function getStyle(el, style) {
    var value = el.style[style];

    if(!value) {
        if(document.defaultView)
            value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
        else if(el.currentStyle)
            value = el.currentStyle[style];
    }

    return value;
}
function CloseCoupon() {
    var couponDiv = returnObjById("couponDiv");
    couponDiv.style.display = "none";
}


