
function intervalToString(sec){
	days = Math.floor(sec / 86400);
	hours = (sec /3600 % 24);
	minutes = (sec / 60 % 60);;
	seconds = (sec % 60);

	result = "";
	result += days;
	result += " Tag"+(Math.floor(sec / 86400) != 1 ? 'e':'');
	if(hours!=0 || minutes!=0 || seconds!=0){
		result += " ,";
		result += hours;
		result += " Stunde"+(Math.floor(sec / 3600 % 24) != 1 ? 'n':'');
		if(minutes!=0 || seconds!=0){
			result += " ,";
			result += minutes;
			result += " Minute"+(Math.floor(sec / 60 % 60) != 1 ? 'n':'');
		    if(seconds!=0){
			    result += " und";
			    result += seconds;
		        result += " Sekunde"+(Math.floor(sec % 60) != 1 ? 'n':'');
		    }
		}
	}

	return result;
}

var searchText = '';
var baseUrl = '';

function swapFieldClass(obj)
{
	if (searchText == '') {
		searchText = obj.value;
	}
	if (obj.className == 'fakeSearch') {
		obj.className = 'realSearch';
		obj.value="";
	}
	else {
		if (obj.value == '' || obj.value == searchText) {
			obj.className = 'fakeSearch';
			obj.value = searchText;
		}
		
	}
}

var professionURI = "";
var professions;
var professionValues = "";
var data;
var searching = false;
var city = "";
var country = "";
var detailLink = "";

function slideUpOnTimer()
{
	var slideUpTimer = setTimeout("slideUp()", 4000);
}

function slideUp() {
	$('.language-container').slideUp('fast');
}

function getDataOnTimeout()
{
	if (searching == false) {
		searching = true;
		var timer = setTimeout("callFunctions()", 500);
	}
}

function getVideoLibrarySearchDataOnTimeout()
{
	if (searching == false) {
		searching = true;
		var timer = setTimeout("getVideoLibrary()", 500);
	}	
}

function checkUsernameOnTimeout()
{
	if (searching == false) {
		searching = true;
		var timer = setTimeout("checkUsername()", 500);
	}
}

function checkUsername()
{
	searching = false;
	$.ajax({
		  url: '/create-account/check-username/',
		  dataType: 'json',
		  data: {username: $('#username').val()},
		  type: 'POST'
		});	
}

function checkEmailOnTimeout()
{
	if (searching == false) {
		searching = true;
		var timer = setTimeout("checkEmail()", 500);
	}
}

function checkEmail()
{
	
	searching = false;
	$.ajax({
		  url: '/create-account/check-email/',
		  dataType: 'json',
		  data: {email: $('#mail').val()},
		  type: 'POST',
		  success: function(data) {
			  alert('haha');
			if (data.success == 'true') {
				$('#mail').addClass("required-ok");
				$('#email_error').html('');
			}
			else {
				if ('do-claim' == data.error) {
					fetchClaimProfileContainer(data.id);
				}
				else {
					$('#mail').removeClass("required-ok");
					$('#email_error').html(data.error);
				}
			}
		  }
		});	
}

function checkConfirmEmailOnTimeout()
{
	if (searching == false) {
		searching = true;
		var timer = setTimeout("checkConfirmEmail()", 500);
	}
}

function checkConfirmEmail()
{
	searching = false;
	$.ajax({
		  url: '/create-account/check-email/',
		  dataType: 'json',
		  data: {email: $('#confirmmail').val(), origmail: $('#mail').val()},
		  type: 'POST',
		  success: function(data) {
			
			if (data.success == 'true') {
				$('#confirmmail').addClass("required-ok");
				$('#confirm_email_error').html('');
			}
			else {
				$('#confirmmail').removeClass("required-ok");
				$('#confirm_email_error').html(data.error);
			}
		  }
		});	
}

function vote(url)
{
	$.ajax({
		  url: url,
		  dataType: 'json',
		  data: {},
		  type: 'POST'	  
		});		
}

function callFunctions()
{
	  searching = false;
	  getPaidFeaturedDentists();
	  getStandardDentists();	
}
function getVideoLibrary()
{
	searching = false;
	var params = {'language': $('.selected-language').html(), 'word' : $('#search-video-field').val()};
	$('.video-library-search-result').load(baseUrl + '/video/video-list-by-word', params, 
			function () {
				if ('' == $('.video-library-search-result').html()) {
					$('.video-library-search-result').hide();
				}
				//$('#video-result-list div').keynav('active', '');
//				$('#video-result-list div:first').removeClass().addClass('active');

//				$('.video-library-search-result div').focus();
			}
	);
	var loader = $('#loader').html();
	$('.video-library-search-result').html(loader);
	$('.video-library-search-result').show();
	
}

function getPaidFeaturedDentists(clickedLetter)
{
		if(undefined == clickedLetter) {
			letter = '';
		}
		else {
			letter = clickedLetter;
		}
	  $('.paidfeatureddentists').html($('#loader').html());
	  professions = document.getElementsByName("profession[]");
	  professionValues = "";
	  for (var i = 0; i < professions.length; i++) {
		  if (professions[i].checked == true) {
			  professionValues += professions[i].value + ",";
		  }
	  }
	  
	  professionURI = "";
	  if (professionValues != "") {
		  professionValues = professionValues.substring(0, professionValues.length -1);
		  professionURI = "/professions/" + professionValues;
	  }	
	data = {'searchstring': $('.searchtext').val(), 'professions': professionValues, 'letter': letter, 'country': $('#country').val(), 'city': $('#city').val(), 'zip': $('.zip').val()};
	$('.paidfeatureddentists').load('/find-a-dentist/get-paid-featured-dentists/', data);
}

function getProvinces()
{
	data = {'country': $('#select-country').val(), 'norender': 1};
	$('#province-combo').load(baseUrl+'/province/province-combo/', data);	
}

function getLanguages()
{
	data = {'country': $('#select-country').val(), 'norender': 1};
	$('#languages-combo').load(baseUrl+'/language/dentist-languages-by-country-code/', data);	
}

function searchForDentists(link, submitForm)
{
	if (1 === submitForm) {
		$('#dentist-search-form').submit();
		return false;
	}
	showLoaderBig();
	$('#show-parameter').show();
	$('#search-parameters').slideUp('slow', 
			function()
			{
				$('#toggle-arrows').removeClass('arrow-down-toggle').addClass('arrow-right-toggle');
			}
	);
	
	//$('#paidfeatureddentists-small').html('');
	$('#paidfeatureddentists-small').load(link+'get-dentists', getDentistData('0,0,100',1,'0,1','0,1',0,'paid-featured-dentists-home','distance',1,1,1,1), function () {hideLoaderBig();});
//	$('#toprateddentists-small').load(link+'get-dentists', getDentistData(0,1,0,1,0,'top-rated-dentists-home','distance',1,0,0,0));
//	$('#standard-small').load(link+'get-dentists', getDentistData(100,1,0,0,0,'top-rated-dentists-home','distance',1,0,0,0));
//	$('#paidfeatureddentists-small').load(link+'get-paid-featured-dentists', data, function () {hideLoaderBig();});
//	$('#toprateddentists-small').load(link+'get-top-rated-dentists', data);
}
function getDentistData(dentistsCount,dentistTypeId, featured, payed, render, renderScript, orderBy, next, showHeader, showNotFound, showNextHeader)
{
	
	var data = {
			'keyword': $('#keyword').val(), 
			'zip': $('#zip').val() == zipValue ? '' : $('#zip').val(), 
			'city': $('#city').val() == cityValue ? '' : $('#city').val(), 
			'country': $('#select-country').val(), 
			'insurance': '', 
			'language': $('#language').val(), 
			'handicap': $('input:radio[name=handicap]:checked').val(), 
			'render': 0,  
			'profession_code': $('#profession_code').val(),
			'dentistsCount': dentistsCount,
			'dentist-type-id': dentistTypeId,
			'featured': featured,
			'payed': payed,
			'render': render,
			'renderScript': renderScript,
			'orderBy': orderBy,
			'next': next,
			'showHeader': showHeader,
			'showNotFound': showNotFound,
			'showNextHeader': showNextHeader,
			'distance' : $('#distance').val()
			};
	
	return data;
}
function getStandardDentists(clickedLetter)
{
	if(undefined == clickedLetter) {
		letter = '';
	}
	else {
		letter = clickedLetter;
	}
	$('.standarddentists').html($('#loader').html());
	data = {'searchstring': $('.searchtext').val(), 'professions': professionValues, 'letter': letter, 'country': $('#country').val(), 'city': $('#city').val(), 'zip': $('#zip').val(), 'profession_code': $('#profession_code').val()};
	$('.standarddentists').load('/find-a-dentist/get-standard-dentists/', data);
}

function getCities ()
{	
	var params = {'country': $('#country').val()};
	$('#city-element').load('http://' + subdomain + '/find-a-dentist/get-cities/', params);
}

function setDetails(link)
{
	detailLink = link;
}

function Get_Cookie( check_name, language, isWp ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				var valueArray = cookie_value.split('|');
				var newValue = valueArray[0]+'|'+language+'|'+valueArray[2]+'|'+valueArray[3];
				Set_Cookie('checkdent_com', newValue, 365, '/');
//				if (1 == isWp) {
//					window.location = '?lang='+language;
//				}
//				else {
					window.location = '/'+language;
//				}
				
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

/****************************** LOGIN ****************************/

function showLogin()
{
	$('#overlay-screen').show();
	$('#login-field').show();
	$('#login_username').focus();
}
function setLogin()
{
	var docWidth  = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	
	var fieldTop = winHeight / 2 + scrollTop - $('#login-field').height() / 2;
	var fieldLeft = docWidth / 2 - $('#login-field').width() / 2;

	$('#login-field').offset({top: fieldTop, left: fieldLeft});
	$('#login-field').css({position: "fixed"});	
}
function showError(action, type, error, buttons, message)
{

	
	if (undefined == message) {
		message = '';
	}
	if (undefined == buttons) {
		buttons = 'okcancel';
	}
	
	showLoaderBig();
	
	var data = {'doaction': action, 'type': type, 'error': error, 'buttons': buttons, 'message': message};
	
	$('.error-container').load(baseUrl+'/error/get-error-message/', data, function(){
		hideLoaderBig();
		$('#cancel-button').click(
				function()
				{
					closeErrorMessage();
				}
			);

			$('#action-button').click(
					function()
					{
						closeErrorMessage();			
						eval(action);
					}
				);		
		setErrorContainerPos();
		$('#overlay-screen').show();
		$('.error-container').show();		
		
	});
}
function setErrorContainerPos()
{
	var docWidth  = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();	
	
	var fieldTop = winHeight / 2 + scrollTop - $('.error-container').height() / 2;
	var fieldLeft = docWidth / 2 - $('.error-container').width() / 2;	
	
	$('.error-container').css({top: fieldTop, left: fieldLeft});	
}
function setOverlaySize()
{
	var docWidth = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	$('#overlay-screen').width(docWidth);
	$('#overlay-screen').height(docHeight+233);
}
function closeLogin()
{
	$('#overlay-screen').hide();
	$('#login-field').hide();
	$('.cropping-page').hide();
	$('.message-container').hide();
	$('.upload-thumb').hide();
	$('#dentist-hours-container').hide();
	$('.contact-message-success').hide();
	$('.error-container').hide();
	$('#reply-container').hide();
	$('#flying-button-field').hide();
	$('#forgot-password').hide();
	$('.specials').hide();
	$('#share-all').hide();
	$('#reply-container-form').hide();
	$('#join-doc-network').hide();
	$('.add-review-form').hide();
	$('#claim-profile-container').hide();
	$('#edit-signature-container').remove();
	closePluginPlayer();

	$('#overlay-screen').trigger('cdentHide');

}
function Get_CookieValue( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function logout()
{
	$('.account').show();
	$('.account-logged-in').hide();
	
	var cookie_value = Get_CookieValue('checkdent_com');
	var valueArray = cookie_value.split('|');
	var newValue = valueArray[0]+'|'+valueArray[1]+'|'+valueArray[2]+'|guest';	
	Set_Cookie('checkdent_com', newValue, 365, '/');
	Set_Cookie('checkdent_com_logged_in', null, null, '/', cdcdom);
}
function showLoaderBig()
{
	$('#overlay-screen').show();	
	$('#loader-big').show();
	
}
function setLoaderBig()
{
	var docWidth = $(document).width();
	var winHeight = $(window).height();
	
	var fieldTop = winHeight / 2 - $('#loader-big').height() / 2;
	var fieldLeft = docWidth / 2 - $('#loader-big').width() / 2;
	
	$('#loader-big').offset({top: fieldTop, left: fieldLeft});	
}
function hideLoaderBig()
{
	$('#loader-big').hide();
	$('#overlay-screen').hide();
}
var newwindow;
function newWindow(url, name, width, height)
{
	newwindow=window.open(url,name,'height='+height+',width='+width);
	if (window.focus) {newwindow.focus();}
	
}
function postComment(baseUrl, videoId, userId, norender)
{
	norender = norender == undefined ? 0 : norender;
	if ('' != $('#comment-textbox').val()) {				
		$.ajax({
			  url: baseUrl + '/comments/post-comment',
			  dataType: 'json',
			  data: {'videoid': videoId, 'userid': userId, 'text': $('#comment-textbox').val(), 'nr': norender},
			  type: 'POST',
			  success: function(data) {
				
				$('.comment-save-status').html(data.error);
				var commentsTimer = setTimeout(function(){
					$('.comment-save-status').html('');
					$('#comment-textbox').val('');
				}, 2000);
				
				$('#all-video-comments').load(baseUrl + '/comments/all-comments', {'videoid': videoId, 'nr': 1});
			  }
			});	
	}
}

function toggleField(field)
{
	$('#'+field).toggle('fast','swing');
}

function showShare()
{
	$('#overlay-screen').show();
	$('#share-all').show();
}

function hideShare()
{
	$('#overlay-screen').hide();
	$('#share-all').hide();
}

function setSharePosition()
{
	var docWidth  = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	
	var fieldTop = winHeight / 2 + scrollTop - $('#share-all').height() / 2;
	var fieldLeft = docWidth / 2 - $('#share-all').width() / 2;

	$('#share-all').offset({top: fieldTop, left: fieldLeft});
}

function addMovieLangForm()
{
	searching = false;
	$.ajax({
		  url: '/admin/videos/new-movie-lang/',
		  dataType: 'json',
		  data: {},
		  type: 'POST',
		  success: function(data) {			  
			if (data.success == true) {
				$("#fieldset-movies_lang dl").html($("#fieldset-movies_lang dl").html() + data.form); 
			}
		  }
		});	
}
function closeErrorMessage()
{
	$('#overlay-screen').hide();
	$('.error-container').hide();	
}
function checkdentConsoleLog(msg)
{
	if (console) {
		console.log(msg);
	}
}

function loadRecaptcha(id){
	id = (typeof id == 'undefined') ? 'recaptcha' : id;

	$('#'+id).replaceWith("<div id='"+id+"'></div>");
	$.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js', function() {
	    Recaptcha.create("6Lci1MESAAAAAFNPAPCbjtGwuiqpCuAPOtlQBFsE",
	    		id,
			    {
			      theme: "white"
			    }
			  );
	});
}

function menuLinkClicked(element){
	if(element.href.indexOf("/affiliates")>=0){
		var affiliatelang = "english";
		switch(LANGUAGE){
			case "de":
				affiliatelang = "german";
				break;
		}
		$.post(element.href+"/index.php", { "language": affiliatelang },
		     function(data) {
		         window.location.href = element.href;
		         return;
		     }
		);
		return false;
	}
	return true;
}
function forgotPassword()
{
	$('#login-field').hide();
	$('#forgot-password').show();
}
function setForgotPassword()
{
	var docWidth  = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	
	var fieldTop = winHeight / 2 + scrollTop - $('#forgot-password').height() / 2;
	var fieldLeft = docWidth / 2 - $('#forgot-password').width() / 2;

	$('#forgot-password').offset({top: fieldTop, left: fieldLeft});
	$('#forgot-password').css({position: "fixed"});	
}
function getPass()
{
	$.ajax({
		  url: baseUrl+'/forgot-password/get-data/',
		  dataType: 'json',
		  data: {'username': $('#forgot-username').val(), 'email': $('#forgot-email').val()},
		  type: 'POST',
		  success: function(data) {			  
			if (data.success == true) {
				$('#forgot-password').hide();
				showError('', 'info', data.msg, 'ok', '');
			}
		  }
		});		
}
function loadSpecial(href)
{
	var data = {'nrd':1};
	showLoaderBig();
	if ($('.specials').length > 0) {
		$('.specials').remove();
	}
	$('<div class="specials"></div>').load(href, data, function(){
		$('#loader-big').hide();
		setSpecialsPos();
		$('.specials').show();
	}).appendTo('body');	
	return false;
}
function setSpecialsPos()
{
	var docWidth  = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	
	var fieldTop = winHeight / 2 + scrollTop - $('.specials').height() / 2;
	var fieldLeft = docWidth / 2 - $('.specials').width() / 2;

	$('.specials').offset({top: fieldTop, left: fieldLeft});
}
function closeBox(obj)
{
	$('#overlay-screen').hide();
	$('#'+obj).hide();	
}
function setBoxHref(okHrefBox, cancelHrefBox, buttonSend, buttonCancel)
{
	$('#'+okHrefBox).width($('#'+buttonSend).width());
	$('#'+okHrefBox).height($('#'+buttonSend).height());

	$('#'+cancelHrefBox).width($('#'+buttonCancel).width());
	$('#'+cancelHrefBox).height($('#'+buttonCancel).height());	
}
function setAddReviewForm()
{
	var docWidth  = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	
	var fieldTop = winHeight / 2 + scrollTop - $('.add-review-form').height() / 2;
	var fieldLeft = docWidth / 2 - $('.add-review-form').width() / 2;

	$('.add-review-form').offset({top: fieldTop, left: fieldLeft});	
}
function showAddReview()
{
	$('#overlay-screen').show();
	$('.add-review-form').show();
}
function hideAddReview()
{
	$('#overlay-screen').hide();
	$('.add-review-form').hide();	
}
function getPage(href, page)
{
	if (1 == $('#ajax-pagination').val() && $('#ajax-load-to').val().length > 0) {
		//console.log($('#ajax-load-to').val());
		$('.'+$('#ajax-load-to').val()).load(href, {'nrd': 1});
	}
	else {
		if ($('#page').length > 0) {
			$('#page').val(page);
			document.searchform.submit();
		}
		else {
			window.location = href;
		}
	}
}
function setInformHeader()
{
	var winHeight = $(window).height();
	var minHeight = 800;
	var reserved  = 362;
	
	var actualHeight = $('#informHeader').height();
	
	if (winHeight - reserved > 800) {
		$('#informHeader').css({'min-height': winHeight - reserved+'px'});
	}
	//console.log(winHeight);
}

function showUserMenu()
{
	$('.user-menu-holder').show();
}
function setUserMenuPos()
{
	var pos = $('#menu-username').position();
	if (pos) {
		$('.user-menu-holder').css({'top': pos.top + 30, 'left': pos.left});
	}
}

function postAHref(obj, link){
	pos = 0;
	if(link == null || link.length<=0){
	    link = $(obj).attr('href');
	}
	pos = link.indexOf('?');
	if(pos<=0){ pos = link.length; }

	url = link.substr(0, pos);
	query = link.substr(pos+1);

	$(obj).attr('href', 'javascript:void(0);');

	post_to_url(url, query, "post");
	return false;
}
function post_to_url(url, querystring, method) {
    method = method || "post"; // Set method to post by default, if not specified.

    params = {};
    if(querystring.length>0){
        params = explodeQueryString(querystring);
    }
    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", url);

    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        form.appendChild(hiddenField);
    }

    document.body.appendChild(form);
    form.submit();
}
function explodeQueryString(q){
	urlParams = {};
	a = /\+/g;  // Regex for replacing addition symbol with a space
    r = /([^&=]+)=?([^&]*)/g;
    d = function (s) { return decodeURIComponent(s.replace(a, " ")); };
    while (e = r.exec(q))
	       urlParams[d(e[1])] = d(e[2]);
    return urlParams;
}
function setCroppingPos()
{
	var docWidth  = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	setOverlaySize();

	var fieldTop = winHeight / 2 + scrollTop - $('.cropping-page').height() / 2;
	var fieldLeft = docWidth / 2 - $('.cropping-page').width() / 2;

	$('.cropping-page').offset({top: fieldTop, left: fieldLeft});	
}
function setNewWindowAction()
{
    $('.newWindow').click(function (event){
   	 
        // Gets the URL from the clicked link.
        var url = $(this).attr("href");

        /*Gets the name from the clicked link. Currently I commented out the
          jquery script and just put "popUp" for a default name because I didn't
          include the name in the links.*/
        var windowName = $(this).attr("name");
        if ('' == windowName) {
        	windowName = 'socialPopUp';
        }

        /*Places the string from the array into the windowSize variable.
          The array slot is determined by the "rel" number on the link.*/
        var windowSize = $(this).attr("rel");
        if ('' == windowSize) {
        	windowSize = 'width=1000,height=600,scrollbars=yes';
        }
        
        var sizeData = windowSize.split(',');
        
        var tmp;
        var left = 0;
        var top = 0;
        for (i = 0; i < sizeData.length; i++) {
        	tmp = sizeData[i].split('=');
        	if ('width' == tmp[0]) {
        		left = (screen.width/2)-(tmp[1]/2);
        	}
        	if ('height' == tmp[0]) {
        		top = (screen.height/2)-(tmp[1]/2);
        	}
        }

        windowSize += ',top='+top+',left='+left;
        
        //This method opens a new browser window.
        window.open(url, windowName, windowSize);

        /*Prevents the browser from executing the default action and
          allows us to use the "window.open" within our script.*/
        event.preventDefault();

    }); 	
}
function loadClaimProfile(id) {
	
	$('#claim-profile-container').load(baseUrl+'/claim-profile/', {'id': id}, function() {
		setClaimProfileContainerPos();
		hideLoaderBig();
		$('#claim-profile-container').draggable();
		$('#overlay-screen').show();
		$('#claim-profile-container').show();
	});
}
function setClaimProfileContainerPos()
{
	var docWidth  = $(document).width();
	var docHeight = $(document).height();
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	setOverlaySize();

	var fieldTop = winHeight / 2 + scrollTop - $('#claim-profile-container').height() / 2;
	var fieldLeft = docWidth / 2 - $('#claim-profile-container').width() / 2;

	$('#claim-profile-container').css('top', fieldTop+'px').css('left', fieldLeft+'px');
}
function hideClaimProfile()
{
	$('#claim-profile-container').hide();
	$('#overlay-screen').hide();
}
function claimProfile(id) 
{
	$('#claim-profile-container').hide();
	showLoaderBig();
	$('#claim-profile-container').load(baseUrl+'/claim-profile/claim/', {'id': id, 'email': $('#claim-email').val()}, function() {
		hideLoaderBig();
		$('#overlay-screen').show();
		$('#claim-profile-container').show();
	});	
}
function fetchClaimProfileContainer(id)
{
	showLoaderBig();
	$('#overlay-screen').show();
	loadClaimProfile(id);	
}
function loadPluginPlayer(width, height, image, video, autoplay, player)
{
	showLoaderBig();
	var $data = {'width': width, 'height': height, 'image': image, 'video': video, 'autoplay': autoplay, 'player': player};
	$('<div id="cd-plugin-player-holder" style="display:none;position:absolute;z-index:999;"></div>').load(baseUrl+'/video-plugin', $data, function(){
		var docWidth  = $(document).width();
		var docHeight = $(document).height();
		var scrollTop = $(document).scrollTop();
		var winHeight = $(window).height();
		
		var fieldTop = winHeight / 2 + scrollTop - $('#cd-plugin-player-holder').height() / 2;
		var fieldLeft = docWidth / 2 - $('#cd-plugin-player-holder').width() / 2;

		$('#cd-plugin-player-holder').css('top', fieldTop+'px').css('left', fieldLeft+'px');
		hideLoaderBig();
		$('#overlay-screen').show();
		$('#cd-plugin-player-holder').show();
	}).appendTo('.middle-big');
}
function closePluginPlayer()
{
	$('#cd-plugin-player-holder').remove();
	$('#overlay-screen').hide();
}
