﻿// ** MPG Additions - 6/9/2010 **
function GeneratePostForm(formCode, formID, iWidthpx, iHeightpx, strTrackingType, strQuery)
{
    var strTemp = "";
    var strQueryString = "";
	var strTempQueryString = "";
	var strURL = "http://leads.post.edu/webforms/inquiryforms/view_form.asp?cellWidth=70&formID=" + formID + "&inqSource=" + formCode + "&style=Light"
    
    //Marcelo wants to use URL's again!!!, oh no he does not!!!
    if(strTrackingType == 'COOKIE' || strTrackingType == 'BOTH')
    {
		strTempQueryString = SetTrackingCookieToTrackingQueryString("CLIENT_TRACKING");		
	
        if(strTempQueryString.length > 1)
        {
		    strQueryString += '&' + unescape(strTempQueryString);
        }    
    }
    
    if(strTrackingType == 'QUERYSTRING' || strTrackingType == 'BOTH')
    {       
        if(strQuery.length > 1)
        {
		    if(strQuery.charAt(0) == '?')
		    {
			    strQueryString += '&' + unescape(strQuery.substr(1));
		    }
		    else
		    {
			    strQueryString += '&' + unescape(strQuery);
		    }
        }    
    }    
	
    strTemp += '<iframe allowtransparency="true" background-color="transparent" style="filter: chroma(color=#FFFFFF);height:'+iHeightpx+'px;width:'+iWidthpx+'px;" src="' + strURL ;
    strTemp += strQueryString;
    strTemp += '" name="PostForm_' + formID + '" scrolling=no frameborder=no align=top marginwidth=0 marginheight=0></iframe>';
    
    //strTemp = strQueryString;   
    //alert("GenerateForm:strTemp:" + strTemp);
    
    return(strTemp);
}


// ** END OF MPG ADDITIONS **

// JScript File
//This is the main function that inserts the form via transparent iFrame
// Typical USAGE inside a HTML file e.g. <script type='text/javascript'>window.document.write(GenerateForm('forsm.post.ikaptivate.com', 123456, 280, 345, window.location.search));</script>
function GenerateForm(strFormDNS, lAID, iWidthpx, iHeightpx, strTrackingType, strQuery)
{
    var strTemp = "";
    var strQueryString = "";
	var strTempQueryString = "";
    
    //Marcelo wants to use URL's again!!!, oh no he does not!!!
    if(strTrackingType == 'COOKIE' || strTrackingType == 'BOTH')
    {
		strTempQueryString = SetTrackingCookieToTrackingQueryString("CLIENT_TRACKING");		
	
        if(strTempQueryString.length > 1)
        {
		    strQueryString += '&' + unescape(strTempQueryString);
        }    
    }
    
    if(strTrackingType == 'QUERYSTRING' || strTrackingType == 'BOTH')
    {       
        if(strQuery.length > 1)
        {
		    if(strQuery.charAt(0) == '?')
		    {
			    strQueryString += '&' + unescape(strQuery.substr(1));
		    }
		    else
		    {
			    strQueryString += '&' + unescape(strQuery);
		    }
        }    
    }    
	
    strTemp += '<iframe allowtransparency="true" background-color="transparent" style="filter: chroma(color=#FFFFFF);height:'+iHeightpx+'px;width:'+iWidthpx+'px;" src="' + strFormDNS + '/appsynthesis/applicationdata/start.asp?AID=' + lAID;
    strTemp += strQueryString;
    strTemp += '" name="iKaptivateForm_' + lAID + '" scrolling=no frameborder=no align=top marginwidth=0 marginheight=0></iframe>';
    
    //strTemp = strQueryString;   
    //alert("GenerateForm:strTemp:" + strTemp);
    
    return(strTemp);
}
var DOMinccfg = null;

function GenerateInquiryPopDownLink(iWidthpx, iHeightpx, strQuery, strLinkText, strLinkText)
{
    var strTemp = "";

    DOMinccfg={
    // CSS classes
    // trigger DOMinclude
    triggerClass:'DOMpop',
    // class of the popup
    popupClass:'popup',
    // class of the link when the popup
    // is open
    openPopupLinkClass:'popuplink',
    // text to add to the link when the
    // popup is open
    displayPrefix:strLinkText,
    // filter to define which files should
    // not open in an iframe
    imagetypes:'',
    // dimensions of the popup
    frameSize:[iWidthpx,iHeightpx]
    }
    
    //Create the object
    DOMinclude.init();

    strTemp += '<a href="http://forms.post.ikaptivate.com/appsynthesis/applicationdata/start.asp?AID=203209';
    if(strQuery.length > 1)
    {
      strTemp += '&' + strQuery.substr(1);
    }
    strTemp += '" class="DOMpop">' + strLinkText + '</a>';
    
    return(strTemp);   
}

function SetTrackingCookieToTrackingQueryString(strCookieName)
{
    var queryString = "";  
	var pairs = new String(window.document.cookie).split(";");	
	var tmp, cookieName, keyName;
	
    //alert("Cookie in browser for POST domain:" + window.document.cookie);
    //alert("getCookie:" + getCookie ( strCookieName ));	
	
	for (var i=0 ; i<pairs.length; i++)
	{
	    //alert(unescape(pairs[i]).indexOf(unescape(strCookieName)));
	    if(unescape(pairs[i]).indexOf(unescape(strCookieName)+'=') >= 0)
	    {    
	        //Remove the head part
            queryString = unescape(pairs[i]).replace(unescape(strCookieName)+'=','');
            queryString = queryString.replace(' ', '');
            //alert(queryString);            
	    }
	}
	
	//alert("queryString sent to iKap->" + queryString);
	
	return(queryString);
}

function getCookie ( cookie_name )
{
  var results = window.document.cookie.match ( escape(cookie_name) + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}

function QueryString() 
{
	var data = [];
	this.Read = function() 
	{
		var aPairs, aTmp;
		var queryString = new String(window.location.search);
		queryString = queryString.substr(1, queryString.length); //remove "?"
		aPairs = queryString.split("&");	
		
		for (var i=0 ; i<aPairs.length; i++)
		{
			aTmp = aPairs[i].split("=");
			data[aTmp[0]] = aTmp[1];
		}
	}
	
	this.GetValue = function( key )
	{
		return data[key];
	}
	this.SetValue = function( key, value )
	{
		if (value == null)
			delete data[key];
		else 
			data[key] = value;
	}
	this.ToString = function()
	{
		var queryString = new String(""); 
		
		for (var key in data)
		{	
			if (queryString != "")
				queryString += "&"
			if (data[key])
				queryString += key + "=" + data[key];		
		}
		if (queryString.length > 0)
			return "?" + queryString;
		else
			return queryString;
	}
	this.Clear = function()
	{
		delete data;
		data = [];
	}
}


function Cookies() 
{
	var cookieData = [];
	
	this.Read = function()
	{
		var pairs = new String(window.document.cookie).split(";");	
		var tmp, cookieName, keyName;
		for (var i=0 ; i<pairs.length; i++)
		{
			tmp = pairs[i].split("=");
			
			if (tmp.length == 3)
			{
				cookieName = new String(tmp[0]);
				cookieName = cookieName.replace(" ", "");
				
				if (cookieData[cookieName] == null)
					cookieData[cookieName] = [];
				cookieData[cookieName][tmp[1]] = unescape(tmp[1]);
			}
			else //length = 2
			{
				keyName = tmp[0];
				keyName = keyName.replace(" ", "");
				if (keyName.substring(0,12)!="ASPSESSIONID") 
				{
					if (cookieData[""] == null)
						cookieData[""] = [];
					cookieData[""][keyName] = unescape(tmp[1]);
				}
			}	
		}	
		
	}
	
	this.GetValue = function( cookie, key )
	{
		if (cookieData[cookie] != null)
			return cookieData[cookie][key];
		else
			return null;
	}
	this.SetValue = function( cookie, key, value )
	{
		if (cookieData[cookie] == null)
			cookieData[cookie] = [];
		cookieData[cookie][key] = value;
	}
	this.Write = function()
	{
	
		var toWrite;
		var thisCookie;
		var expireDateKill = new Date();
		var expireDate = new Date();
		expireDate.setYear(expireDate.getFullYear() + 10);
		expireDateKill.setYear(expireDateKill.getFullYear() - 10);


		var pairs = new String(window.document.cookie).split(";");	
		var tmp, cookieName, keyName;
		for (var i=0 ; i<pairs.length; i++)
		{
			tmp = pairs[i].split("=");
			if (tmp.length == 3)	
			{		
				window.document.cookie = tmp[0] + "=" + tmp[1] + "='';expires=" + expireDateKill.toGMTString();
			}
			else
			{
				keyName = tmp[0];
				keyName = keyName.replace(" ", "");
				if (keyName.substring(0,12)!="ASPSESSIONID") 
					window.document.cookie = keyName + "='';expires=" + expireDateKill.toGMTString();
			}
		}

		for (var cookie in cookieData)
		{
			toWrite = "";
			thisCookie = cookieData[cookie];
			for (var key in thisCookie)
			{
				if (thisCookie[key] != null)
				{
					if (cookie == "")
						toWrite = key + "=" + thisCookie[key];
					else
						toWrite = cookie + "=" + key + "=" + escape(thisCookie[key]);						
					toWrite += "; expires=" + expireDate.toGMTString();
					window.document.cookie = toWrite;	
				}
			}
		}
	}
	this.ToQueryString = function(strCookie)
	{
		var queryString = new String(""); 
		
		var toWrite;
		var thisCookie;

		for (var cookie in cookieData)
		{
			toWrite = "";
			thisCookie = cookieData[cookie];
			
			for (var key in thisCookie)
			{	
				if (thisCookie[key] != null)
				{
        			alert("thisCookie[key]:" + thisCookie[key]);
							
					if (cookie == "")
						toWrite = key + "=" + thisCookie[key];
					else
						toWrite = cookie + "=" + key + "=" + escape(thisCookie[key]);						
					toWrite += "&";
					queryString += toWrite;	
				}
			}
		}
		
		return(queryString);		
	}	
}


