function readCookie(name)

{

  var cookieValue = "";

  var search = name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = unescape(document.cookie.substring(offset, end))

    }

  }

  return cookieValue;

}

function writeCookie(name, value, hours, path)

{

  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }
  if(path!=null)
  {
	   path = "; path=" + path;
  }

  document.cookie = name + "=" + escape(value) + expire + path;

}

function writeCookieDomain(name, value, hours, path, domain)

{

  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }
  if(path!=null)
  {
	   path = "; path=" + path;
  }
  
  if(domain!=null)
  {
	   domain = "; domain=" + domain;
  }


  document.cookie = name + "=" + escape(value) + expire + path  + domain;

}


function showpop(id)
{
	//var onsurvey=readCookie("onsurvey");
	//var already=readCookie("already");
	var popup=readCookie("popup_begin");	
	writeCookie("back",id,3,"/");
	//Neu co already, onsurvey thi khong hien ra
	
		if(popup==null || popup=="")
		{
			if(id!="46")
			{
				writeCookie("popup_begin","1",1,"/");	
				//writeCookie("popup1234","1",1,"/");	Khong set cai nay de cho 10% hien ra
				var agreewin=dhtmlmodal.open("agreebox", "iframe", "/SurveyAttention_Begin.aspx", "Tell Us About Your Dog's Situation", "width=654px,height=375px,center=1,resize=0,scrolling=0", "recal");
			
				agreewin.onclose=function(){ //Define custom code to run when window is closed
				}	
			}
		}	
	
}

function showpop_close(id)
{
	//var onsurvey=readCookie("onsurvey");
	//var already=readCookie("already");
	var popup=readCookie("popup1234");
	//Neu co already, onsurvey thi khong hien ra
	writeCookie("back",id,3,"/");

		if(popup==null || popup=="")
		{					
			writeCookie("popup1234","1",1,"/");		
			//writeCookie("popup_begin","1",1,"/");
			var agreewin1=dhtmlmodal.open("agreebox1", "iframe", "/surveyattention_end.html", "10% Discount Offer For New Customers", "width=654px,height=375px,center=1,resize=0,scrolling=0", "recal");
		
			agreewin1.onclose=function(){ //Define custom code to run when window is closed
			}	
		}				
	
}

function showpop_cart()
{/*
	//var already=readCookie("already");
	var popup=readCookie("popup1234");
	//Neu co already, onsurvey thi khong hien ra
		
		if(popup==null || popup=="")
		{		
				
			writeCookie("popup1234","1",1,"/");		
			//writeCookie("popup_begin","1",1,"/");
			var agreewin2=dhtmlmodal.open("agreebox2", "iframe", "/surveyattention_end.html", "10% Discount Offer For New Customers", "width=654px,height=375px,center=1,resize=0,scrolling=0", "recal");
		
			agreewin2.onclose=function(){ //Define custom code to run when window is closed
			}	
		}				
	*/
}


function showpop_close_newv2(id)
{
	/*
	var popup=readCookie("popup1234");
	var already=readCookie("already");
	var o10=readCookie("o10");
	
	//writeCookie("back",id,3,"/");
	
	//Neu co cac popup tren thi khong hien nua
	if(already!="" || o10!="")
	{}else{
		if(popup==null || popup=="")
		{	
						
			writeCookie("popup1234","1",2,"/");		
			
				var sidebar=document.getElementById("sidebar");
				if(sidebar!=null)
				{
				sidebar.style.display='none';
				sidebar.style.visibility='hidden';
				}
				
			var agreewin1=dhtmlmodal.open("agreebox1", "div", "popupend", "10% Discount Offer For New Customers", "width=654px,height=355px,center=1,resize=0,scrolling=0","");
		
			agreewin1.onclose=function(){ //Define custom code to run when window is closed
				showagain();
				return true;
			}	
			
		}			
	}
	*/
}

function showpop_beginv2(id)
{
	
	
	var popup=readCookie("popup_begin");	
	var onsurvey=readCookie("onsurvey");
	var already=readCookie("already_survey");
	writeCookie("back",id,3,"/");
	
	if(onsurvey!="" || already!="")
	{}else{
		if(popup==null || popup=="")
		{
			if(id!="46")
			{
				var sidebar=document.getElementById("sidebar");
				
				sidebar.style.display='none';
				sidebar.style.visibility='hidden';
				
				writeCookie("popup_begin","1",1,"/");
				
				var agreewin2=dhtmlmodal.open("agreebox", "div", "popupbegin", "Tell Us About Your Dog's Situation To Receive Recommended Products", "width=654px,height=355px,center=1,resize=0,scrolling=0", "");
			
				agreewin2.onclose=function(){ //Define custom code to run when window is closed
					showagain();
					return true;
				}					
			}
		}				
	}
	
	
}

function showagain()
{
	var sidebar=document.getElementById("sidebar");
	
	sidebar.style.display='block';
	sidebar.style.visibility='visible';
	
}


function show_sidebar(id)
{
	
	//if(id!="129")
	//{	
		var survey=readCookie("already_survey");
		var bought=readCookie("already");
		var o10=readCookie("o10");
	
		writeCookie("back",id,3,"/");
		
		var sidebar=document.getElementById("sidebar");
		
		sidebar.style.display='block';
		sidebar.style.visibility='visible';
		
		if(bought!="" || survey != "" || o10!="" || !window.XMLHttpRequest)//Mua roi khong hien len gi het
		{
			sidebar.style.display='none';
			sidebar.style.visibility='hidden';
			
		}else{//Hien het 2 hinh
			//sidebar.style.background='url(/images/NEW-CONSULT_03_CANINE.png) no-repeat top right';
		}
	//}else{
	//	var sidebar=document.getElementById("sidebar");
	//	sidebar.style.display='none';
	//	sidebar.style.visibility='hidden';
	//}
}

function closethis()
{
	
		var sidebar=document.getElementById("sidebar");
		sidebar.style.display='none';
		sidebar.style.visibility='hidden';
		
		writeCookie("already_survey",0,3,"/");
	
}





function showpop_close_cats(id)
{
	/*
	var popup=readCookie("popup1234");
	var already=readCookie("already");
	var o10=readCookie("o10");
	
	//writeCookie("back",id,3,"/");
	
	//Neu co cac popup tren thi khong hien nua
	if(already!="" || o10!="")
	{}else{
		if(popup==null || popup=="")
		{					
			writeCookie("popup1234","1",2,"/");				
				
			var agreewin1=dhtmlmodal.open("agreebox1", "div", "popupend", "10% Discount Offer For New Customers", "width=654px,height=355px,center=1,resize=0,scrolling=0","");
		
			agreewin1.onclose=function(){ //Define custom code to run when window is closed
				return true;
			}	
		}			
	}
	*/
}

function showpop_begin_cats(id)
{
	var popup=readCookie("popup_begin");	
	var onsurvey=readCookie("onsurvey");
	var already=readCookie("already_survey");
	writeCookie("back",id,3,"/");
	
	if(onsurvey!="" || already!="")
	{}else{
		if(popup==null || popup=="")
		{
				writeCookie("popup_begin","1",1,"/");
				
				var agreewin2=dhtmlmodal.open("agreebox", "div", "popupbegin", "Tell Us About Your Cat's Situation To Receive Recommended Products", "width=654px,height=355px,center=1,resize=0,scrolling=0", "");
			
				agreewin2.onclose=function(){ //Define custom code to run when window is closed
					
					return true;
				}					
			
		}				
	}
}


function show_sidebar_article(id)
{		
		var already=readCookie("already_survey");
		writeCookie("back",id,3,"/");
		var sidebar=document.getElementById("sidebar");
		
		sidebar.style.display='block';
		sidebar.style.visibility='visible';
		
		if(!window.XMLHttpRequest || already!="")//Mua roi khong hien len gi het
		{
			sidebar.style.display='none';
			sidebar.style.visibility='hidden';
			
		}
}

