﻿// trims leading and trailing spaces from a string
function trim(s)
{
	while (s.substring(0, 1) == ' ')
	{
		s = s.substring(1, s.length);
	}
	
	while (s.substring(s.length-1, s.length) == ' ')
	{
		s = s.substring(0, s.length-1);
	}

	return s;
}

// retrieves a value of a query string key
function queryString(key)
{
	var args = new Object();
	var query = location.search.substring(1); 
	var pairs = query.split("&"); 
	
	for(var i = 0; i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf('='); 

		if (pos == -1)
			continue;
		
		var argname = pairs[i].substring(0,pos); 	
		var value = pairs[i].substring(pos+1); 
	
		if (trim(argname) == trim(key))
			return trim(value);
	}

	return "";
}


// Client side postback functionality
if (window.ActiveXObject && !window.XMLHttpRequest)
{
    window.XMLHttpRequest = function()
    {
        return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
    };
}

function getHttpResponse(sURL)
{
	try
	{
		var oXMLHTTP = new XMLHttpRequest();

		oXMLHTTP.open("GET", sURL, false);
		oXMLHTTP.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		oXMLHTTP.setRequestHeader("content-length", 0);
		oXMLHTTP.send("");
	
		if (oXMLHTTP.readyState < 4 || (oXMLHTTP.status != 0 && oXMLHTTP.status != 200 && oXMLHTTP.status != 201))
		{
			alert("Client Side Postback Error: Postback to URL " + trim(sURL) + " has failed.");
			return;
		}
		else if (oXMLHTTP.responseText != null && trim(oXMLHTTP.responseText) != "")
		{
			return oXMLHTTP.responseText;
		}
	}
	catch(e)
	{
	}
}

function raiseError(message)
{
    alert("ERROR: " + message);
}

function gotoLicenseGenerator()
{
    document.location.href = "../License/LicenseGenerator.aspx";
}

function gotoLicenseGeneratorIntro()
{
    document.location.href = "../Steps/Start.aspx";
}

function BacktoParties()
{
    document.location.href = "../Steps/Parties.aspx";
}

// help window functions
function openMediaMatrixHelp()
{
    //var helpWindow = window.open("../Help/Definitions.html?aMediaMatrix", "Help", "top=50,left=350,width=650,height=720,scrollbars=1,status=0");

    var helpWindow = window.open("http://plus.ozmo.com/genhelp.htm", "Help", "top=50,left=350,width=700,height=720,scrollbars=1,status=0");

	if (helpWindow && helpWindow.open)
	{
		helpWindow.focus();
	}
	else
	{
		alert("Your browser's pop-up blocker is preventing the term window from displaying on your screen. " +
	    	"Please set your pop-up blocker to allow this site to open the window.");
    }    
}

function openMediaMatrixInformation()
{
    var helpWindow = window.open("../Help/Definitions.html?aMediaMatrix", "Help", "top=50,left=350,width=650,height=720,scrollbars=1,status=0");

	if (helpWindow && helpWindow.open)
	{
		helpWindow.focus();
	}
	else
	{
		alert("Your browser's pop-up blocker is preventing the term window from displaying on your screen. " +
	    	"Please set your pop-up blocker to allow this site to open the window.");
    }    
}

function showMore()
{
    if (document.getElementById("divMore").style.display=="none")
    {
        document.getElementById("divMore").style.display = "block";
        document.getElementById("lnkMore").innerHTML = "Hide";
    }
    else
    {
        document.getElementById("divMore").style.display = "none";
        document.getElementById("lnkMore").innerHTML = "More";
    }
}

function openMediaCodeHelp()
{
    var helpWindow = window.open("../Help/Definitions.html?aMediaCode", "Help", "top=50,left=350,width=650,height=720,scrollbars=1,status=0");

	if (helpWindow && helpWindow.open)
	{
		helpWindow.focus();
	}
	else
	{
		alert("Your browser's pop-up blocker is preventing the term window from displaying on your screen. " +
	    	"Please set your pop-up blocker to allow this site to open the window.");
    }    
}

function StartOver()
{
    if (confirm('Are you sure that you want to start over and lose all of the information you have already entered?')) 
    {
        document.location.href = "../Steps/Start.aspx?StartOver=y";
    }
    
}
function openMediaSummaryCodeHelp()
{
    var helpWindow = window.open("../Help/Definitions.html?aMediaSummaryCode", "Help", "top=50,left=350,width=650,height=720,scrollbars=1,status=0");

	if (helpWindow && helpWindow.open)
	{
		helpWindow.focus();
	}
	else
	{
		alert("Your browser's pop-up blocker is preventing the term window from displaying on your screen. " +
	    	"Please set your pop-up blocker to allow this site to open the window.");
    }    
}

function activateField(field)
{   
    document.getElementById(field).disabled = false;
    document.getElementById("spn" + field).style.display = "none";     
}

function saveMulti(field) 
{
    if (trim(document.getElementById("txt" + field).value) == "" ) {
        alert('You must first enter a value for this field.');
        return;
    }
    else {
        var selbox = document.getElementById("lst" + field)
        if (selbox.options.length >=3) {
            alert('You cannot add more than three values for this field.');
            document.getElementById("txt" + field).value = "";
            return;
        }
        var optn = document.createElement("OPTION");
        optn.text = document.getElementById("txt" + field).value;
        optn.value = document.getElementById("txt" + field).value;
        selbox.options.add(optn);
        document.getElementById("txt" + field).value = "";
        document.getElementById("hid" + field).value = "";
        var hidString = ""
        for (i=0; i<selbox.options.length; i++) {
            hidString += document.getElementById("lst" + field).options[i].value + ";";  
        }
        document.getElementById("hid" + field).value = hidString.substr(0, hidString.length-1);
        document.getElementById("txt" + field).focus();
        
    }
}

function openPlusId()
{
    var helpWindow = window.open("../Help/PlusId.html", "PlusId", "top=50,left=350,width=425,height=120,scrollbars=0,status=0");

	if (helpWindow && helpWindow.open)
	{
		helpWindow.focus();
	}
	else
	{
		alert("Your browser's pop-up blocker is preventing the term window from displaying on your screen. " +
	    	"Please set your pop-up blocker to allow this site to open the window.");
    }    
}
