var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editting needed
var ie5=document.all
var ns6=document.getElementById&&!document.all

$(document).ready(function() {
	searchDeafult('Search a Deal');	
	
	if(Trim(Get_Cookie('res')) != '' && Trim(Get_Cookie('res')) != null)
	{
		var which = Trim(Get_Cookie('res'));
		$(('div[resolution1=1]')).attr("class",""+which+"");
	}
	/*
	if(Trim(Get_Cookie('addtocode')) != '' && Trim(Get_Cookie('addtocode')) != null)
	{
		document.getElementById("loginParams").className = 'log-det-cont';
		document.getElementById("loginParams").innerHTML = "<div class='loginanme-head'><span class='topb-link'><a href='/user-dashboard.php'>Your Dashboard</a></span><br /><span class='topb-link'><a href='/user-logout.php'>Logout</a></span></div><div class='loginanme-head'><b>Welcome, "+Trim(Get_Cookie('addtoname'))+"</b><br /><span>If you are not <a href='/user-logout.php'>"+Trim(Get_Cookie('addtoname'))+"?</a></span></div>";
	}
	else
	{
		document.getElementById("loginParams").className = 'log-reg-cont';
		document.getElementById("loginParams").innerHTML = "<ul><li class='register'><a href='javascript:void(0)' style='cursor:pointer;' id='topreg1' myId='registerId' onclick=\"return createLightBoxReg(this.id,'/register.php','RegisterDiv','theDoc','deal','50'); return false;\" >Register</a></li><li class='login'><a href='javascript:void(0)' style='cursor:pointer;' id='toplogin1' myId='loginId' onclick=\"return createLightBoxReg(this.id,'/login.php','LoginDiv','theDoc','deal','50'); return false;\">Login</a></li></ul>";
	}
	*/
  });						  

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden){
if (ie5||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function dropdownmenu(obj, e, dropmenuID){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous menu
dropmenuobj.style.visibility="hidden"
clearhidemenu()
if (ie5||ns6){
obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(dropmenuID)
if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
dropmenuobj.onmouseover=clearhidemenu
dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
showhide(dropmenuobj.style, e, "visible", "hidden")
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
return clickreturnvalue()
}

function clickreturnvalue(){
if ((ie5||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie5&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function changeMenu(curItem)
{
	switch(curItem)
	{
		case "Stores" :
		document.getElementById('searchDiv').innerHTML = "<input type='text' name='txtsearch' value='Search a Store' style='float:left;' id='txtsearch' defaultTxt='' /><a class='anylinkcss-a' href='javascript:void(0)' onClick=\"return clickreturnvalue()\" onMouseover=\"dropdownmenu(this, event, 'anylinkmenu1')\">Stores</a><div id='anylinkmenu1' class='anylinkcss'><a href='javascript:void(0)' onclick=\"changeMenu('Deals')\";>Deals</a></div><input type='hidden' name='pressed' id='pressed' value='Stores'  />";
		searchDeafult('Search a Store');
		break;
		/*case "Coupons" :
		document.getElementById('searchDiv').innerHTML = "<input type='text' name='txtsearch' value='Search a Coupon' style='float:left;'  id='txtsearch' defaultTxt='Search a Coupon' /><a class='anylinkcss-a' href='javascript:void(0)' onClick=\"return clickreturnvalue()\" onMouseover=\"dropdownmenu(this, event, 'anylinkmenu1')\">Coupons</a><div id='anylinkmenu1' class='anylinkcss'><a href='javascript:void(0)' onclick=\"changeMenu('Deals')\";>Deals</a><a href='javascript:void(0)' onclick=\"changeMenu('Stores');\">Stores</a></div><input type='hidden' name='pressed' id='pressed' value='Coupons'  />";
		searchDeafult('Search a Coupon');
		break;*/
		case "Deals" :
		document.getElementById('searchDiv').innerHTML = "<input type='text' name='txtsearch' value='Search a Deal' style='float:left;' id='txtsearch' defaultTxt='Search a Deal'  /><a class='anylinkcss-a' href='javascript:void(0)' onClick=\"return clickreturnvalue()\" onMouseover=\"dropdownmenu(this, event, 'anylinkmenu1')\">Deals</a><div id='anylinkmenu1' class='anylinkcss'><a href='javascript:void(0)' onclick=\"changeMenu('Stores')\";>Stores</a></div><input type='hidden' name='pressed' id='pressed' value='Deals'  />";
		searchDeafult('Search a Deal');
		break;
	}
	
}
function searchDeafult(defaultText)
{
/**************** COmment start for serach box ***********************************/

			var searchBoxes = $("#txtsearch");
			var searchBox2 = $("#txtsearch");
			
			//var searchBox2Default = "Search a Deal";
			//Effects for both searchbox
			//Searchbox1, set focus when document is ready
			
			//Searchbox2 show/hide default text if needed
			searchBox2.focus(function(){
				if($(this).attr("value") == defaultText) $(this).attr("value", "");
			});
			searchBox2.blur(function(){
				if($(this).attr("value") == "") $(this).attr("value", defaultText);
			});

/**************** COmment end for serach box ***********************************/
}

function changeResolution(which)
{	
	if(document.getElementById('mainCont') != '' && document.getElementById('mainCont') != 'undefined' && document.getElementById('mainCont') != null)
	{
		document.getElementById('mainCont').className = which;
	}
	else
	{
		$(('div[resolution1=1]')).attr("class",""+which+"");
	}
	Set_Cookie('res', which, 365); 		
	return false;
}

/********************     TOP MENU JS ********************/

var zindex=100;
			function showmenu(menuid,buttonid) {
				if (eval('typeof(menuisvisible_'+menuid+')==\'undefined\'')) {
					eval('menuisvisible_'+menuid+'=false; showingmenu_'+menuid+'=false; hidingmenu_'+menuid+'=false; menubuttonid_'+menuid+'=\''+buttonid+'\'');
				}
				eval('shouldshowmenu_'+menuid+'=true;');
				showmenunow(menuid);
			}
			function showmenunow(menuid) {
				if (eval('menuisvisible_'+menuid+'==false') && eval('shouldshowmenu_'+menuid+'==true') && eval('showingmenu_'+menuid+'==false') && eval('hidingmenu_'+menuid+'==false')) {
					eval('shouldhidemenu_'+menuid+'=false; showingmenu_'+menuid+'=true');
					
					var obj = document.getElementById(eval('menubuttonid_'+menuid));
					var curleft = curtop = 0;
					var i = 1;
					while (obj) {
						curleft += obj.offsetLeft;
						curtop += obj.offsetTop;
						obj = obj.offsetParent;
						i++;
					}
					
					var e=document.getElementById(menuid);
					e.style.position="absolute";
					e.style.top=curtop+"px";
					e.style.left=curleft+"px";
					e.style.display="inline";
					e.style.zIndex=zindex++;
					time = 500;
					p=50;
					t=0;
					s= 100/(time/p);
					o=0;
					changeOpac(o,menuid);
					while (o<=100) {
						setTimeout("changeOpac("+Math.round(o)+",'"+menuid+"')",t);
						o=o+s;
						t = t+p;
					}
					setTimeout('showingmenu_'+menuid+'=false; menuisvisible_'+menuid+'=true; hidemenunow(\''+menuid+'\');',t+p);
				}
				
			}
			function hidemenu(menuid) {
				eval('shouldshowmenu_'+menuid+'=false');
				setTimeout('hidemenunow(\''+menuid+'\')', 600);
			}
			function hidemenunow(menuid) {
				if (eval('menuisvisible_'+menuid+'==true') && eval('shouldshowmenu_'+menuid+'==false') && eval('hidingmenu_'+menuid+'==false') && eval('showingmenu_'+menuid+'==false')) {
					eval('hidingmenu_'+menuid+'=true');
					time = 500;
					p=50;
					t=0;
					s= 100/(time/p);
					o=100;
					changeOpac(o,menuid);
					while (o>=0) {
						setTimeout("changeOpac("+Math.round(o)+",'"+menuid+"')",t);
						o=o-s;
						t = t+p;
					}
					setTimeout('document.getElementById(\''+menuid+'\').style.left= \'-999em\';changeOpac(100,\''+menuid+'\'); hidingmenu_'+menuid+'=false; menuisvisible_'+menuid+'=false; showmenunow(\''+menuid+'\');',t+p);
				}
			}
			function changeOpac(opacity, id) { 
			    var object = document.getElementById(id).style; 
			    object.opacity = (opacity / 100); 
			    object.MozOpacity = (opacity / 100); 
			    object.KhtmlOpacity = (opacity / 100); 
			    object.filter = "alpha(opacity=" + opacity + ")"; 
			}
			
/*************     END OF TOP MENU JS **************************************/			

function validateSearch()
{
	//alert(document.getElementById('pressed').value);	
	if(document.getElementById('pressed').value == 'Deals')	
	{
		document.searchform.action = '/search-deal.php';	
	}
	if(document.getElementById('pressed').value == 'Stores')	
	{
		document.searchform.action = '/search-store.php';	
	}
	//document.searchform.submit();
	
	return true;
}

var timestart     = 500;
var timeout     = 500;
var tabclosetimer  = 0;
var tabitem  = 0;
var tabheader  = 0;

// open hidden layer
function tabopen(id)
{   
	  // cancel close timer
	  tabcancelclose();
	  // close old layer
	  if(tabitem) 
	  {
	  	tabitem.style.visibility = 'hidden';
		tabitem.style.display = 'block';
	  }
	  if(tabheader) tabheader.className = 'fullTab';
	  
	  // get new layer and show it
	  tabitem = document.getElementById(id);
	  tabitem.style.visibility = 'visible';
	  tabitem.style.display = 'block';
	  tabheader = document.getElementById(id + 'TB');
	  tabheader.className = 'highTab';
}
// close showed layer
function closetab()
{
	  if(tabitem) tabitem.style.visibility = 'hidden';
	  if(tabheader) tabheader.className = 'fullTab';
}
// go close timer
function tabclose()
{
	  tabclosetimer = window.setTimeout(closetab, timeout);
}
// cancel close timer
function tabcancelclose()
{
	  if(tabclosetimer)
	  {
			window.clearTimeout(tabclosetimer);
			tabclosetimer = null;
	  }
}
// close layer when click-out
document.onclick = closetab; 
var isActive = false;	



/***Light box functions****/
function createLightBoxReg(id,url,divElem,bodyId,tableType,DivWidth)
{
	divIdLight =  $('#'+id+'').attr("myId");
	
	if(document.getElementById(divElem) != null)
	{
		document.getElementById(divElem).style.display = 'block';
		document.getElementById(divElem).innerHTML="<div align='center' style='margin-top:50px;'><img src='/images/loading.gif' ></div>";
	}
	
	if(url != '')
	{
		$("#"+divElem+"").load(""+url+"",{ 'id': [""+divIdLight+""],'case1':[tableType] });
	}
	lightBoxReg(''+bodyId+'',''+divElem+'',DivWidth);	
}
function lightBoxReg(bodyId,showId,customWidth)
{	
	divHeight = $("#"+showId+"").offset().top;	
	model_img = document.createElement('img');
	model_img.setAttribute('src','/images/topbg.gif');
	myWidth = document.getElementById(bodyId).offsetWidth;
	myHeight = document.getElementById(bodyId).scrollHeight;
	model_img.setAttribute('width',myWidth);
	model_img.setAttribute('height',myHeight);
	
	//model_img.setAttribute('z-index',1100);
	model_img.style.top = 0;
	model_img.style.position = "absolute";
	
	model_img.style.zIndex=10;
	model_img.style.opacity=0.6;
	model_img.style.MozOpacity = '0.7';
	model_img.style.filter="alpha(opacity=60)";	
	tempHeight = screen.height/2;		

	//if(navigator.appVersion.match('MSIE 6.0'))
	//{
		$( "#"+showId+"" ).scrollFollow({
				//offset: divHeight
		});		
	//}
	//alert(document.getElementById(showId).innerHTML);
	document.body.appendChild(model_img);	
	myWidth = document.getElementById(bodyId).scrollWidth;	
	
	document.getElementById(showId).style.display = "block";
	tempWidth = screen.width-((myWidth*customWidth)/100);
	leftPos = tempWidth/2;	
	document.getElementById(showId).style.left = leftPos+"px";	
	//document.getElementById(showId).style.zIndex = 1000;
}

function closeLightBoxReg(id)
{
	//alert(id);
	document.body.removeChild(model_img);
	divClose = $("#"+id+"").attr("parentDiv");
	//alert(divClose);
	document.getElementById(divClose).innerHTML = "";
	document.getElementById(divClose).style.display = "none";
}

function askReg(id)
{
	closeLightBoxReg('closeDivReg2');
	createLightBoxReg(id,'/register.php','RegisterDiv','theDoc','deal','50');	
}

function askLogin(id)
{
	closeLightBoxReg('closeDivReg1');
	createLightBoxReg(id,'/login.php','LoginDiv','theDoc','deal','50');	
}

function askForgot(id)
{
	closeLightBoxReg('closeDivReg2');
	createLightBoxReg(id,'/forgot-password.php','ForgotDiv','theDoc','deal','50');
}

function socialMediaBackOld(closeId,id,url,div,bodyId,width)
{
	closeLightBoxRev(closeId);
	createLightBoxRev(id,url,div,bodyId,'deal',width);
}

function socialMediaBack(id,url,div,bodyId,tableType,width)
{
	closeLightBoxRev('closeDiverr3');
	createLightBoxRev(id,url,div,bodyId,tableType,width);
}

/************ functions for Refresh Cdoe link *******************/
function loadcode(pass1,pgUrl)
{

	xmlHttp4 = GetXmlHttpObject();
	
	url= '/'+pgUrl+'?'+pass1;
	
	if(document.getElementById("vrfCode") != null)
	{
		document.getElementById("vrfCode").style.display = 'block';
		document.getElementById("vrfCode").innerHTML="<img src='/images/loader2.gif' >";
	}			
	xmlHttp4.onreadystatechange= showcode
	xmlHttp4.open("GET",url,true)
	xmlHttp4.send(null);    
}

function showcode()
{
	if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete")
	{
		//alert(xmlHttp4.responseText);
		document.getElementById("vrfCode").innerHTML=xmlHttp4.responseText;
		xmlHttp4 = null;
	}
}
/************ functions for Refresh Cdoe link *******************/

