﻿var oldEvt=window.onload;
var tmcMPU;
window.onload=function()
{
    if (oldEvt) oldEvt();
	tmcOnLoad();
}

function tmcOnLoad()
{
    var tmcLink=document.getElementById("tmcLink");
    var tmcAffiliateHI=document.getElementById("tmcAffiliateID");
    var tmcFormName=document.getElementById("tmcFormName");
	var tmcFormLogo=document.getElementById("tmcFormLogo");
	var tmcFormTitle=document.getElementById("tmcFormTitle");
	var tmcFormIntro=document.getElementById("tmcFormIntro");
	var tmcFormInitialCountry=document.getElementById("tmcFormInitialCountry");
	var tmcFormCurrency=document.getElementById("tmcFormCurrency");
	var tmcFormStyle=document.getElementById("tmcFormStyle");
	var tmcFormBackground=document.getElementById("tmcFormBackground");
	var tmcFormFont=document.getElementById("tmcFormFont");
	var tmcFormTitleSize=document.getElementById("tmcFormTitleSize");
	var tmcFormTitleFont=document.getElementById("tmcFormTitleFont");
	var tmcFormTitleColor=document.getElementById("tmcFormTitleColor");
	var tmcFormTitleWeight=document.getElementById("tmcFormTitleWeight");
	var tmcFormTitleAlign=document.getElementById("tmcFormTitleAlign");
	var tmcFormIntroSize=document.getElementById("tmcFormIntroSize");
	var tmcFormIntroFont=document.getElementById("tmcFormIntroFont");
	var tmcFormIntroColor=document.getElementById("tmcFormIntroColor");
	var tmcFormIntroWeight=document.getElementById("tmcFormIntroWeight");
	var tmcFormIntroAlign=document.getElementById("tmcFormIntroAlign");
	
    tmcMPU=document.getElementById("frmTMCSOS");
    if (tmcMPU==null)
    {
        alert("no iframe");
        return false;
    }
    if (tmcAffiliateHI==null)
    {
        addFrameText("no affiliate id");
        return false;
    }
    var tmcAffiliateID=tmcAffiliateHI.value;
    if (tmcLink==null)
    {
        addFrameText("no link");
        return false;
    }
    if (tmcLink.innerHTML.length<10)
    {
       addFrameText("no link text");
       return false;
    }
    if (tmcLink.href.indexOf("themovechannel")<1)
    {
       addFrameText("no link to themovechannel");
       return false;
    }
    
	
	
	var sSRC="http://services.themovechannel.com/SOS/"
    switch (tmcFormName.value)
    {
        case "long":
            sSRC = sSRC + "long.aspx";
            break;
		case "mpu":
            sSRC = sSRC + "mpu.aspx";
            break;
		case "narrow":
            sSRC = sSRC + "narrow.aspx";
            break;
		case "250":
            sSRC = sSRC + "250.aspx";
            break;
		case "500":
            sSRC = sSRC + "500.aspx";
            break;
        case "550":
            sSRC = sSRC + "550.aspx";
            break;
        case "200":
            sSRC = sSRC + "200.aspx";
            break;
		case "tmc":
            sSRC = sSRC + "tmc.aspx";
            break;
        case "lightbox":
            sSRC = sSRC + "lightbox.aspx";
            break;
        default:
            sSRC = sSRC + "mpu.aspx";
            break;
    }
	sSRC=sSRC + "?affiliateID=" + tmcAffiliateID;
	if (tmcFormLogo!=null)
		sSRC=sSRC + "&logo=" + escape(tmcFormLogo.value);
	if (tmcFormTitle!=null)
		sSRC=sSRC + "&title=" + escape(tmcFormTitle.value);
	if (tmcFormIntro!=null)
		sSRC=sSRC + "&intro=" + escape(tmcFormIntro.value);
	if (tmcFormInitialCountry!=null)
		sSRC=sSRC + "&initialCountry=" + tmcFormInitialCountry.value;
	if (tmcFormCurrency!=null)
		sSRC=sSRC + "&currency=" + tmcFormCurrency.value;
	if (tmcFormStyle!=null)
		sSRC=sSRC + "&style=" + tmcFormStyle.value;
	if (tmcFormBackground!=null)
		sSRC=sSRC + "&background=" + escape(tmcFormBackground.value);	
	if (tmcFormFont!=null)
		sSRC=sSRC + "&font=" + tmcFormFont.value;
	if (tmcFormTitleSize!=null)
		sSRC=sSRC + "&title-size=" + tmcFormTitleSize.value;	
	if (tmcFormTitleFont!=null)
		sSRC=sSRC + "&title-font=" + tmcFormTitleFont.value;	
	if (tmcFormTitleColor!=null)
		sSRC=sSRC + "&title-color=" + escape(tmcFormTitleColor.value);	
	if (tmcFormTitleWeight!=null)
		sSRC=sSRC + "&title-weight=" + tmcFormTitleWeight.value;	
	if (tmcFormTitleAlign!=null)
		sSRC=sSRC + "&title-align=" + tmcFormTitleAlign.value;			
		
		
	if (tmcFormIntroSize!=null)
		sSRC=sSRC + "&intro-size=" + tmcFormIntroSize.value;		
	if (tmcFormIntroFont!=null)
		sSRC=sSRC + "&intro-font=" + tmcFormIntroFont.value;
	if (tmcFormIntroColor!=null)
		sSRC=sSRC + "&intro-color=" + escape(tmcFormIntroColor.value);	
	if (tmcFormIntroWeight!=null)
		sSRC=sSRC + "&intro-weight=" + tmcFormIntroWeight.value;
	if (tmcFormIntroAlign!=null)
		sSRC=sSRC + "&intro-align=" + tmcFormIntroAlign.value;		
	sSRC=sSRC + "&parenturl=" + parent.document.location.href;
    tmcMPU.src=sSRC;
	
    
    
}

function addFrameText(txt)
{
    var doc=tmcMPU.document;
    if (tmcMPU.contentDocument)
        doc=tmcMPU.contentDocument;
    else if (tmcMPU.contentWindow)
        doc=tmcMPU.contentWindow.document;
    doc.open();
    doc.writeln(txt);
    doc.close();
   
}