/**
 * VisualDNA API
 *
 * @author Imagini 
 */

var VDNA_urls = { 
	live: "http://gateway-lite.visualdna.com/vdna_api.php",
	staging: "http://gateway-lite.staging.visualdna.com/vdna_api.php",
	dt: "http://gateway-lite.deploytest.visualdna.com/vdna_api.php",
	vm: "http://gateway-lite.vm.visualdna.com/vdna_api.php"
}
var VDNA_url = VDNA_urls.live;

var VDNA_enableVDNABank = true;
var VDNA_cookieName = "vdnaUserId";
var VDNA_permCookieName = "vdnaUserPermission";
var VDNA_userAskedCookieName = "vdnaUserAskedAboutPermission";

var xmlhttp;
var VDNA_userPermission;
var VDNA_lastUserResponse;
var VDNA_userProfile;
var VDNA_userFeedback;
var VDNA_userID;
var VDNA_safariNewUser = false;
var VDNA_safariUpdateCookie = false;
var VDNA_setComplete;
var VDNA_error = '';
var VDNA_answer = '';
var VDNA_functionNameCalled = new Array(); // used to know what function was called, to know to call it again after the permission is set  

/**
 * Fetches UserService id for current user
 *
 */
function VDNA_GetUserID()
{
	if (VDNA_LocalCookieExists(VDNA_cookieName)) 
	{
		VDNA_userID = VDNA_GetInfoFromCookie(VDNA_cookieName);
		return VDNA_userID;
	}
	else 
	{
		if (VDNA_enableRemoteCookies)
		{
			if (VDNA_RequestPeriodOver()) 
			{
				VDNA_GetUserIDRemote();
			}
			else 
			{
				return 0;
			}
		}
		else
		{
			if (!VDNA_LocalCookieExists(VDNA_permCookieName))
			{
				VDNA_SetUpInfoCookie(VDNA_permCookieName, 'true');
			}
		}
	}
}

/**
 * Determines if a client has access to a user's VDNA data
 *
 */
function VDNA_getClientPermission()
{
	if (VDNA_functionNameCalled.length > 0 && !VDNA_LocalCookieExists(VDNA_userAskedCookieName) && VDNA_enableVDNABank == true)
		return false;

	if (!VDNA_LocalCookieExists(VDNA_userAskedCookieName) && VDNA_enableVDNABank == true && VDNA_LocalCookieExists(VDNA_cookieName))  
	{
		callback = 'VDNA_processGetClientPermission';
		var url = VDNA_url + '?method=api.soa.us.getClientPermission&param1=' +  VDNA_config.userID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; 
		var headID = document.getElementsByTagName("head")[0];
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = url; 
		headID.appendChild(newScript);
		
		return false;
	}
	
	return true;
}

/*
* Method that processes the client's permission over user VDNA data
*
*/
function VDNA_processGetClientPermission(jsonObj)
{
	if (jsonObj['@attributes'].stat == 'ok')
	{
		if (jsonObj.userPermission['@attributes'].permission == '0')
		{
			VDNA_show_modal();
		}
		else
		{
			if (jsonObj.userPermission['@attributes'].permission == '1')
			{
				VDNA_SetUpInfoCookie(VDNA_userAskedCookieName, 'true');
				if (VDNA_functionNameCalled.length > 0)
				{
					for (var i=0; i<VDNA_functionNameCalled.length; i++)
						eval(VDNA_functionNameCalled[i]);
					VDNA_functionNameCalled = new Array();
				}
			}
		}
	}	
	else 
	{
		if (jsonObj['@attributes'].stat == 'fail')
			alert(jsonObj.err['@attributes'].msg);
	}
}

/*
* Method that processes the user permission response
*
*/
function VDNA_processUserResponse()
{
	if (VDNA_answer != '')
	{
		switch(VDNA_answer)
		{
			case 'true':
			  VDNA_SetUpInfoCookie(VDNA_userAskedCookieName, 'true');
			  VDNA_setClientPermission(1);
			  break;
			case 'false':
			  VDNA_SetUpInfoCookie(VDNA_userAskedCookieName, 'false');
			  break;
			default:
			  VDNA_SetUpInfoCookie(VDNA_userAskedCookieName, '24h');
			  break;
		}
	
	}
	if (VDNA_functionNameCalled.length > 0)
	{
		for (var i=0; i<VDNA_functionNameCalled.length; i++)
			eval(VDNA_functionNameCalled[i]);
		VDNA_functionNameCalled = new Array();
	}
}

/**
 * Sets client's permission to the user's VDNA data
 *
 */
function VDNA_setClientPermission(val)
{
	callback = 'VDNA_processSetClientPermission';
	var url = VDNA_url + '?method=api.soa.us.setClientPermission&param1=' +  VDNA_config.userID + '&param2=' + val + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&format=json&v=1' + '&callback=' + callback; 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = url; 
	headID.appendChild(newScript);
}

/*
* Method that processes the response from the server when VDNA_setClientPermission() function it's called
*
*/
function VDNA_processSetClientPermission(jsonObj)
{
	if (jsonObj['@attributes'].stat == 'fail')
		alert(jsonObj.err['@attributes'].msg);
}

/*
* Method that determines if the entered value is an integer or not(utility function)
*
*/
function isInt(x)
{
	var y = parseInt(x);
	if (isNaN(y)) return false;
	return x == y && x.toString() == y.toString();
}

/*
* Method called by VDNA flash app to determine the current domain name (utility function)
*
*/
function VDNA_getCookieDomain()
{
	var thisDomain = document.domain;
	var domainArr = thisDomain.split(".");
	var isIP = true;
	for (var i = 0; i < domainArr.length; i++)
	{
		if (!isInt(domainArr[i]))
			var isIP = false;
	}
	if (!isIP)
		thisDomain = '.' + domainArr[domainArr.length-2] + "." + domainArr[domainArr.length-1];
	
	return thisDomain;
}

/*
* Verifies if local cookie exists or not
*
*/
function VDNA_LocalCookieExists(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{
			return true;
		}
	}
	return false;
}

/*
* Parse local cookie data
*
*/
function VDNA_GetInfoFromCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) 
			{
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return false;
}

/*
* Write data to cookie
*/
function VDNA_SetUpInfoCookie(name, infoStr)
{
	var availability = 1000 * 60 * 60 * 24 * 356 * 10; // ten years
	if (name == 'vdnaTimestamp')
	{
		infoStr = Math.round(new Date().getTime() / 1000);
	}
	
	if (name == VDNA_cookieName || infoStr == '24h') // 24h for asked permission cookie (don't allow)
	{
		if (infoStr == 0)
			return false;
		availability = 1000 * 60 * 60 * 24; // one day
	}	
	
	//cookie val: timestamp;
	var thisDomain = VDNA_getCookieDomain();

	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );	
	var expires_date = new Date( today.getTime() + availability ); // one year
	document.cookie = name + "=" + escape(infoStr) +
					  ";expires=" + expires_date.toGMTString() +
					  ";path=/" +
					  ";domain=" + thisDomain;
}	

/*
* Write data to cookie
*/
function VDNA_DeleteLocalCookie(name)
{
	var thisDomain = VDNA_getCookieDomain();
	var deleteTime = 'Thu, 01-Jan-1970 00:00:01 GMT';
	document.cookie = name + "=0" + 
					  ";expires=" + deleteTime +
					  ";path=/" +
					  ";domain=" + thisDomain;
}	

/*
* Verifies that the time period from the former request is over 24h
*
*/
function VDNA_RequestPeriodOver()
{
	var cookieTimestamp = VDNA_GetInfoFromCookie('vdnaTimestamp');
	if (!cookieTimestamp) 
	{
		return true;
	}
	
	var timestamp = Math.round(new Date().getTime() / 1000);
	if (timestamp - cookieTimestamp > 60*60*24) // period passed is biger than 24h we try again :)
	{
		return true;
	}
	return false;	
}

/*
* Return user id from remote cookie, if available
*
*/
function VDNA_GetUserIDRemote()
{
	if ( (VDNA_userID === false || VDNA_userID == undefined || VDNA_userID == 'false') && VDNA_error == '')
	{
		var headID = document.getElementsByTagName("head")[0];
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = VDNA_url + '?format=json&method=api.vdna.getRemoteCookie&v=1&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_GetUserIDRemoteValue'; 
		headID.appendChild(newScript);
	
		setTimeout('VDNA_GetUserIDRemote()',300);
	}
	else
	{
		if (VDNA_error != '')
		{
			alert(VDNA_error);
			VDNA_error = '';
		}
		else
		{	
			VDNA_SetUpInfoCookie('vdnaTimestamp', '');
			VDNA_SetUpInfoCookie(VDNA_cookieName, VDNA_userID);
			VDNA_SetUpInfoCookie(VDNA_permCookieName, VDNA_userPermission);
		}
	}
}

/*
* Takes the new cookie values from the remote host
*
*/
function VDNA_RefreshCookieValues()
{	
	var headID = document.getElementsByTagName("head")[0];
        var newScript = document.createElement('script');
        newScript.type = 'text/javascript';
        newScript.src = VDNA_url + '?format=json&method=api.vdna.getRemoteCookie&v=1&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_GetUserIDRemoteValue';
	headID.appendChild(newScript);
}

/*
* Works togheter with VDNA_GetUserIDRemote() and VDNA_RefreshCookieValues() functions, setting the values from json object
*
*/
function VDNA_GetUserIDRemoteValue(jsonObj)
{
	if (jsonObj['@attributes'].stat == 'fail')
	{
		VDNA_error = jsonObj.err['@attributes'].msg;
		alert(VDNA_error);
	}
	else
	{
		VDNA_userID = jsonObj.data.vdnaUserId['@value'];
                VDNA_config.userID = VDNA_userID;
                VDNA_userPermission = jsonObj.data.vdnaUserPerm['@value'];
		
		VDNA_SetUpInfoCookie('vdnaTimestamp', '');
                VDNA_SetUpInfoCookie(VDNA_permCookieName, VDNA_userPermission);
		if (VDNA_userID == 0)
			VDNA_DeleteLocalCookie(VDNA_cookieName);
		else
			VDNA_SetUpInfoCookie(VDNA_cookieName, VDNA_userID);
	}
}

/*
* Returns last response for a given module
* 
*/
function VDNA_GetLastResponse(moduleID, callback)
{
	if (!VDNA_getClientPermission())
	{
		var thisFunction = 'VDNA_GetLastResponse(' + moduleID + ', "' + callback + '")';
		VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction;
		return false;
	}

	if (callback == null)
		callback = 'VDNA_processLastUserResponse';
	var url = VDNA_url + '?method=api.soa.us.getLastUserResponse&param1=' +  VDNA_config.userID + '&param2=' + moduleID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = url; 
	headID.appendChild(newScript);
}

/*
* Returns response data for a given response id
* 
*/
function VDNA_GetUserResponse(responseID, callback)
{
	if (!VDNA_getClientPermission())
	{
		var thisFunction = 'VDNA_GetUserResponse(' + responseID + ', "' + callback + '")';
		VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction;
		return false;
	}

	if (callback == null)
		callback = 'VDNA_processResponse';
	var url = VDNA_url + '?method=api.soa.us.getUserFullResponse&param1=' +  VDNA_config.userID + '&param2=' + responseID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = url; 
	headID.appendChild(newScript);
}

/*
* Returns response data for a shared response id
* 
*/
function VDNA_GetSharedResponse(responseID, callback)
{
	if (!VDNA_getClientPermission())
	{
		var thisFunction = 'VDNA_GetSharedResponse(' + responseID + ', "' + callback + '")';
		VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction;
		return false;
	}

	if (callback == null)
		callback = 'VDNA_processSharedResponse';
	var url = VDNA_url + '?method=api.soa.us.getFullResponse&param1=' + responseID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = url; 
	headID.appendChild(newScript);
}

/*
* Returns user profile
* 
*/
function VDNA_GetUserProfile(callback)
{
	if (!VDNA_getClientPermission())
	{
		var thisFunction = 'VDNA_GetUserProfile("' + callback + '")';
		VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction;
		return false;
	}

	if (callback == null)
		callback = 'VDNA_processUserProfile';
	var url = VDNA_url + '?method=api.soa.us.getUserProfile&param1=' + VDNA_config.userID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = url; 
	headID.appendChild(newScript);
}

/*
* Returns response feedback data
* 
*/
function VDNA_GetUserFeedback(responseID, schema_id, callback)
{
	if (!VDNA_getClientPermission())
	{
		var thisFunction = 'VDNA_GetUserFeedback(' + responseID + ', ' + schema_id + ', "' + callback + '")';
		VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction;
		return false;
	}

	if (callback == null)
		callback = 'VDNA_processUserFeedback';
	var url = VDNA_url + '?method=api.soa.us.getUserFeedback&param1=' + responseID + '&param2=' + escape('<applicationData></applicationData>') + '&param3=' + schema_id + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = url; 
	headID.appendChild(newScript);
}

/*
*  Write user id to cookie, function called from Flash
* 
*/
function VDNA_FlashGetUserID(user_id)
{
	// set cookie on local domain
	VDNA_SetUpInfoCookie(VDNA_cookieName, user_id);

	// adding userid to the config var
	VDNA_config.userID = user_id
	VDNA_userID = user_id;

	//In case of Safari 
	if (/Safari/.test(navigator.userAgent)) 
		VDNA_safariNewUser = true;

	// set cookie on remote domain (my.visualdna.com) 
	var scriptUrl = VDNA_url + '?format=json&method=api.vdna.setRemoteCookie&v=1&param1=' + user_id + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_SetCompleteRemoteValue'; 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = scriptUrl;
	headID.appendChild(newScript);
}	

/*
* In case of Safari redirect user to my.visualdna.com site for cookie saving
* 
*/
function VDNA_Redirect(resultsPage, target)
{
	VDNA_userPerm = VDNA_GetInfoFromCookie(VDNA_permCookieName);
	if ( (VDNA_safariNewUser == true && VDNA_safariUpdateCookie == false) )
	{
		var scriptUrl = VDNA_url + '?format=json&method=api.vdna.setRemoteCookie&v=1&param1=' + VDNA_userID + '&param2=&param3=' + escape(resultsPage) + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash; 
		document.location.assign(scriptUrl);
		return false;
	}
	
	if (VDNA_safariUpdateCookie == true)
	{
		if (VDNA_userPerm == 'true')
		{
			var scriptUrl = VDNA_url + '?format=json&method=api.vdna.setRemoteCookie&v=1&param1=&param2=%22' + VDNA_userPerm + '%22&param3=' + escape(resultsPage) + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash; 
			document.location.assign(scriptUrl);
		}
		if (VDNA_userPerm == 'false')
		{
			var scriptUrl = VDNA_url + '?format=json&method=api.vdna.deleteRemoteCookie&v=1&param1=' + escape(resultsPage) + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash; 
			document.location.assign(scriptUrl);
		}
		return false;
	}

	document.location.assign(resultsPage);
}

/*
* wait first for response and then redirect
* 
*/
function VDNA_WaitAndRedirect(resultsPage)
{
	if (VDNA_setComplete !== true)
	{
		setTimeout('VDNA_WaitAndRedirect("' + resultsPage + '");', 100);
		return false;
	}

	return VDNA_Redirect(resultsPage);
}

/*
* Works togheter with VDNA_FlashGetUserID() and VDNA_FlashGetUserPerm() and VDNA_DeleteCookie() functions, getting the values from json object
*
*/
function VDNA_SetCompleteRemoteValue(jsonObj)
{
  if (jsonObj['@attributes'].stat == 'fail' && jsonObj.err['@attributes'].msg != 'No vdnaUserId cookie set')
	{
		alert(jsonObj.err['@attributes'].msg);
	}
	else
	{
		VDNA_setComplete = true;
	}
}

/*
*  function for unsetting "Save my VisualDNA"
* 
*/
function VDNA_FlashSetVDNA(bool)
{
	//In case of Safari 
	if (/Safari/.test(navigator.userAgent)) 
		VDNA_safariUpdateCookie = true;
	
	if (bool == 'false') 
	{
		var confText = 'Saving your VisualDNA is recommended, as it allows you to have a more personalised web experience.' +
		'\n\nWe respect your privacy and your VisualDNA is under your control at all times -' +
		' simply go to my.visualdna.com to opt-out or manage your VisualDNA.' +
		'\n\nAre you sure you want to change this setting?';
		var conf = confirm(confText);
		
		if (conf) 
		{
			VDNA_SetUpInfoCookie(VDNA_permCookieName, 'false');
			VDNA_DeleteCookie();
			return 'false';
		}
		
		return 'true';
	}
	else 
	{
		if (bool == 'true') 
		{
			VDNA_FlashGetUserPerm('true');
			return 'true';
		}
	}
}	

/*
*  Delete user id cookie and all the association between him and his responses
* 
*/
function VDNA_DeleteCookie()
{
	// delete cookie on local domain
	VDNA_DeleteLocalCookie(VDNA_cookieName);
	VDNA_DeleteLocalCookie(VDNA_userAskedCookieName);

	//In case of Safari we solve this by redirect, else we do it this way
	if (!/Safari/.test(navigator.userAgent)) 
	{
		// delete cookie on remote domain(my.visualdna.com) an remove associations 
		var headID = document.getElementsByTagName("head")[0];
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = VDNA_url + '?format=json&method=api.vdna.deleteRemoteCookie&v=1&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_SetCompleteRemoteValue'; 
		headID.appendChild(newScript);
	}
}

/*
* Get user id from cookie, function called from Flash
* 
*/
function VDNA_FlashSendUserID()
{
	VDNA_userID = VDNA_GetInfoFromCookie(VDNA_cookieName);
	return VDNA_userID;
}	

/*
*  Write user permission to cookie, function called from Flash or JS
* 
*/
function VDNA_FlashGetUserPerm(bool)
{
	// set cookie on local domain
	VDNA_SetUpInfoCookie(VDNA_permCookieName, bool);

	// set cookie on remote domain (my.visualdna.com) 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = VDNA_url + '?format=json&method=api.vdna.setRemoteCookie&v=1&param1=&param2=%22' + bool + '%22&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_SetCompleteRemoteValue';
    headID.appendChild(newScript);
}	

/*
* Get user permission from cookie, function called from Flash or JS
* 
*/
function VDNA_FlashSendUserPerm()
{
	VDNA_userPerm = VDNA_GetInfoFromCookie(VDNA_permCookieName);
	return VDNA_userPerm;
}	

/*
*  External interface check for Flash
*
*/
function VDNA_FlashHasExternalInterface()
{
	return true;
}

/*
* Close the permission modal 
* 
*/
function VDNA_modalClose() {

	x = document.getElementById('permModal');
	x.parentNode.removeChild(x);

	x = document.getElementById('modalDataContainer');
	x.parentNode.removeChild(x);

    document.body.style.overflow = 'auto';
}

/*
* Open the permission modal 
* 
*/
function VDNA_modalClose() {

	x = document.getElementById('permModal');
	x.parentNode.removeChild(x);

	x = document.getElementById('modalDataContainer');
	x.parentNode.removeChild(x);

	document.body.style.overflow = 'auto';
}

/*
* Open the permission modal 
* 
*/
function VDNA_show_modal() 
{
	var left = (VDNA_getWindowWidth() - 400)/2 + "px",
	domain = VDNA_getCookieDomain(),
	timestamp = Math.round(new Date().getTime() / 1000);

	VDNA_answer = 'true';	
	
	/* outer */
	var modalContainerOuter = document.createElement('div');
	modalContainerOuter.setAttribute('id', 'modalDataContainer');
	modalContainerOuter.style.fontFamily = 'font-family: Arial, "Helvetica Neue", Helvetica, sans-serif';
	modalContainerOuter.style.fontSize = '15px';
	modalContainerOuter.style.lineHeight = '18px';
	modalContainerOuter.style.textAlign = 'left';
	modalContainerOuter.style.color = '#999999';
	modalContainerOuter.style.backgroundColor = '#eeeeee';
	modalContainerOuter.style.position = 'absolute';
	modalContainerOuter.style.margin = '0';
	modalContainerOuter.style.padding = '0';
	modalContainerOuter.style.fontWeight = 'normal';
	modalContainerOuter.style.fontStyle = 'normal';
	modalContainerOuter.style.textTransform = 'none';
	modalContainerOuter.style.left = left;
	modalContainerOuter.style.top = '90px';
	modalContainerOuter.style.zIndex = 1001;
	modalContainerOuter.style.width = '406px';
	
	/* container */
	var modalContainer = document.createElement('div');
	modalContainer.style.zIndex = 1001;
	modalContainer.style.borderColor = '#a9a9a9';
	modalContainer.style.borderWidth = '6px';
	modalContainer.style.borderStyle = 'solid';
	
	/* inner */
	var modalContainerInner = document.createElement('div');
	modalContainerInner.style.padding = '25px 18px 13px 18px';
	modalContainerInner.style.zIndex = 1001;
	modalContainerInner.innerHTML = '<p style="font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 15px; line-height: 18px; text-align: left; color: #999; margin: 2px 0 17px 0; padding: 0 40px; font-weight: normal; font-style: normal; text-transform: none;"><a href="http://my.visualdna.com" target="_blank" title="visualdna.com" style="font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 15px; line-height: 18px; color: #000000; font-weight: bold; text-decoration: none;">' + domain.substr(1, domain.length) + '</a> wants permission to access your VisualDNA and give you a more personalized experience.</p>'+
							   '<ul style="list-style: none; list-style-image: none; margin: 0; padding: 0 40px;">'+
							   '<li style="list-style: none; list-style-image: none; margin: 0 0 6px 0; padding: 0;"><input onclick="VDNA_answer = this.value;" type="radio" name="permission" checked="checked" value="true" id="vdnaPermAllow" /> <label for="vdnaPermAllow" style="font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 15px; line-height: 18px; text-align: left; color: #000; margin: 0; padding: 0; font-weight: bold; font-style: normal; text-transform: none;">Allow</label></li>'+
							   '<li style="list-style: none; list-style-image: none; margin: 0 0 6px 0; padding: 0;"><input onclick="VDNA_answer = this.value;" type="radio" name="permission" value="' + timestamp + '" id="vdnaPermDontAllow" /> <label for="vdnaPermDontAllow" style="font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 15px; line-height: 18px; text-align: left; color: #999; margin: 0; padding: 0; font-weight: normal; font-style: normal; text-transform: none;">Don\'t Allow</label></li>'+
							   '<li style="list-style: none; list-style-image: none; margin: 0 0 18px 0; padding: 0;"><input onclick="VDNA_answer = this.value;" type="radio" name="permission" value="false" id="vdnaPermNeverAllow" /> <label for="vdnaPermNeverAllow" style="font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 15px; line-height: 18px; text-align: left; color: #999; margin: 0; padding: 0; font-weight: normal; font-style: normal; text-transform: none;">Never Allow</label></li>'+
							   '</ul>'+
							   '<input type="hidden" value="true" id="answer" name="answer" />'+
							   '<input type="image" alt="Continue" title="Continue" src="http://media.youniverse.com/vdnaPermissionsI.gif" style="padding-left: 40px;" onclick="VDNA_processUserResponse(); VDNA_modalClose();" />'+
							   '<p style="font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 12px; line-height: 18px; text-align: left; color: #999; margin: 20px 0 0 0; padding: 0; font-weight: normal; font-style: normal; text-transform: none;">See your VisualDNA and set preferences on <a href="http://my.visualdna.com" target="_blank" title="my.visualdna.com" style="font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 12px; line-height: 18px; color: #0568ff; font-weight: normal; text-decoration: none;">my.visualdna.com</a></p>'+
							   '<div style="text-align: right; margin: 8px 0 0 0;"><a href="http://www.visualdna.com" target="_blank" title="Visit visualdna.com"><img src="http://media.youniverse.com/vdnaPermissionsII.gif" alt="VisualDNA" style="border: 0;" /></a></div>'
	
	/* modal shadow */
	var permModal = document.createElement('div');
	permModal.id = "permModal";
	permModal.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=20)';
	permModal.style.backgroundColor = '#333';
	permModal.style.position = 'absolute';
	permModal.style.top = '0';
	permModal.style.left = '0';
	permModal.style.height = '100%';
	permModal.style.width = '100%';
	permModal.style.opacity = '.2';
	permModal.style.zIndex = '1000';

	document.body.style.overflow = 'hidden';
	document.body.appendChild(permModal);
	
	modalContainer.appendChild(modalContainerInner);
	modalContainerOuter.appendChild(modalContainer);
	document.body.appendChild(modalContainerOuter);
	
	permModal.onclick = VDNA_modalClose;
}

/*
* Gets the window width so that the modal window will be always positioned on the center
* 
*/
function VDNA_getWindowWidth()
{
    var x = 0;
    if (self.innerHeight)
	    x = self.innerWidth;
    else if (document.documentElement && document.documentElement.clientHeight)
        x = document.documentElement.clientWidth;
    else if (document.body)
        x = document.body.clientWidth;

    return x;
}

