// JavaScript Document
var seconds; var minutes; var hours; var days;
var winW = f_clientWidth();
var winH = f_clientHeight();


function gagaSideBanner()
{
	showDialogRight(278,342);
	var msg = '<a href="http://www.socialbuy.com/gaga-giveaway?sales_id=57">';
    msg += '<div style="height: 342px; width: 278px; overflow: hidden; background: url('+server_path+'images/GagaBanner_merged.png) no-repeat; padding-left: 20px;">';
    msg += '</div></a>';
	
	var div = document.getElementById("dialogcontent");
	div.innerHTML = msg;
}
function closeDialogRight()
{
	$("#floatFG1").slideToggle("slow");
}
function showDialogRight(wid,hei,flag)
{ 
	newdiv1 = document.createElement("div");
	newdiv1.setAttribute("id","floatFG1");
	newdiv1.style.position = "absolute";
	newdiv1.style.zIndex = 7;
	//newdiv1.style.backgroundColor = "#FFFFFF";
	
	newdiv1.style.overflow = "visible";
	
	newdiv1.style.width = wid +"px";
	newdiv1.style.height = hei +"px";
	newdiv1.style.paddingTop = 0;
	newdiv1.style.display = "none";
	
	var box = "";
	box += '<div style="width: '+(wid)+'px; position: relative;"><!--PopUp-->';
    box += '<div style="height: 44px; width: 44px; overflow: hidden; position: absolute; right: -20px; margin-top:-14px;"><!--Cross-->';
    box += '<a href="#" onclick="';
	if(flag == null)
	{
		box += 'closeDialogRight(); ';
	}
	else
	{
		box += 'closeDialogRight(); ';
	}
	box += 'return false;"><img src="'+server_path+'images/pop_cross.png" width="44" height="44" border="0"/></a>';
    box += '</div><!--Cross-->';
    
    box += '<div style="overflow: hidden;"><!--Mid-->';
    box += '<div style="float: left; height: '+(hei)+'px; width: '+(wid)+'px; overflow: hidden;" id="dialogcontent">';
    box += '</div>';
    
    box += '<div class="clear"></div>';
    box += '</div><!--Mid-->';
    box += '</div><!--PopUp-->';
    box += '<div class="clear"></div>';
	
	var top = (((parseInt(f_clientHeight())-hei)/2) + parseInt(f_scrollTop()));
	//var left = ((parseInt(f_clientWidth())/2)-(wid/2));
	var temp1 = (f_clientWidth()-960)/2;
	var temp2 = 0;
	if(temp1 > 280)
	{
		temp2 = 960+temp1;	
	}
	else
	{
		temp2 = parseInt(f_clientWidth() - (wid+22));
	}
	
	
	
	var left = temp2;
	
	
	if(top < 10)
	{
		top = 10;
	}
	
	if(left < 0)
	{
		left = 0;
	}
	
	newdiv1.style.top = top+"px";
	
	newdiv1.style.left = left+"px";
	document.body.appendChild(newdiv1);
	newdiv1.innerHTML = box;
	showDialogLoading(document.getElementById('dialogcontent'));
	$("#floatFG1").slideToggle("slow");
	return document.getElementById("dialogcontent");
}
function updateCash()
{
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=updateCash",
		success: function(msg)
		{
			document.getElementById("cash").innerHTML = msg;
		}
 	});
	
}
function redeemCode()
{
	var code = document.getElementById("code").value;
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=redeemCode&code="+code,
		success: function(msg)
		{
			alert(msg);
			updateCash();
		}
 	});
}
function pushEnter2(e) {
	if (window.event) { // IE
		if (e.keyCode == 13) {	//override default value so you know it was caused by input
			redeemCode();	
		}
	}
	else if(e.which == 13) {	// Netscape/Firefox/Opera
		redeemCode();
	}
	
}
function processPayment(deal_id)
{
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=processPayment&deal_id="+deal_id,
		success: function(msg)
		{
			
		}
 	});
}
function gagaPopUp()
{
	showDialogNew(556,351);
	var msg = '<div style="height: 351px; width: 536px; overflow: hidden; background: url('+server_path+'images/gaga_popup.png) no-repeat; padding-left: 20px;">';
    msg += '<a style="float: left; width: 215px; height: 40px; margin: 295px 0 0 0;" href="https://www.socialbuy.com/gaga-giveaway"></a>';
    msg += '</div>';
	
	var div = document.getElementById("dialogcontent");
	div.innerHTML = msg;
}
function resendEmail(id)
{
	showDialog(575,200);
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=resendEmail&id="+id,
		success: function(msg)
		{
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
 	});
}

function thanksEmail(id)
{
	showDialog(575,200);
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=thanksEmail&id="+id,
		success: function(msg)
		{
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
 	});
}
function getConfirmPopup(uid,deal_id)
{
	showDialog(575,400);
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=confirmPurchase&deal_id=" +deal_id+ "&uid=" +uid,
		success: function(msg)
		{
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
 	});
}
function getRedeemPopUp(rid)
{
	showDialog(566,370);
	
	site_url = server_path+"ajaxcall/ajaxForm.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=rpop&rid=" +rid,
		success: function(msg)
		{
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
 	});
	
	//div.innerHTML = "noo";
}
function getAllContacts()
{
	var pro = getPro();
	var email = document.getElementById("email").value;
	var pass = document.getElementById("pass").value;
	var msg = document.getElementById("msg").value;
	
	showDialog(700,370);
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=getContactsBox&email=" +email+ "&pass=" +pass+ "&msg=" +msg+ "&pro=" +pro,
		success: function(msg)
		{
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
 	});
}

function forgetPassPopUp()
{
	showDialog(700,250);
	
	site_url = server_path+"ajaxcall/ajaxForm.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "fPass=fPassForm",
		success: function(msg)
		{
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
 	});
}

function submitForgetEmail()
{
	var email = document.getElementById('uemail2').value;
	
	site_url = server_path+"ajaxcall/process.php";
	
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=changePass&email=" +email,
		success: function(msg)
		{
			alert(msg);
			document.getElementById('uemail2').value = "";
		}
 	});
	
}

function getPro()
{
	for(var i=0; i<document.referF.pro.length; i++)
	{
		if(document.referF.pro[i].checked)
		{
			return document.referF.pro[i].value;
		}
	}
}
function checkAll()
{
	var total = document.getElementById("total").value;
	for(var i=0; i<total; i++)
	{
		document.getElementById("contact"+i).checked = true;
	}
}
function uncheckAll()
{
	var total = document.getElementById("total").value;
	for(var i=0; i<total; i++)
	{
		document.getElementById("contact"+i).checked = false;
	}
}

function getCVVBox()
{
	
}
function sendActivationPop(email)
{
	showDialog(700,250);
	var html = '';
	html+= '<div style="background-image:url('+document.location.protocol+'//www.socialbuy.com/images/popup_yellow.jpg); background-repeat:repeat-x; height:105px;">';
	html+= '<h1 style="font: bold 24px Georgia; color: #5F3E29; text-align: center; padding-top: 20px;">Resend Account Activation Link</h1>';
	html+= '<h1 style="font: bold 13px Georgia; color: #777; text-align: center; padding-top: 10px;">&nbsp;</h1></div>';
	html+= '<div class="in_name_suggest" style="margin:20px 0 0 0px; text-align:center; width:630px;">You can resend your activation link to: '+email+'</div>';
	html+= '</div>';
	html+= '<div class="clear"></div>';
	html+= '<div class="input_hold_suggest" style="text-align:center; padding-bottom:4px; width:630px;">';
    html+= '<a class="but" href="#" onclick="resendActivationLink(\''+email+'\');" style="margin-right:250px;">Click to resend</a>';
	html+= '</div>';
	html+= '<div style="text-align:center; padding-top:20px;" id="msg"></div>';
	
	document.getElementById("dialogcontent").innerHTML = html;
	
}


function whatsThis(flag)
{
	if(document.getElementById("floatBG"))
	{
		closeDialog();
	}
	showDialog(700,430,flag);
	
	var http = "";
	
	var html = '<div class="popup">';
	html+= '<h2 style="text-align: center; font: bold 20px Arial; padding: 20px 0 5px 0; margin-bottom: 5px;">What is a Security Code?</h2>';
	html+= '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	html+= '<tr><td colspan="2"><h4 style="line-height: 16px;">The Security Code also known as the CVV (Card Verification Value) is a code on your credit or debit card that helps us verify your identity. On a Visa, Mastercard or Discover, it\'s the last three digits that appear to the right of the signature strip on the back of the card. On an American Express card, it\'s the four digits that appear above your credit card number on the front of the card.</h4></td></tr>';
	html+= '<tr><td align="right"><img src="images/popup_card_back.jpg" alt="" /></td><td><img src="images/popup_card_front.jpg" alt="" /></td></tr>';
	html+= '<tr><td colspan="2" style="padding: 0 0 0 50px;"><img src="images/popup_visa.jpg" alt="" /></td></tr></table></div>'	
	
	document.getElementById("dialogcontent").innerHTML = html;
	
}
function resendActivationLink(email)
{
	var div = document.getElementById("msg");
	div.innerHTML = "<div class='success' align='center'>sending...</div>";
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=resend&email=" + email,
		success: function(msg){
			div.innerHTML = msg;
		}
 	});
}
function howItWorks()
{
	showDialog(700,470);
	var html = '';
	html+= '<div style="background-image:url('+document.location.protocol+'//www.socialbuy.com/images/popup_yellow.jpg); background-repeat:repeat-x; height:105px;">';
	html+= '<h1 style="font: bold 24px Georgia; color: #5F3E29; text-align: center; padding-top: 10px;">How Does SocialBuy Work?</h1>';
	html+= '<h1 style="font: bold 13px Georgia; color: #777; text-align: center; padding-top: 10px;">SocialBuy helps both businesses and consumers by offering great deals on local products and services.  We help customers by working out such huge discounts, and we help businesses by bringing them new customers.</h1>';
	html+= '</div>';
	html+= '<div align="center" style="margin-top:20px;"><img src="'+document.location.protocol+'//www.socialbuy.com/images/pop_con.png" /></div>';
	
	document.getElementById("dialogcontent").innerHTML = html;
}
function fbLogout()
{
	location.href = server_path+"signin.php?out=1"; 
}
function isNumeric(fld)
{
	var error = "";
    var res = /^[-+]?[0-9]+(\.[0-9]+)?$/.test(fld.value);
	fld.style.background = '#E0ECFF'; 
	if(res == true)
	{
		return true;
	}
	return false;
}
function alertBox()
{
	showDialogNew(481,220);
	var html = '';
	html+= '<div style="width: 481px; overflow: hidden;"><!--PopUp-->';
	html+= '<div style="height: 37px; width: 481px; background: url('+document.location.protocol+'//www.socialbuy.com/images/email_popup.png) no-repeat; overflow: hidden; position: absolute;"><!--Top-->';
	html+= '<h1 style="font: bold 17px Arial; color: #fff; line-height: 37px; text-indent: 20px;">Email Sign Up!</h1>';
    html+= '</div><!--Top-->';
    html+= '<div style="padding: 40px 20px 20px 20px; background-color: #fff; border: 1px solid #939495; margin-top: 15px; width: 438px; height:140px;"><!--Bottom-->';
    html+= '<p style="font: bold 18px Arial; padding-bottom: 30px;">Enter your email to subscribe to this and other great deals from SocialBuy.</p>';
	html+= '<input type="text" style="float: left; width: 300px; margin-right: 5px; height:23px;" value="Enter email address..." id="popemail" onFocus="focusEmail3();" />';
	html+= '<input style="float: left;" type="image" src="'+document.location.protocol+'//www.socialbuy.com/images/but_signup.png" id="" onClick="emailNotPopup();" />';
    html+= '<div class="clear"></div>';
	html+= '</div><!--Bottom-->';
	html+= '</div><!--PopUp-->';
	
	document.getElementById("dialogcontent").innerHTML = html;
}
function focusEmail()
{
	if(document.getElementById("uemail").value == "Enter email address...")
	{
		document.getElementById("uemail").value = "";
	}
}
function focusEmail3()
{
	if(document.getElementById("popemail").value == "Enter email address...")
	{
		document.getElementById("popemail").value = "";
	}
}

function blurEmail()
{
	if(document.getElementById("uemail").value == "")
	{
		document.getElementById("uemail").value = "Enter email address...";
	}
}
function focusEmail2()
{
	if(document.getElementById("uemail2").value == "Enter email address...")
	{
		document.getElementById("uemail2").value = "";
	}
}
function verifyLink(linkurl,type)
{
	return linkurl;
}
function stateShow()
{
	if(document.getElementById("state").style.display == "block")
	{
		//document.getElementById("state").style.display = "none";
		//document.getElementById("head").src = "images/arrow.jpg";
		document.getElementById("head").innerHTML = "&raquo;";
	}else{
		//document.getElementById("state").style.display = "block";
		//document.getElementById("head").src = "images/arrow2.jpg";
		document.getElementById("head").innerHTML = "&laquo;";
	}
	$("#state").slideToggle("slow");
	
}
function checkDelete(msg)
{
	if(confirm(msg))
	{
		return true;
	}
	else
	{	
		return false;
	}
}
function submitForm(form)
{
	document.getElementById(form).submit();
}
function timeCounter(){
	seconds=document.getElementById("seconds").innerHTML;
	minutes = document.getElementById("minutes").innerHTML;
	hours = document.getElementById("hours").innerHTML;
	days = document.getElementById("days").innerHTML;
	display(seconds);
}
function display(seconds){ 
	 if (seconds < 0)
	 { 
		seconds = 59;
		minutes = document.getElementById("minutes").innerHTML;
		if(minutes <= 0)
		{
			minutes = 59;
			hours = document.getElementById("hours").innerHTML;
			if(hours <= 0)
			{
				hours = 23;
				days = document.getElementById("days").innerHTML;
				if(days <= 0)
				{
					
				}
				else
				{
					days--;
				}
			}
			else
			{
				hours--;
			}
		}
		else
		{
			minutes--;
		}
		display(seconds);
	 } 
	 else
	 {
		if(seconds < 10)
		{
			document.getElementById("seconds").innerHTML = "0"+seconds; 
		}else{
			document.getElementById("seconds").innerHTML = seconds; 
		}
		if(minutes < 10)
		{
			document.getElementById("minutes").innerHTML = "0"+minutes; 
		}else{
			document.getElementById("minutes").innerHTML = minutes; 
		}
		if(hours < 10)
		{
			document.getElementById("hours").innerHTML = "0"+hours; 
		}else{
			document.getElementById("hours").innerHTML = hours; 
		}
		if(days < 10)
		{
			document.getElementById("days").innerHTML = "0"+days; 
		}else{
			document.getElementById("days").innerHTML = days; 
		}
		if(days != 0 || hours != 0 || minutes != 0 || seconds != 0)
		{
			setTimeout(function(){ display(seconds); },1000);
			seconds--;
		}
	 }
}
function showFloatDiv(wid,hei)
{ 
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id","floatBG");
	newdiv.style.position = "absolute";
	newdiv.style.zIndex = 5;
	newdiv.style.backgroundColor = "#000000";
	
	newdiv.style.filter = "alpha(opacity=50)"; 
	newdiv.style.mozOpacity = "0.5";
	newdiv.style.opacity = "0.5";
	
	newdiv.style.width = document.body.clientWidth+"px";
	newdiv.style.height = document.body.clientHeight+"px";
	newdiv.style.paddingTop = 0;
	
	newdiv.style.top = 0+"px";
	newdiv.style.left = 0+"px";
	
	document.body.appendChild(newdiv);
	//------------------------------------
	//------------------------------------
	
	newdiv1 = document.createElement("div");
	newdiv1.setAttribute("id","floatFG");
	newdiv1.style.position = "absolute";
	//newdiv1.style.borderBottom = "2px solid #000000";
	newdiv1.style.zIndex = 7;
	newdiv1.style.backgroundColor = "#ffffff";
	newdiv1.style.overflow = "visible";
	
	newdiv1.style.width = wid +"px";
	newdiv1.style.height = hei +"px";
	newdiv1.style.paddingTop = 0;
	
	newdiv1.style.top = 250+"px";
	newdiv1.style.left = ((document.body.clientWidth-900)/2)+100+"px";
	document.body.appendChild(newdiv1);
	showLoading(newdiv1);
	//return newdiv1;
}

function showLoading(div)
{
	div.innerHTML = "<div style='text-align:center; padding-top:100px;'><img src='"+ verifyLink('images/loader.gif'); + "' style='vertical-align: middle;'/></div>";
}

function closeFloatDiv()
{
	var div = document.getElementById("floatFG");
	document.body.removeChild(div);
	var div = document.getElementById("floatBG");
	document.body.removeChild(div);
}
/*function emailNot()
{
	showFloatDiv(675,199);
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=emailNot",
		success: function(msg){
			var div = document.getElementById("floatFG");
			div.innerHTML = msg;
		}
 	});
}*/
function emailNot()
{
	var email = document.getElementById("uemail").value;
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=emailNot1&email="+email,
		success: function(msg){
			var arr = new Array();
			arr = msg.split("_");
			
			if(arr[0] == 1)
			{
				emailNot3(arr[1]);
			}
			else
			{
				var div = showDialog(675,199);
				div.innerHTML = msg;
			}
			document.getElementById("uemail").value = "";
		}
 	});
}
function emailNotPopup()
{
	var email = document.getElementById("popemail").value;
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	if (email == "") 
    {
        alert("You didn't enter an email address");
		return false;
    }
    else if (!emailFilter.test(email)) 
	{
        alert("Please enter a valid email address");
		return false;
    } 
    else if (email.match(illegalChars)) 
    {
        alert("The email address contains illegal characters");
		return false;
    }
	
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=emailNot1&email="+email,
		success: function(msg){
			var arr = new Array();
			arr = msg.split("_");
			
			if(arr[0] == 1)
			{
				emailNot3(arr[1]);
			}
			else
			{
				var div = showDialog(675,199);
				div.innerHTML = msg;
			}
			document.getElementById("popemail").value = "";
		}
 	});
}
function emailNot3(emailId)
{
	var div = showDialog2(480,378);
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=emailNot3&id="+emailId,
		success: function(msg){
			div.innerHTML = msg;
		}
 	});
}
function emailNotFin()
{
	var sex = document.getElementById("sex_1").value;
	var db = document.getElementById("year_1").value + "-" + document.getElementById("mon_1").value + "-" + document.getElementById("day_1").value;
	var zip = document.getElementById("zip_1").value;
	var id = document.getElementById("emailId").value;
	
	var res = /^[-+]?[0-9]+(\.[0-9]+)?$/.test(zip);
	if(res == true || zip == "")
	{
		document.getElementById("zip_1").style.background = "#fff";
		site_url = server_path+"ajaxcall/process.php";
		$.ajax({
			type: "POST",
			url: site_url,
			data: "p=emailNotSaveOther&sex=" + sex + "&db=" + db + "&zip=" + zip + "&id=" + id,
			success: function(msg){
				closeDialog();
			}
		});
	}
	else
	{
		document.getElementById("zip_1").style.background = "#ffaaaa";
		alert("Zip Code should be numeric");
	}
}
function showDialog2(wid,hei,flag)
{ 
	var div = document.getElementById("floatFG");
	if(div)
	{
		document.body.removeChild(div);
	}
	
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id","floatBG");
	newdiv.style.position = "absolute";
	newdiv.style.zIndex = 5;
	newdiv.style.backgroundColor = "#61BDFF";
	
	newdiv.style.filter = "alpha(opacity=50)"; 
	newdiv.style.mozOpacity = "0.5";
	newdiv.style.opacity = "0.5";
	
	newdiv.style.width = document.body.clientWidth+"px";
	newdiv.style.height = document.body.clientHeight+document.body.scrollTop+"px";
	newdiv.style.paddingTop = 0;
	
	newdiv.style.top = 0+"px";
	newdiv.style.left = 0+"px";
	
	document.body.appendChild(newdiv);
	//------------------------------------
	//------------------------------------
	
	newdiv1 = document.createElement("div");
	newdiv1.setAttribute("id","floatFG");
	newdiv1.style.position = "absolute";
	newdiv1.style.zIndex = 7;
	//newdiv1.style.backgroundColor = "#FFFFFF";
	
	newdiv1.style.overflow = "visible";
	
	newdiv1.style.width = wid +"px";
	newdiv1.style.height = hei +"px";
	newdiv1.style.paddingTop = 0;
	newdiv1.style.display = "none";
	
	var box = "";
	box += '<div style="width: '+(wid)+'px; position: relative;"><!--PopUp-->';
    box += '<div style="height: 44px; width: 44px; overflow: hidden; position: absolute; right: 0;"></div><!--Cross-->';
    box += '<div style="overflow: hidden;"><!--Mid-->';   
    box += '<div style="float: left; height: '+(hei)+'px; width: '+(wid)+'px; overflow: hidden;" id="dialogcontent">';
    box += '</div>';    
    box += '<div class="clear"></div>';
    box += '</div><!--Mid-->';
    box += '<div style="height: 28px;"><!--Bot-->';    
    box += '<div class="clear"></div>';
    box += '</div><!--Bot-->';
    box += '</div><!--PopUp-->';
    box += '<div class="clear"></div>';
	
	var top = (((parseInt(f_clientHeight())-hei)/2) + parseInt(f_scrollTop()));
	var left = ((parseInt(f_clientWidth())/2)-(wid/2));
	if(top < 10)
	{
		top = 10;
	}
	
	if(left < 0)
	{
		left = 0;
	}
	
	newdiv1.style.top = top+"px";
	
	newdiv1.style.left = left+"px";
	document.body.appendChild(newdiv1);
	newdiv1.innerHTML = box;
	showDialogLoading(document.getElementById('dialogcontent'));
	$("#floatFG").slideToggle("slow");
	return document.getElementById("dialogcontent");
}
function emailNot2()
{
	div = document.getElementById('msg');
	var email = document.getElementById("pemail").value;
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=emailNot1&email="+email,
		success: function(msg){
			
			if(msg == 1)
			{
				div.innerHTML = '<div align="center" class="success" style="margin-top:50px; font-size:16px;">You have successful subscribed. You will receive emails about daily deals and monthly newsletters. You can unsubscribe at any time and we don\'t share your contact information with anyone. Read more about how your privacy is protected. <a href="content.php?m=5">Read more</a></div>';
			}
			else if(msg == 0)
			{
				div.innerHTML = '<div align="center" class="error" style="margin-top:60px; font-size:16px;">You have already subscribed</div>';
			}
			else if(msg == 2)
			{
				div.innerHTML = '<div align="center" class="error" style="margin-top:60px; font-size:16px;">Please provide your email</div>';
			}
			else if(msg == 3)
			{
				div.innerHTML = '<div align="center" class="error" style="margin-top:60px; font-size:16px;">Please provide a valid email address in order receive emails about daily deals and monthly newsletters</div>';
			}
			document.getElementById("pemail").value = "";
		}
 	});
}
function submitEmailNot()
{
	
	var div = document.getElementById("msgText");
	div.innerHTML = "<div align='center' class='success'>Processing...</div>";
	var name = document.getElementById("uname").value;
	var email = document.getElementById("uemail").value;
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=emailNotSubmit&name=" + name + "&email=" + email,
		success: function(msg){
			if(msg == 1)
			{
				div.innerHTML = "<div align='center' class='success'>You are successfully subscribed</div>";
			}
			else if(msg == 0)
			{
				div.innerHTML = "<div align='center' class='error'>This email is already subscribed</div>";
			}
			else if(msg == 2)
			{
				div.innerHTML = "<div align='center' class='error'>Please provide your Name & Email</div>";
			}
			else if(msg == 3)
			{
				div.innerHTML = "<div align='center' class='error'>Please provide valid email address</div>";
			}
		}
 	});
}
function shareEmail()
{
	showFloatDiv(675,209);
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=shareEmail",
		success: function(msg){
			var div = document.getElementById("floatFG");
			div.innerHTML = msg;
		}
 	});
}
function submitEmailShare()
{
	var div = document.getElementById("msgText");
	div.innerHTML = "<div align='center' class='success'>Processing...</div>";
	var email1 = document.getElementById("email1").value;
	var email2 = document.getElementById("email2").value;
	var email3 = document.getElementById("email3").value;
	
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=submitShareEmail&email1=" + email1 + "&email2=" + email2 + "&email3=" +email3,
		success: function(msg){
			if(msg == 1)
			{
				div.innerHTML = "<div align='center' class='success'>Successfully invited to your friends</div>";
			}
			else if(msg == 0)
			{
				div.innerHTML = "<div align='center' class='error'>Please provide 3 email addresses</div>";
			}
			else if(msg == 2)
			{
				div.innerHTML = "<div align='center' class='error'>Please provide valid email addresses</div>";
			}
		}
 	});
}
function pushEnter(e,fname) {
	if (window.event) { // IE
		if (e.keyCode == 13) {	//override default value so you know it was caused by input
			submitForm(fname);
		}
	}
	else if(e.which == 13) {	// Netscape/Firefox/Opera
		submitForm(fname);
	}
	
}
function lendingInput()
{
	//showFloatDiv(675,209);
	showDialog(675,209);
	var email = document.getElementById("email").value;
	var city = document.getElementById("city").value;
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=landEmail&email="+email+"&city="+city,
		success: function(msg){
			//var div = document.getElementById("floatFG");
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
 	});
}
function lendingInput2()
{
	//showFloatDiv(675,209);
	//showDialog(675,209);
	var email = document.getElementById("email").value;
	var city = document.getElementById("city").value;
	var area = document.getElementById("area").value;
	
	site_url = server_path+"ajaxcall/ajaxForm.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=landEmail&email="+email+"&city="+city+"&area="+area,
		success: function(msg){
			var arr = new Array();
			arr = msg.split("_");
			
			if(arr[0] == 1)
			{
				emailNot3(arr[1]);
			}
			else
			{
				var div = showDialog(675,199);
				div.innerHTML = msg;
			}
			document.getElementById("uemail").value = "";
			//var div = document.getElementById("floatFG");
			//var div = document.getElementById("dialogcontent");
			//div.innerHTML = msg;
		}
 	});
}
function twitterAuthenticate(authenticateUrl)
{
	var windowObj = window.open(server_path+authenticateUrl, "twcWindow","width=800,height=400,left=150,top=100,scrollbar=no,resize=no,location=1");
	return false;
}

function twitterShare(shareUrl, entry_id)
{
	var windowObj = window.open("http://twitter.com/home?status="+encodeURIComponent(shareUrl), "twcWindow","width=800,height=400,left=150,top=100,scrollbar=no,resize=no");
	return false;
}

function facebookShare(shareUrl, entry_id)
{
	var windowObj = window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(shareUrl+"&ref_code=470"), "fbcWindow","width=800,height=400,left=150,top=100,scrollbar=no,resize=no");
	return false;
}

function facebookChangeStatus(status)
{
	FB.Connect.streamPublish(status);
}

function facebookInvite(title, url, actionurl)
{
	var div = showDialog(830,700);
	site_url = server_path+"ajaxcall/fbInvite.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "title="+encodeURIComponent(title)+"&url="+encodeURIComponent(url+"&ref_code=473")+"&actionurl="+encodeURIComponent(actionurl),
		success: function(msg){
			div.innerHTML = msg;
			FB_RequireFeatures(["XFBML"], function(){
				FB.init("69df8f684c465388bafdda81e803046e");
	 		});
		}
 	});
}

function twitterCallback(newuser)
{
	if (newuser)
	{
		window.location = twitterurl;
	}
	else
	{
		window.location.reload();
	}
}
function showDialog(wid,hei,flag)
{ 
	var div = document.getElementById("floatFG");
	if(div)
	{
		document.body.removeChild(div);
	}
	
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id","floatBG");
	newdiv.style.position = "absolute";
	newdiv.style.zIndex = 5;
	newdiv.style.backgroundColor = "#61BDFF";
	
	newdiv.style.filter = "alpha(opacity=50)"; 
	newdiv.style.mozOpacity = "0.5";
	newdiv.style.opacity = "0.5";
	
	newdiv.style.width = document.body.clientWidth+"px";
	newdiv.style.height = document.body.clientHeight+document.body.scrollTop+"px";
	newdiv.style.paddingTop = 0;
	
	newdiv.style.top = 0+"px";
	newdiv.style.left = 0+"px";
	
	document.body.appendChild(newdiv);
	//------------------------------------
	//------------------------------------
	
	newdiv1 = document.createElement("div");
	newdiv1.setAttribute("id","floatFG");
	newdiv1.style.position = "absolute";
	newdiv1.style.zIndex = 7;
	//newdiv1.style.backgroundColor = "#FFFFFF";
	
	newdiv1.style.overflow = "visible";
	
	newdiv1.style.width = wid +"px";
	newdiv1.style.height = hei +"px";
	newdiv1.style.paddingTop = 0;
	newdiv1.style.display = "none";
	
	var box = "";
	box += '<div style="width: '+(wid)+'px; position: relative;"><!--PopUp-->';
    box += '<div style="height: 44px; width: 44px; overflow: hidden; position: absolute; right: 0;"><!--Cross-->';
    box += '<a href="#" onclick="';
	if(flag == null)
	{
		box += 'closeDialog(); ';
	}
	else
	{
		box += 'switchPaymentCard('+flag+'); ';
	}
	box += 'return false;"><img src="'+document.location.protocol+'//www.socialbuy.com/images/pop_cross.png" width="44" height="44" border="0"/></a>';
    box += '</div><!--Cross-->';
    box += '<div style="height: 28px;"><!--Top-->';
    box += '<div style="float: left; height: 28px; width: 33px; background: url('+document.location.protocol+'//www.socialbuy.com/images/popup_top_left.png) no-repeat;"></div>';
    box += '<div style="float: left; height: 28px; width: '+(wid-66)+'px; background: url('+document.location.protocol+'//www.socialbuy.com/images/popup_top_mid.png) repeat-x;">';
    //box += '<h1 style="font: bold 24px Georgia; color: #5F3E29; text-align: center; padding-top: 30px;">Add A New Card</h1>';
    //box += '<h1 style="font: bold 13px Georgia; color: #777; text-align: center; padding-top: 0px;">Enter Your Creadit Card Information Below.</h1>';                                       
    box += '</div>';
    box += '<div style="float: left; height: 28px; width: 33px; background: url('+document.location.protocol+'//www.socialbuy.com/images/popup_top_right.png) no-repeat;"></div>';
    box += '<div class="clear"></div>';
    box += '</div><!--Top-->';
    box += '<div style="overflow: hidden;"><!--Mid-->';
    box += '<div style="float: left; height: '+(hei-28)+'px; width: 33px; background: url('+document.location.protocol+'//www.socialbuy.com/images/popup_mid_left.png) repeat-y;"></div>';
    box += '<div style="float: left; height: '+(hei-28)+'px; width: '+(wid-66)+'px; background-color: #fff; overflow: hidden;" id="dialogcontent">';
    box += '</div>';
    box += '<div style="float: left; height: '+(hei-28)+'px; width: 33px; background: url('+document.location.protocol+'//www.socialbuy.com/images/popup_mid_right.png) repeat-y;"></div>';
    box += '<div class="clear"></div>';
    box += '</div><!--Mid-->';
    box += '<div style="height: 28px;"><!--Bot-->';
    box += '<div style="float: left; height: 28px; width: 33px; background: url('+document.location.protocol+'//www.socialbuy.com/images/popup_bot_left.png) no-repeat;"></div>';
    box += '<div style="float: left; height: 28px; width: '+(wid-66)+'px; background: url('+document.location.protocol+'//www.socialbuy.com/images/popup_bot_mid.png) repeat-x;"></div>';
    box += '<div style="float: left; height: 28px; width: 33px; background: url('+document.location.protocol+'//www.socialbuy.com/images/popup_bot_right.png) no-repeat;"></div>';
    box += '<div class="clear"></div>';
    box += '</div><!--Bot-->';
    box += '</div><!--PopUp-->';
    box += '<div class="clear"></div>';
	
	//newdiv1.style.top = ((winH+document.body.scrollTop)/2)-100+"px";
	//newdiv.style.top = ((document.body.clientHeight-(height+30))/2) + document.body.scrollTop;
	//alert(f_clientHeight()+":"+f_scrollTop());
	
	var top = (((parseInt(f_clientHeight())-hei)/2) + parseInt(f_scrollTop()));
	var left = ((parseInt(f_clientWidth())/2)-(wid/2));
	if(top < 10)
	{
		top = 10;
	}
	
	if(left < 0)
	{
		left = 0;
	}
	
	newdiv1.style.top = top+"px";
	
	newdiv1.style.left = left+"px";
	document.body.appendChild(newdiv1);
	newdiv1.innerHTML = box;
	showDialogLoading(document.getElementById('dialogcontent'));
	$("#floatFG").slideToggle("slow");
	return document.getElementById("dialogcontent");
}
function showDialogLoading(div)
{	
	div.innerHTML = "<div style='text-align:center; padding-top:10px;'><img src='"+ verifyLink(server_path+'images/loader.gif'); + "' style='vertical-align: middle;'/></div>";
}
function closeDialog()
{
	$("#floatFG").slideToggle("slow");
	//var div = document.getElementById("floatFG");
	//document.body.removeChild(div);
	var div = document.getElementById("floatBG");
	document.body.removeChild(div);
	$("#floatBG").css("display","none");
}
function showDialogNew(wid,hei,flag)
{ 
	var div = document.getElementById("floatFG");
	if(div)
	{
		document.body.removeChild(div);
	}
	
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id","floatBG");
	newdiv.style.position = "absolute";
	newdiv.style.zIndex = 5;
	newdiv.style.backgroundColor = "#61BDFF";
	
	newdiv.style.filter = "alpha(opacity=50)"; 
	newdiv.style.mozOpacity = "0.5";
	newdiv.style.opacity = "0.5";
	
	newdiv.style.width = document.body.clientWidth+"px";
	newdiv.style.height = document.body.clientHeight+document.body.scrollTop+"px";
	newdiv.style.paddingTop = 0;
	
	newdiv.style.top = 0+"px";
	newdiv.style.left = 0+"px";
	
	document.body.appendChild(newdiv);
	//------------------------------------
	//------------------------------------
	
	newdiv1 = document.createElement("div");
	newdiv1.setAttribute("id","floatFG");
	newdiv1.style.position = "absolute";
	newdiv1.style.zIndex = 7;
	//newdiv1.style.backgroundColor = "#FFFFFF";
	
	newdiv1.style.overflow = "visible";
	
	newdiv1.style.width = wid +"px";
	newdiv1.style.height = hei +"px";
	newdiv1.style.paddingTop = 0;
	newdiv1.style.display = "none";
	
	var box = "";
	box += '<div style="width: '+(wid)+'px; position: relative;"><!--PopUp-->';
    box += '<div style="height: 44px; width: 44px; overflow: hidden; position: absolute; right: -20px; margin-top:-14px; z-index:10;"><!--Cross-->';
    box += '<a href="#" onclick="';
	if(flag == null)
	{
		box += 'closeDialog(); ';
	}
	else
	{
		box += 'urlRedirect('+flag+'); ';
	}
	box += 'return false;"><img src="'+document.location.protocol+'//www.socialbuy.com/images/pop_cross.png" width="44" height="44" border="0"/></a>';
    box += '</div><!--Cross-->';
    
    box += '<div style="overflow: hidden;"><!--Mid-->';
    box += '<div style="float: left; height: '+(hei)+'px; width: '+(wid)+'px; overflow: hidden;" id="dialogcontent">';
    box += '</div>';
    
    box += '<div class="clear"></div>';
    box += '</div><!--Mid-->';
    box += '</div><!--PopUp-->';
    box += '<div class="clear"></div>';
	
	//newdiv1.style.top = ((winH+document.body.scrollTop)/2)-100+"px";
	//newdiv.style.top = ((document.body.clientHeight-(height+30))/2) + document.body.scrollTop;
	//alert(f_clientHeight()+":"+f_scrollTop());
	
	var top = (((parseInt(f_clientHeight())-hei)/2) + parseInt(f_scrollTop()));
	var left = ((parseInt(f_clientWidth())/2)-(wid/2));
	if(top < 10)
	{
		top = 10;
	}
	
	if(left < 0)
	{
		left = 0;
	}
	
	newdiv1.style.top = top+"px";
	
	newdiv1.style.left = left+"px";
	document.body.appendChild(newdiv1);
	newdiv1.innerHTML = box;
	showDialogLoading(document.getElementById('dialogcontent'));
	$("#floatFG").slideToggle("slow");
	return document.getElementById("dialogcontent");
}
function gagaSignupPopup()
{
	showDialog(350,500);
	var msg = "";
	
    msg += '<div class="popup">';
    msg += '<table style="margin: 0 auto;" width="80%" border="0" cellpadding="0" cellspacing="0">';
    msg += '<tr><td><img src="images/lady_gaga/lady_gaga_popup.jpg" alt="" /></td></tr>';
    msg += '<tr><td><h1 style="font: bold 20px Arial; color: #000; line-height: 16px; padding-left: 18px;">CONGRATULATIONS!</h1></td></tr>';
    msg += '<tr><td><p style="font: bold 12px Arial; color: #444; padding: 0 18px;">You are entered into tha Lady Gaga Los Angeles Sweepstakes and have the chance to win a VIP Packege to the Lady Gaga Concert in August 12, 2010 at the LA Staples Center.</p></td></tr>';
    msg += '<tr><td><p style="font: italic bold 12px Arial; color: #000; padding: 0 18px;">Increase your chances of winning by referring your friends to SocialBuy!</p></td></tr>';
    msg += '<tr><td><p style="font: bold 12px Arial; color: #444; padding: 0 18px;">&bull;&nbsp;Earn 1 extra entry, for every friend you refer, who Signs up to SocialBuy</p></td></tr>';
    msg += '<tr><td><a href="#" style="font: bold 14px Arial; color: #00aaef; padding-left: 18px; letter-spacing: -1px;">CLICK TO INCREASE YOUR CHANCES</a></td></tr>';
    msg += '</table>';
    msg += '</div>';
	
	var div = document.getElementById("dialogcontent");
	div.innerHTML = msg;
}
//----------------------------------------------------------------
//POPUP SIGNIN START
//----------------------------------------------------------------
function getSignInPopup(flag,reUrl)
{
	showDialogNew(610,653);
	site_url = "ajaxcall/process_an.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=getGagaSignin&reUrl="+reUrl+"",
		success: function(msg){
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
	});
}
function popupSignIn(reUrl)
{
	var error = "";
	

	error+=  validateEmail(document.getElementById('emailS'));
	error+=  validateEmpty(document.getElementById('passwordS'));
	
	if (error == "") 
	{
		var email = document.getElementById('emailS').value;
		var pass  = document.getElementById('passwordS').value;
		site_url = "ajaxcall/process_an.php";
		$.ajax({
			type: "POST",
			url: site_url,
			data: "p=signin&email=" + email + "&pass=" + pass,
			
			success: function(msg){
				//alert(msg);
				if (msg == "ok") 
				{
					//location.href = verifyLink("accountOverview.php?m=0", 0);
					location.href = verifyLink(reUrl, 0);
				}
				else 
				{
					alert(msg);
				}
			}
		});
	}
	else
	{
		alert(error);
	}
}

function submitSignupPop(reUrl)
{


	var erObj = document.getElementById('errorSU');
	
	
	if(document.getElementById("name").value == "")
	{
		erObj.innerHTML = "Provide your name";
		return false;
	}
	else if(document.getElementById("email1").value != document.getElementById("email2").value)
	{
		erObj.innerHTML = "Email address do not matched";
		return false;
	}

	else if(validateEmail(document.getElementById("email1")) != "")
	{
		erObj.innerHTML = validateEmail(document.getElementById("email1"));
		return false;
	}
	else if(validatePassword(document.getElementById("pass1")) != ""){

		erObj.innerHTML = validatePassword(document.getElementById("pass1"))
		return false;
	}
	else if(document.getElementById("pass1").value != document.getElementById("con").value)
	{
		erObj.innerHTML = "Passwords do not match";
		return false;
	}
	else if(document.getElementById("ts").checked != true)
	{
		erObj.innerHTML = "You must agree to the Terms of Use and Privacy policy.";
		return false;
	}
	else
	{
		var site_url = "ajaxcall/process.php";
		
		var email    = document.getElementById('email1').value;
		var pass     = document.getElementById('pass1').value;
		var name     = document.getElementById('name').value;

		$.ajax({
		type: "POST",
		url: site_url,
		data: "p=signInEmail&emailId="+email,
		success: function(msg)
		{

			if (msg == "hasRow") {
				erObj.innerHTML = ("This E-mail id already exists in our database.");
				return false;
			}
			else {
				var site_url = "ajaxcall/process_an.php";
				$.ajax({
					type: "POST",
					url: site_url,
					data: "p=signupPop&email=" + email + "&name=" + name + "&pass=" + pass,
					success: function(msg){
						if(msg!= '0')
						{
							location.href = verifyLink(reUrl, 0);
						}
					}
				});
			}
		}
 	});
 	

	return false;
		
	}
	
}
//----------------------------------------------------------------
//POPUP SIGNIN END
//----------------------------------------------------------------

function urlRedirect(url)
{
	window.location = server_path + url;
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function moreadd(deal_id)
{
	showDialog(400,350);
	
	site_url = server_path+"ajaxcall/process.php";
	$.ajax({
		type: "POST",
		url: site_url,
		data: "p=moreadd&deal_id="+deal_id,
		success: function(msg)
		{
			var div = document.getElementById("dialogcontent");
			div.innerHTML = msg;
		}
 	});
}