﻿// JScript File

// check for proper mpdrm components
	function doComponentCheck() {
		try {
			mpdrmobj2 = new ActiveXObject("mpDRMNETOBJLib.RMGetLicense");
			r = mpdrmobj2.GetSystemInfo();
			s = mpdrmobj.GetDRMVersion();
			if (s.indexOf("="+ DVDBurnerCoreVersion)>-1) 
			{
				document.getElementById("showInstall").innerHTML = "<hr noshade size=1 color=#666666 width=95%><table border=\"0\" cellspacing=\"0\" cellpadding=\"5\"><tr><td class=\"a12\">The CinemaNow DVD Burner is installed in your system. You are ready to purchase this movie!</td><td><img src=\"img/dvd_burner_installed_icon02.gif\" height=\"63\" width=\"161\" border=\"0\" alt=\"DVD Burner Installed\"></td></tr></table><hr noshade size=1 color=#666666 width=95%>";
				document.aspnetForm.clientinfo.value = mpdrmobj2.GetSystemInfo();
			}
			else
			{
				testtimer = setTimeout("doComponentCheck()",2000);
			}			
		} catch(e) {
			testtimer = setTimeout("doComponentCheck()",2000)
		}
	}

	function installApp() {
		window.open(DVDBurnerDownloadPath,'installWindow',"width=100,height=100");
		doComponentCheck();
	}


	function securityCode()
	{
		window.open("securitycode.aspx","new","scrollbars=no,resizable=no,location=no,status=no,toolbar=no,width=400,height=535");
	}
	
	function Privacy()
	{
		window.open("privacy.aspx","new","scrollbars=yes,resizable=yes,location=no,status=no,toolbar=no");
	}

	function Terms()
	{
		window.open("Terms.aspx","new","scrollbars=yes,resizable=yes,location=no,status=no,toolbar=no");
	}

	function BillingCountryChanged(obj)
	{
		BillingCountryChangedValue(obj.value);
	}
	
	function BillingCountryChangedValue(val)
	{
	    try
	    {
	        var dZUS = document.getElementById('dZipUS');
            var dSUS = document.getElementById('dStateUS');
            var dZInt = document.getElementById('dZipInt');
            var dSCan = document.getElementById('dStateCan');
    		
		    if (val=='usa')
	            {
	                dZUS.style.display = 'block';
				    dSUS.style.display = 'block';
    				
				    try {
				        dSecCode.style.display = 'block';
				        dSecCode1.style.display = 'block';
				        }
                    catch(e) {
                        //billing mode does not show sec code box	
                        }
                     
				    dZInt.style.display = 'none';
				    dSCan.style.display = 'none';
	            }
    	        
   		    else if (val=='can')
                {
				    dZInt.style.display = 'block';
				    dSCan.style.display = 'block';
				    dZUS.style.display = 'none';
    				
				    try {
				        dSecCode.style.display = 'none';
				        dSecCode1.style.display = 'none';
				        }
                    catch(e) {
                        //billing mode does not show sec code box	
                        }
                        
				    dSUS.style.display = 'none';
                }

   		    else
                {
				    dZInt.style.display = 'block';
				    dSCan.style.display = 'none';
				    dZUS.style.display = 'none';
    				
				    try {
				        dSecCode.style.display = 'none';
				        dSecCode1.style.display = 'none';
				    }
                    catch(e) {
                        //billing mode does not show sec code box	
                        }
    				
				    dSUS.style.display = 'none';
                }		
        }
        catch(e)
        {}
	}
	
	function hideElement(element) {
        if (element) { element.style.display = 'none'; }
    }

    function showElement(element) {
        if (element) { element.style.display = 'block'; }
    }
	
	function getCCElement() {
	    return document.getElementById("dBillingInfo");
	}
	
	function getRequiredElement() {
	    return document.getElementById("requiredMsg");
	}

    function hideCC() {
        var dC = document.getElementById("dCollapse");
	    if (dC) {
	        showElement(dC);
	        var ccElement = getCCElement();
	        if (ccElement) { hideElement(ccElement);}	
	    }        
	    var reqElement = getRequiredElement();
	    if (reqElement) { hideElement(reqElement);}	        
	}
	
	function showCC() {
	    var dC = document.getElementById("dCollapse");
	    if (dC) {
	        showElement(dC);
	        var ccElement = getCCElement();
	        if (ccElement) { showElement(ccElement);}
	    }	        
	    var reqElement = getRequiredElement();
	    if (reqElement) { showElement(reqElement);}
	}	
	
	function ToCollapseOrNot()
	{
	    try {
	        var dC = document.getElementById("dCollapse");
	        if (dC) { 
	            if (dC.style.display == 'none'){ showCC(); }	            
	            else if (document.getElementById("dBillingInfo").style.display != 'none') { hideCC(); }
	            else { showCC(); }
	        }
		} catch(e) {alert('error collapse');}
	}
	
	
	
	function ToCollapseOrNotDebit()
	{
		if (document.getElementById("debitComment").style.display != 'none')
			document.getElementById("debitComment").style.display = 'none';
		else
			document.getElementById("debitComment").style.display = 'inline';
	}
	
	function updatePrice(obj)
	{
		if (obj)
		{
			c = obj.value.split(',');
			ba = myObj('lblCCAmount')
			if (ba){myObj('lblCCAmount').innerHTML = c[2]}
		}
	}
	
	function DisableButton() 
	{
		document.body.style.cursor = 'wait';
		//document.forms[0].submit();
		window.setTimeout("disableButton('" + 
			window.event.srcElement.id + "')", 0);
	}

	function disableButton(buttonID) 
	{
		document.getElementById(buttonID).disabled=true;
	}

function isValidCustomer(){
		var d = new Date();
		var h = d.getTimezoneOffset()/60;
		var ul = UserLanguages;
		if (h>=4 && h<=11){
			return true
			//language check
			//if (ul.toLowerCase()=='en-us'){return true}
		}
		return false
	}
				
function validateCustomer(){
	//obj = document.aspnetForm.rblCash
	//obj = document.aspnetForm.paymentOptionRB
	obj = getElementsByClass("radioBtn");
	doAlert = false
	if (!isValidCustomer()){
		for (i=1;i<obj.length;i++) {
				obj[i].disabled = true;
				doAlert = true;
		}
	}
	if (doAlert){
		validationMsg.innerText += '<br />Sorry, due to certain restrictions we are unable to process this transaction using pre-paid funds. You must enter a credit card to purchase this title.'
		}
}

function openpopup(thisurl,thisname) {
	popup = window.open(thisurl,thisname,"channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,width=529,height=386,top=10,left=10")
}

function resizePaymentOptionDivs()
{
		var maxHeight = 0;
		var controlCount = 0;
		var controlArray = new Array();
		var divs = document.getElementsByTagName('div');
		
		for(var i = 0; i < divs.length; i++)
		{
			if(divs[i].className == "PaymentMethodDetails")
			{
				if(divs[i].offsetHeight > maxHeight)
				{
					maxHeight = divs[i].offsetHeight;
				}
				controlArray[controlCount] = divs[i];
				controlCount++;
			}			
		}

		for(var j = 0; j < controlCount; j++)
		{
			controlArray[j].style.height = maxHeight + "px";
		}
		
		//Fix for IE 7
		if(maxHeight > 0 && typeof document.body.style.maxHeight != "undefined")
		{
		    var v = document.getElementById('PaymentDetailHr');
		    v.style.padding = maxHeight + "px 0px 0px 0px";
		}
		
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		{ node = document; }
	if ( tag == null )
		{ tag = '*'; }
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getRadioButtonByValue(rvalue) {
	var rbls = getElementsByClass("radioBtn");
	if (rbls.length > 0)
	{
		for (i = 0; i < rbls.length; i++ )
		{
			if (rbls[i].value == rvalue)
			{
				return rbls[i];
			}
		}
	}
}

function clickRBLimage(rValue) {
	var rb1 = getRadioButtonByValue(rValue);
	if (rb1)
	{
		rb1.checked = true;
	}
}

function clickPaypalSubmit() {
    //paypalSubmit
    var ppSub = document.getElementById('paypalSubmit')
    if (ppSub) {
        ppSub.click();
    }
}

function hideTerms() {
    var terms = document.getElementById('termsDiv')
    if (terms) {terms.style.display='none'; }
}

function showTerms() {
    var terms = document.getElementById('termsDiv')
    if (terms) {terms.style.display='block'; }
}

function hideCheckoutBottom() {
    try {
        hideTerms();
        document.getElementById('submitDiv').style.display='none';
    } catch (e) {}
}

function showCheckoutBottom() {
    try {
        showTerms();
        document.getElementById('submitDiv').style.display='block';
    } catch (e) {}
}

function clickRadioShowCC() {
    showCC();
    showCheckoutBottom();
}

function clickRadioHideCC() {
    hideCC();
    showCheckoutBottom();
}


function AssociateContent() {

    try
        {
            
            if(_mm_init('normal'))
             {	
                document.getElementById("appid").value=_mm_Exec( 'GetAppID', null, null );
                //AJAXRequest("GET", 'Handler/AssociateDellContentToUser.ashx?appid=' + _mm_Exec( 'GetAppID', null, null ), null, AssociateContentCallBack, false);
             }   

        }catch(e)
        {
        //alert(e);
        }
        
    return false;

} 
                       
function AssociateContentCallBack() {
}

var paymentOptionTmr = null;
function persistPaymentOption() {
    try {
        if (document.getElementById('lblErrorMsg')) {
            if (document.getElementById('lastPaymentOption')) {
                if (document.getElementById('lastPaymentOption').value != '')
                    clickRBLimage(document.getElementById('lastPaymentOption').value);
            }
        }
        clearInterval(paymentOptionTmr);
    }
    catch (e) {
    }
}

paymentOptionTmr = setInterval(persistPaymentOption, 300);