// JavaScript Document

function mobileDetector()
{
	if((navigator.userAgent.match(/iPad/i))) {
		document.write("<link type=\"text\/css\" rel=\"stylesheet\" media=\"all\" href=\"http:\/\/www.carvart.com\/styles\/global\/carvart_base_mobile.css\" charset=\"utf-8\" \/>");
		document.write("<meta name=\"viewport\" content=width=1024px, minimum-scale=1.0, maximum-scale=1.0 \/>");
	}
	
	else if(navigator.userAgent.match(/iPhone/i)) {
		document.write("<link type=\"text\/css\" rel=\"stylesheet\" media=\"all\" href=\"http:\/\/www.carvart.com\/styles\/global\/carvart_base_mobile.css\" charset=\"utf-8\" \/>");
		document.write("<meta name=\"viewport\" content=width=768px, minimum-scale=1.0, maximum-scale=1.0 \/>");
	}
	
	else if((navigator.userAgent.match(/android/i)) || (navigator.userAgent.match(/opera/i)) || (navigator.userAgent.match(/blackberry/i)) || (navigator.userAgent.match(/palm/i)) || (navigator.userAgent.match(/windows/i))) {
		//document.write("<link type=\"text\/css\" rel=\"stylesheet\" media=\"all\" href=\"http:\/\/www.carvart.com\/styles\/global\/carvart_base_mobile.css\" charset=\"utf-8\" \/>");
	}
	
	else
	{
	}
}

/*$(document).ready(function() 
{
	if((navigator.userAgent.match(/iPad/i))) {
		//$('head').append('<link rel="stylesheet" href="http://www.carvart.com/newsite2/styles/global/carvart_base_mobile.css" type="text/css" />');
		//$('head').append('<meta name="viewport" content="width=1024px, minimum-scale=1.0, maximum-scale=1.0" />');
		
		//document.write("<link type=\"text\/css\" rel=\"stylesheet\" media=\"all\" href=\"http:\/\/www.carvart.com\/styles\/global\/carvart_base_mobile.css\" charset=\"utf-8\" \/>");
		//document.write("<meta name=\"viewport\" content=width=1024px, minimum-scale=1.0, maximum-scale=1.0 \/>");
	}
	
	else if(navigator.userAgent.match(/iPhone/i)) {
		$('head').append('<link rel="stylesheet" href="http://www.carvart.com/newsite2/styles/global/carvart_base_mobile.css" type="text/css" />');
		$('head').append('<meta name="viewport" content="width=768px, minimum-scale=1.0, maximum-scale=1.0" />');
		
		//document.write("<link type=\"text\/css\" rel=\"stylesheet\" media=\"all\" href=\"http://www.carvart.com\newsite2\styles\global\carvart_base_mobile.css\" charset=\"utf-8\" \/>");
		//document.write("<meta name=\"viewport\" content=width=768px, minimum-scale=1.0, maximum-scale=1.0 \/>");
	}
	
	else if((navigator.userAgent.match(/android/i)) || (navigator.userAgent.match(/opera/i)) || (navigator.userAgent.match(/blackberry/i)) || (navigator.userAgent.match(/palm/i)) || (navigator.userAgent.match(/windows/i))) {
		$('head').append('<link rel="stylesheet" href="http://www.carvart.com/newsite2/styles/global/carvart_base_mobile.css" type="text/css" />');
	}
	
	else
	{
	}

//if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/android/i)) || (navigator.userAgent.match(/opera/i)) || (navigator.userAgent.match(/blackberry/i)) || (navigator.userAgent.match(/palm/i)) || (navigator.userAgent.match(/windows/i)))
});
*/

function copyrightYear()
{
  var currentYear = (new Date).getFullYear();
  $(document).ready(function() {
    $("#year").text(currentYear);
  });
}
						   

function checkCountry()
{
	$(document).ready(function() {
	
		if($.cookies.test())
		{
			var selectedCountry = $.cookies.get('selectedCountry');
			var curlocation=window.location;
			var location="";
			
			if(selectedCountry!=null && selectedCountry!="en")
			{
				//location="http://www.carvart.com/" + selectedCountry + "/";
				
				$.cookies.del('selectedCountry');  
		   		$.cookies.set('selectedCountry', "en" );
				
				location="http://www.carvart.com/";
				
				if(curlocation !=location)
				{
					window.location.replace(location);
					
				}
			}
		}
	
	});
	

}

function setLinks()
{
	$(document).ready(function() {
   // put all your jQuery goodness in here.
   
   if( $.cookies.test() )
   {
	   //browser is accepting cookies
	   var selectedCountry = $.cookies.get('selectedCountry');
	   
	   var siteURL="http://www.carvart.com/newsite2";
	   
	   var hrefURL="";
		   
	   $("a[href]").each(function()
		{
			hrefURL=this.href;

			hrefURL=hrefURL.replace(/^http:\/\/www\.carvart\.com/,'');
			
			if(hrefURL=="/worldwide/")
				this.href=siteURL + hrefURL;
				
			else
			{
				if($(this).parent().parent().parent().attr("id")=="globalmenu")
				{
					if(selectedCountry!=null && selectedCountry!="en")
						this.href=siteURL + "/" + selectedCountry + hrefURL;
				
					else
						this.href=siteURL + hrefURL;
				}
				
				else
				{
				
				if($(this).parent().is("li"))	
					if($(this).parent().parent().attr("id")=="languageSelector")
						this.href=siteURL + hrefURL;
						
					
					 else if($(this).parent().parent().attr("id")=="productItemList")
					 {
					  }
				

				
				else if(selectedCountry!=null && selectedCountry!="en")
					this.href=siteURL + "/" + selectedCountry + hrefURL;
				
				else
					this.href=siteURL + hrefURL;
				}
			}
		});
	   
	   //disable languages not available yet
	   $("#languageSelector li a").each(function(){
												 
										hrefURL=this.href;
										hrefURL=hrefURL.replace(/^http:\/\/www\.carvart\.com/,'');
										hrefURL=hrefURL.replace('newsite2','');
										
										if(hrefURL=="/es/" || hrefURL=="ru/")
										{
											this.href=siteURL + "/";
										}
								  });
	   
	   $("#cse-search-box").attr("action", "http://www.carvart.com/search/");
   }
   
   });
}

function setCountry(country)
{
	  if(country=="es" || country=="ru")
	  {
	  	return false;
	  }
	  
	else
	{
	  if( $.cookies.test() )
   	  {
		  //browser is accepting cookies
		   var selectedCountry = $.cookies.get('selectedCountry');
		   
		   if(selectedCountry!=null)
		   {
			   $.cookies.del('selectedCountry');
		   }
		   
		   $.cookies.set('selectedCountry', country );
	  }
	}
}

function getGup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function disableSearch()
{
	$(document).ready(function() {
		$('#search-input').attr("disabled", "disabled");
		$('#search-button').attr("disabled", "disabled"); 
	});
}

copyrightYear();
//setLinks();
mobileDetector();
disableSearch();
