var cat_img_filepath = "/v/vspfiles/templates/reunioncoffe/images/main_img/";
var default_img_filepath = "/v/vspfiles/templates/reunioncoffe/images/main_img/main_XX.jpg";

function setCatImg(imgfile,dimgfile){	

	setGET();
	var cat = window.location.GET["cat"];

	if(typeof cat == 'undefined'){
		var str = window.location.pathname;
		str = str.match(/\b-s\/\d+\.htm/i);
		if(str != null ){
			str = str[0].replace('.htm','');
			str = str.replace('-s/','');
			cat = str;
		}
	}

	var imgfile = imgfile+cat+".jpg";
	try {
		if( typeof cat != 'undefined' ){

			// custom to hide product images on category pages
			document.getElementById("prod_img").style.display = "none";
			//
			
			var xmlhttp=false;
			var val=false;
			/*@cc_on @*/
			/*@if (@_jscript_version >= 5)
			// JScript gives us Conditional compilation, we can cope with old IE versions.
			// and security blocked creation of the objects.
			 try {
			  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
			  try {
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (E) {
			   xmlhttp = false;
			  }
			 }
			@end @*/
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
				try {
					xmlhttp = new XMLHttpRequest();
				} catch (e) {
					xmlhttp=false;
				}
			}
			if (!xmlhttp && window.createRequest) {
				try {
					xmlhttp = window.createRequest();
				} catch (e) {
					xmlhttp=false;
				}
			}
			
			xmlhttp.open("HEAD",imgfile,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					if (xmlhttp.status==200){
						document.getElementById("cat_img").style.backgroundImage = "url("+imgfile+")";
						document.getElementById("cat_img").style.display = "block";
					}
					else{
						//UNCOMMENT BELOW TO SHOW DEFAULT IMG DIV
						//document.getElementById("default_img").style.backgroundImage = "url("+dimgfile+")"; //uncomment to turn on background image
						document.getElementById("default_img").style.display = "block";
					}
				}
			}
			xmlhttp.send(null);
		}else{

			if(PageName()=="one-page-checkout.asp" || PageName()=="shoppingcart.asp"){
				document.getElementById("default_img").style.display = "none"; //turn off DEFAULT IMG DIV on checkout page
			}else{
				//UNCOMMENT BELOW TO SHOW DEFAULT IMG DIV
				//document.getElementById("default_img").style.backgroundImage = "url("+dimgfile+")"; //uncomment to turn on background image
				document.getElementById("default_img").style.display = "block";
			}



		}
	}catch (e) {}
}

function setGET() {
   var get = (""+location.search.toLowerCase()).substring(1).split("&");
   window.location.GET = new Array();
   for (var i in get) {
      var temp=get[i].split("=");
      window.location.GET[temp[0]]=temp.splice(1,temp.length-1).join("=");
   }
}
