
var currentThemeLocation = (!currentThemeLocation) ? 'fd1_0' : currentThemeLocation;

var loginForm = '<form name="popLoginForm" id="popLoginForm" action="/login" method="post">';
loginForm += '<p class="blue bold">Email<br/>';
loginForm += '<input type="text" name="pop_email" class="formInput" /></p>';
loginForm += '<p class="blue bold">Password<br/>';
loginForm += '<input type="password" name="pop_password" class="formInput" /></p>';
loginForm += '<p class="bold"><label>Sign In <input type="image" align="absmiddle" src="' + currentThemeLocation + '/images/btn-submitcheckwhite.png" name="pop_submit" value="" /></label></p>';
loginForm += '</form>';

var popup = {
	popWidth: 646,
	getBrowserHeight: function() {
		var intH = 0,intW = 0,h = 0;
		if(typeof window.innerWidth == 'number' ) {
			intH = window.innerHeight;
			intW = window.innerWidth;
			h = window.pageYOffset;
		}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			intH = document.documentElement.clientHeight;
			intW = document.documentElement.clientWidth;
			h = document.documentElement.scrollTop;
		}else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
			intH = document.body.clientHeight;
			intW = document.body.clientWidth;
			h = document.body.scrollTop;
		}
		return { 
			width: parseInt(intW), 
			height: parseInt(intH), 
			yOffset: parseInt(h) 
		};
	},
	setPopResize: function(){
		var bws = popup.getBrowserHeight();
		$('#popupMC').css('height', bws.height + 'px');
		$('#popupMsgGlaze').css('height', bws.height + 'px');
		
		var yo = parseInt(bws.yOffset) + parseInt((bws.height - 650) / 2);
		yo = (yo < 0) ? 0 : yo;
		
		$('#popupMsg').css('top', yo + 'px');
		$('#popupMsg').css('left', parseInt((bws.width - popup.popWidth) / 2) + 'px');
	},
	setPopScroll: function(){
		var bws = popup.getBrowserHeight();
		$('#popupMC').css('height', bws.height + 'px');
		$('#popupMsgGlaze').css('height', bws.height + 'px');
		
		var yo = parseInt(bws.yOffset) + 40;
		
		$('#popupMsg').css('top', yo + 'px');
		$('#popupMsg').css('left', parseInt((bws.width - popup.popWidth) / 2) + 'px');
	},
	popKeyUpDetect: function(e){
		var x = '';
		if (document.all)
		{
			var evnt = window.event;
			x = evnt.keyCode;
		} else {
			x = e.keyCode;
		}
		if(x==27)
		{
			popup.closePopUp();
			document.onkeyup = null;
		}
	},
	closePopUp: function(x)
	{
		$('#popupMC').fadeOut('fast',function(){
			popup.terminatePop.one = true;
		});
		$('#popupMsg').fadeOut('fast',function(){
			popup.terminatePop.two = true;
			popup.terminatePop.removeThem();
		});
		window.onresize = null;
	},
	terminatePop: {
		one: false,
		two: false,
		removeThem: function(){
			if(this.one && this.two)
			{
				$('#popupMC').remove();
				$('#popupMsg').remove();
			}
		}
	},
	message: function(obj)
	{
		if(typeof obj.width!=='undefined' && (obj.width < 646))
		{
			popup.popWidth = obj.width;
		}
		var title = (typeof obj.title!=='undefined') ? obj.title : '';
		var x = (typeof obj.html!=='undefined') ? obj.html : '';
		var bws = popup.getBrowserHeight();
		
		var html = '<div class="popup" id="popup">';
		html += '<img src="' + currentThemeLocation + '/images/ribbon-pop.png" border="0" class="popRibbon" />';
		html += '<a href="javascript:;" onclick="popup.closePopUp()" class="popClose"><img src="' + currentThemeLocation + '/images/btn-close.png" border="0" /></a>';
		html += '<h1 id="popTitle">' + title + '</h1>';
		html += '<div id="popContent">' + x + '</div>';
		html += '</div>';
		html += '<div class="poptear" style="width:' + popup.popWidth + 'px;"><img src="' + currentThemeLocation + '/images/bg-pagetearpop.png" border="0" /></div>';	
		
		var mc = document.createElement('div');
		mc.setAttribute('id','popupMC');
		mc.style.width = '100%';
		mc.style.height = bws.height + 'px';
		
		var glaze = document.createElement('div');
		glaze.setAttribute('id','popupMsgGlaze');
		glaze.style.width = '100%';
		glaze.style.height = bws.height + 'px';
		mc.appendChild(glaze);
		
		var msg = document.createElement('div');
		msg.setAttribute('id','popupMsg');
		var yo = parseInt(bws.yOffset) + 40;
		msg.style.top = yo + 'px';
		msg.style.left = parseInt((bws.width - popup.popWidth) / 2) + 'px';
		msg.style.width = popup.popWidth + 'px';
		msg.style.display = 'none';
		msg.innerHTML = html;
		
		$('body').append(mc);
		$('body').append(msg);
		
		$('#popupMC').fadeIn('fast', function(){
			$('#popupMsg').fadeIn('slow');
			document.onkeyup = popup.popKeyUpDetect;
			window.onresize = popup.setPopResize;
		});
	}
};

function formReset(x)
{
	$(x).each(function(){
	        this.reset();
	});
}

function setAttr(x,y)
{
	$(x).attr('value',y);
}

function setFullAttr(x,y,z)
{
	$(x).attr(y,z);
}

function css(x,y)
{
	$(x).css(y);
}

function html(x,y)
{
	$(x).html(y);
}

function text(x,y)
{
	$(x).text(y);
}

function hide(x)
{
	$(x).hide();
}

function show(x)
{
	$(x).show();
}

function moveUp(x){
	$('#' + x).insertBefore($('#' + x).prev());
	return true;
}

function moveDown(x){
	$('#' + x).insertAfter($('#' + x).next());
	return true;
}

function saved(x,y)
{
	$(y).show('fast');
	var int = window.setTimeout(function(){
		$(y).hide('fast',function(){
			$(x).show('fast');
		});
	},2000);
}

function remove(x)
{
	$(x).remove();
}

function con(x,y)
{
	var con = confirm(y);
	if(con)
	{
		x.submit();	
	}
}

function res(x)
{
	document.getElementById(x).reset();
}

function alphadash(x)
{
	var v = x.value.split(' ').join('-');
	var clean = [];
	var regex = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','-'];
	for(var i=0;i<v.length;i++)
	{
		for(var a in regex)
		{
			if(v.charAt(i).toLowerCase()==regex[a])
			{
				clean[clean.length] = v.charAt(i).toLowerCase();	
			}	
		}
	}
	x.value = clean.join('');
}

function numdash(x)
{
	var v = x.value.split(' ').join('-');
	for(var i=0;i<v.length;i++)
	{
		if(isNaN(v.charAt(i)) || v.charAt(i)!=='-')
		{
			v = v.split(v.charAt(i)).join('');
		}
	}
	x.value = v;
}