// JavaScript Document
popUpWin = 0;
function popUpWindow(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollBars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function popUpWindowMenubar(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollBars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function popUpWindow_scroll(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollBars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function PopupPic(sPicURL) { 
	
	window.open(wwwroot+"/popup.html?"+sPicURL, "", "resizable=1,HEIGHT=300,WIDTH=200");
	}
	
	
function cNum(e) {
	var strCheck = '0123456789.\b\t';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 0 || whichCode == 13)
	{
		return true ;		
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function cNumPhone(e) {
	var strCheck = '0123456789\b\t	 +()[]-';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 0 || whichCode == 13)
	{
		return true ;		
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function validInput(e) {
	var strCheck = '0123456789\b\tABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if ((whichCode == 0 || whichCode == 13)||(whichCode == 65 || whichCode == 90))
	{
		return true ;		
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function getstars(fld,url)
{
	if(fld.name == "use")
	{
		loadDoc2('rate.php?use_div=1&use='+fld.value,'','use_img');
	}
	
	if(fld.name == "clean")
	{
		loadDoc2('rate.php?clean_div=1&clean='+fld.value,'','clean_img');
	}	
}

function changedoc(pdfdoc)
{
	var getlink = document.getElementById('pdflink');	
	getlink.href=pdfdoc;
	//alert(getlink.href);
	window.print();
}
function showCategoriesFilter(position) {
		if (position == null) {
			position = '';
		}
	source = document.getElementById("typeSelect"+position);
	dest = document.getElementById("catySelect"+position);
	box = document.getElementById("stextbox"+position);
  //dest = document.getElementById("catySelectPanel");
 // panel = document.getElementById("dropDownPanel");

  if(source.value == 'p') {
    dest.style.display = "inline";
	//box.size = '17';
	box.style.width = '150px';
  } else {
    dest.selectedIndex = 0;
    dest.style.display = "none";
	//box.size = '45';
	box.style.width = '310px';
  }

}
function getNextFeatureAjax(direction, user_action)
  {
  if (direction == null) {
  	previous = 'next';
  }
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
		
	
			xmlHttp.onreadystatechange=function() {
				  
				  //var form = document.forms['cart_quantity'];
				  
				  if(xmlHttp.readyState==4) {
				  	var response = xmlHttp.responseText;
						if (document.getElementById('best_sellers')) {
							if (user_action == 'true') {
								document.getElementById('featured_buttons').style.display = 'block';
								document.getElementById('processing_request').style.display = 'none';
							}
							document.getElementById('rotating_features_box').innerHTML = response;
						}
					//alert(response);
					
					//eval(response);
					
				  }
			  }
	if (user_action == 'true') {
		document.getElementById('featured_buttons').style.display = 'none';
		document.getElementById('processing_request').style.display = 'block';
	}
    xmlHttp.open("GET",'rotating_features_ajax.php?direction=' + direction,true);
	xmlHttp.send(null);
	rotatingFeaturesTime = setTimeout('getNextFeature(\'' + direction + '\')', 10000);
	
  }
  
	/*var error = false;
	var error_message = "";
	
		function check_input(field_value, message) {
		
			if (field_value == '') {
			  error_message = error_message + "* " + message + "\n";
			  error = true;
			}

		}*/
	function getNextFeature(direction, user_action) {
		if ((direction != 'next') && (direction != 'previous')) {
			direction = 'next';	
		}
		if ((direction == 'previous') && (user_action != 'true')) {
			direction = 'next';	
		}
		//var form = document.forms[form_name];
		clearTimeout(rotatingFeaturesTime);
		
		//alert(price + ' - ' + weight + ' - ' + city + ' - ' + postcode + ' - ' + country + ' - ' + state + ' - ' +delivery_month + ' - ' +delivery_day + ' - ' +delivery_year+ ' - ' +products_id); 
		getNextFeatureAjax(direction, user_action);
				
	}
	function addEvent(obj, evType, fn, useCapture){
if (obj.addEventListener){
  obj.addEventListener(evType, fn, useCapture);
  return true;
} else if (obj.attachEvent){
  var r = obj.attachEvent("on"+evType, fn);
  return r;
// } else {alert("Handler could not be attached");
}
}
var rotatingFeaturesTime;
var bestSellersTime;
function startRotation() {
/*
	//rotatingFeaturesTime = setTimeout('getNextFeature()', 10000); 
	//bestSellersTime = setTimeout('getBestSellers()', 10000);
	//alert(document.getElementById('columnLeft').offsetHeight + ' - ' + document.getElementById('columnLeftContents').offsetHeight);
	var column_left_free_space = document.getElementById('columnLeft').offsetHeight - document.getElementById('columnLeftContents').offsetHeight;
	showBannersAjax(column_left_free_space, 'left');
	var column_right_free_space = document.getElementById('columnRight').offsetHeight - document.getElementById('columnRightContents').offsetHeight;
	showBannersAjax(column_right_free_space, 'right');
*/
}
function showBannersAjax(free_space, position)
  {
  
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
		
	
			xmlHttp.onreadystatechange=function() {
				//var form = document.forms['cart_quantity'];
				  if(xmlHttp.readyState==4) {
				  	var response = xmlHttp.responseText;
						if (document.getElementById('bannerAds')) {
							if (position == 'left') {
								document.getElementById('bannerAds').innerHTML = response;
							}
						}
						if (document.getElementById('right_banner_ads')) {
							if (position == 'right') {
								document.getElementById('right_banner_ads').innerHTML = response;
							}
						}
				  }
			  }

    xmlHttp.open("GET",'banner_ads_ajax.php?free_space='+free_space+'&position='+position,true);
	xmlHttp.send(null);
}
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D to bookmark");
  }
}
function fixPNG(myImage) // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
    if (window.ie55up)
	 {
	 var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	 var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	 var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "
	 var imgStyle = "display:inline-block;" + myImage.style.cssText 
	 var strNewHTML = "<span " + imgID + imgClass + imgTitle
	 strNewHTML += " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";"
	 strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	 strNewHTML += "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>" 
	 myImage.outerHTML = strNewHTML
	 }
   }
   function popupWindow_outblush(url) {
window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=520,height=220,screenX=150,screenY=150,top=150,left=150')
}
function init() 
{
	//scrollablediv 2
	var scroller2 = new Bs_ScrollableDiv();
	scroller2.init('divContainer_2', 'divContent_2');
	
    var sliderObj2 = new Bs_Slider();
	sliderObj2.attachOnChange(Bs_ScrollableDiv_sliderChange);
	sliderObj2.width          = 13;
	sliderObj2.height         = 180;
	sliderObj2.arrowMouseOver = true;
	sliderObj2.valueDefault   = 0; //we don't start at position 0 by default. this is in percent.
	sliderObj2.direction      = 1;
	sliderObj2.imgDir         = 'javascript/images/';
	sliderObj2.setSliderIcon('scroll_bar.gif', 10, 76);
	sliderObj2.setArrowIconLeft('scroll_up.gif', 13, 11);
	sliderObj2.setArrowIconRight('scroll_down.gif', 13, 11);
	
	
	scroller2.setSliderObject(sliderObj2, 'sliderDiv2');
	scroller2.setSlideSpeed(40, 'pixel'); //50 pixel per second
	scroller2.setWheelSpeed(20, 'pixel'); //20 pixel per tick
}


    if (document.images) {
      preload_image_object = new Image();
      // set image url
      image_url = new Array();
      image_url[0] = "/images/sd.jpg";
      image_url[1] = "/images/sd_hov.jpg";
      image_url[2] = "/images/sd_arrow.jpg";
      image_url[3] = "/images/sd_arrow_hov.jpg";
	  image_url[4] = "/images/categories_submenu_1st_item.gif";
	  image_url[5] = "/images/categories_menu_main_category_w_arrow.gif";
	  image_url[6] = "/images/categories_menu_main_category_selected.gif";
	  image_url[7] = "/images/categories_menu_main_category_w_arrow_interact.gif";
	  image_url[8] = "/images/logo.gif";
	  image_url[9] = "/images/logo_hover.gif";
	  image_url[10] = "/images/header_search_go.gif";
	  image_url[11] = "/images/header_search_go_hover.gif";
	  image_url[12] = "/images/header_button.jpg";
	  image_url[13] = "/images/header_button_hover.jpg";
	  image_url[14] = "/images/button_prev_hover.jpg";
	  image_url[15] = "/images/button_prev.jpg";
	  image_url[16] = "/images/button_pause_hover.jpg";
	  image_url[17] = "/images/button_pause.jpg";
	  image_url[18] = "/images/button_next_hover.jpg";
	  image_url[19] = "/images/button_next.jpg";
	  image_url[20] = "/images/best_sellers_button_pause_hover.jpg";
	  image_url[21] = "/images/best_sellers_button_pause.jpg";
	  image_url[22] = "/images/best_sellers_button_play_hover.jpg";
	  image_url[23] = "/images/best_sellers_button_play.jpg";
	  image_url[24] = "/images/button_yellow.jpg";
	  image_url[25] = "/images/button_yellow_hover.jpg";

       var i = 0;
       for(i=0; i<26; i++) 
         preload_image_object.src = image_url[i];
    }
