// this function replaces an element by given "id" with a table holding the
// element itself and left and right columns holding the round edges as backgrounds
// * width, height - parameters to define the width and height of the round edges 
// height also is used to generate and use the name of the images with specific height
// * color - used to generate the name of the corner images with the specific color
// (for ex. white,black etc. according to the used images)
function roundEdges(id,width,height,color) {
 var source = document.getElementById(id);
	 
 if (source) {
 
 source.style.border = '0px';	
 if (source.style.width != null) {
  var srcWidth = parseInt(source.style.width);
  if (srcWidth > width*2) source.style.width = (srcWidth - (width*2))+ 'px';	 
 }
	 
 /**/
 
 
 /* new page fragment */
 var fragment= document.createDocumentFragment();

 /* block.onclick= function() { alert("here"); };*/

 /* new table to hold the round edges and the element */
 var tbl = document.createElement("table");
 tbl.cellSpacing = "0";
 tbl.cellPadding = "0";
 
 var row = document.createElement("tr");
 var columnLeft = document.createElement("td");
 /*columnLeft.style.width = width + 'px';
 columnLeft.style.height = height + 'px';*/
 var divLeft = document.createElement("div");
 divLeft.style.width = width + 'px';
 divLeft.style.height = height + 'px';
 divLeft.style.background = 'url(img/roundedges/roundinput_' + height + 'px_' + color + '_left.png) no-repeat';
 columnLeft.appendChild(divLeft);
 
 var columnMiddle = document.createElement("td");
 /* copy source */
 columnMiddle.appendChild(source.cloneNode(true));
 
 var columnRight = document.createElement("td");
 var divRight = document.createElement("div");
 divRight.style.width = width + 'px';
 divRight.style.height = height + 'px';
 divRight.style.background = 'url(img/roundedges/roundinput_' + height + 'px_' + color + '_right.png) no-repeat';
 columnRight.appendChild(divRight);
 
 row.appendChild(columnLeft);
 row.appendChild(columnMiddle);
 row.appendChild(columnRight);
 
 tbl.appendChild(row);

 /* put table in page fragment */
 fragment.appendChild(tbl)

 /* replace source with new fragment (contains a copy of source) */
 source.parentNode.replaceChild(fragment, source);
 
 }
}

var defaultRoundEdgeHeight = 15; 
//according to the default height from main.css for inputs and selects of the body

// * wrapperID - the id of wrapper element holding the elements 
// to which to add round corners (inputs and selects in this version)
// the function in this version adds round edges 
// if the type of each element is "text" or "select"
// * width, height - parameters to define the width and height of the round edges 
// height also is used to generate and use the name of the images with specific height
// according to the height of the elements defined in their style. 
// If thre is no height set in the style then 
// the default height is used (defaultRoundEdgeHeight)  
//* color - used to generate the name of the corner images with the specific color
//(for ex. white,black etc. according to the used images)
function roundElements(wrapperID,width,height,color) {
 function setElements(tag,type){
 var inp = wrapper.getElementsByTagName(tag);
  for (var i = 0; i < inp.length; i++) {
	if (inp.item(i).type == type || type == null) {	
	 var height = parseInt(inp.item(i).style.height) + 2;
	 if (height == null) height = defaultRoundEdgeHeight;
	 if (inp.item(i).id) { roundEdges(inp.item(i).id,width,height,color); }
	}  
  } 
 }
 var wrapper = document.getElementById(wrapperID);
 if (wrapper && width != null && height != null && color != null) {
  setElements('input','text');
  setElements('select',null);
 }
}

// set on/off hover class for buttons created as <td> tags
// * obj - the DOM object of the <td> tag
// * on  - if set to true  - then set the hover class
// 		   if set to false - then set the original class
function setHover(obj,on) {
 if (on == true) {
  obj.className = 'lightButtonHover'; 
 }else {
  obj.className = 'lightButton';
 }
}

var focusedForm = "";

function bigImage(){
	
	img_path = document.getElementById('BASEIMG').attributes['src'].nodeValue;
	img_name = img_path.split('/');
	img_name = img_name[(img_name.length-1)].replace('productBig_', '');
	img_name = img_name.replace('.jpg', '');
	window.open('index.php?page=imgrender&img='+img_name, '_blank');
}

function bigOfferImage(offer_id){
	
	img_path = document.getElementById('BASEIMG').attributes['src'].nodeValue;
	img_name = img_path.split('/');
	img_name = img_name[(img_name.length-1)].replace('imgBig_', '');
	img_name = img_name.replace('.jpg', '');
	window.open('index.php?page=imgrender&o='+offer_id+'&oimg='+img_name, '_blank');
}

function submitCurrentDealerImage(imgId)
{
	var currHiddenImageProp = document.getElementById('dealerImageNumber');
	currHiddenImageProp.value = imgId;
	
	document.getElementById('uploadPhotoes').submit();	
}

function checkFocused(){
	var f = document.forms;
	
	
	function setFocusedForm(fe,ff){
	 var f1 = document.forms;
	 var formID = '';
	 for(var k=0; k < f1.length; k++){	
	  var el1 = document.forms[k].elements;
	  for(var l=0; l < el1.length; l++){
	   if ((el1[l].name == fe) && (el1[l].form.id == ff)) {
	   	//focusedForm = document.forms[k].name;
	   	//submitFocusedForm(document.forms[k].name);
  	    formID = el1[l].form.id;   
	   }
	  }
	 }
	 
	 if (formID != '') {
	  submitFocusedForm(formID);
	 }
	}



	function KeyCheck(e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;	
	var focusedElement = this.name;
	var focusedForm = this.form.id;
	
	switch(KeyID)
	{
	  case 13:
	   setFocusedForm(focusedElement,focusedForm);
	  break;   
	}
	}

	for(var j=0; j < f.length; j++){	
	var el = document.forms[j].elements;
	for(var i=0; i < el.length; i++){
     if (el[i].type == 'text') {
	  el[i].onkeydown = KeyCheck;
     }
	}
	}
}

	function submitFocusedForm(formName){
		divID = document.getElementById('submitProfileId');
	 switch (formName)
	 {
	  	case "quickSearchForm":
	 		document.getElementById('GoFromGeneralSearch').name='go_ADVANCEDSEARCH';
      		document.getElementById('GoFromGeneralSearch').value='1';
	  		document.getElementById('quickSearchForm').submit();
	  		break;
	  	case "advancedSearch":	
	  		document.getElementById('GoFromGeneralSearch').name='GoAdvSearch'; document.getElementById('advancedSearch').submit();
	  		break;
	  	case "searchRefinePanelForm":
	  		document.getElementById('dealerListingsRefinePanel').name='goFromItems'; 
	  		document.getElementById('dealerListingsRefinePanel').value='1'; 
	  		document.getElementById('searchRefinePanelForm').submit();
	  		break;
	 }
		
	}

function submitLoginForm()
{
 document.loginForm.submit();	
}

var popUPWindow='';
function popUPRequestForm(ownerID, productID, setUserOffer) {
	if (setUserOffer == false) {
		popUPWindow=window.open("index.php?page=requestform&ownerid="+ownerID+'&prod='+productID+"","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=390");
	}
	else {
		popUPWindow=window.open("index.php?page=requestform&ownerid="+ownerID+'&offer='+productID+"","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=390");
	}
}

function popUpPaypalForm(titlecont, userID) {
	popUPWindow=window.open("index.php?page=paypalform&titlecont="+(encodeURI(titlecont)+'&userid='+userID)+"","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=460");
}

/**
 * @purpose            : Get the (x,y) coordinate of a DOM element
 * @param  object elem : a DOM element or null
 * @return object      : an associative array, where indicies "x"
 *                       and "y" hold their respective coordinates
 * @note               : function is recursive
 */
function getXYpos(elem) {
   if (!elem) {
      return {"x":0,"y":0};
   }
   var xy={"x":elem.offsetLeft,"y":elem.offsetTop}
   var par=getXYpos(elem.offsetParent);
   for (var key in par) {
      xy[key]+=par[key];
   }
   return xy;
}

function Left(obj)
{
var curleft = 0;
if (obj.offsetParent)
while (1) {
curleft += obj.offsetLeft;
if (!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

function Top(obj)
{
var curtop = 0;
if (obj.offsetParent)
while (1) {
curtop += obj.offsetTop;
if (!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if (obj.y)
curtop += obj.y;
return curtop;
}

function setModalAccountPanelSize() {
  var pageWidth = 0;
  var d = document.getElementById('modalPanelCreateAccountWrapper');
  var p = document.getElementById('modalPanelCreateAccount');
  
  /*if( window.innerHeight && window.scrollMaxY ) // Firefox 
    {
	pageWidth = window.innerWidth + window.scrollMaxX;
	pageHeight = window.innerHeight + window.scrollMaxY;
	}
	else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
	{
	pageWidth = document.body.scrollWidth;
	pageHeight = document.body.scrollHeight;
	}
	else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
	{ pageWidth = document.body.offsetWidth + document.body.offsetLeft; pageHeight = document.body.offsetHeight + document.body.offsetTop; }*/

  d.style.top = 0;
  d.style.left = 0;
  p.style.top = 0;
  p.style.marginTop = '20px';
  
  if (BrowserDetect.browser == 'Explorer') {
   pageWidth = document.body.offsetWidth + document.body.offsetLeft;
   d.style.width = pageWidth + 'px';
   d.style.height = document.body.childNodes[0].offsetHeight + 'px';
  }
  else {
   pageWidth = document.body.childNodes[1].offsetWidth;
   d.style.width = document.body.childNodes[1].offsetWidth + 'px';
   d.style.height = document.body.childNodes[1].offsetHeight + 'px';
  }
  
  if (pageWidth > 600) {p.style.left = (pageWidth-600)/2 + 'px';}
}

function showHideSelects(show) {
 var s1 = document.getElementById('selectCatsID');
 var s2 = document.getElementById('searchByTypeID');
 var s3 = document.getElementById('selectSortByID');
 var d1 = document.getElementById('iFinderAdvSearch');
 var d2 = document.getElementById('iFinderContent1');
 var d3 = document.getElementById('iFinderContent2');
 var s4 = document.getElementsByName('advancedSearchPosted');
 var s5 = document.getElementsByName('advancedSearchByCountry[]');
 var s6 = document.getElementsByName('advancedSearchShowResultsPerPage');
 var s7 = document.getElementsByName('countryFromDealerCategoryPage');
 var l = document.getElementById('loginBox');
 var f = document.getElementById('feedBox');
 
 if (show == false) {
  if (s1) s1.style.visibility = 'hidden';
  if (s2) s2.style.visibility = 'hidden';
  if (s3) s3.style.visibility = 'hidden';
  if ((d1.style.visibility == 'visible') && (d2.style.visibility == 'hidden') && (d3.style.visibility == 'hidden')) {
   if (s4) s4.item(0).style.visibility = 'hidden';
   if (s5) s5.item(0).style.visibility = 'hidden';
   if (s6) s6.item(0).style.visibility = 'hidden';
  }
  if ((d2.style.visibility == 'visible') || (d3.style.visibility == 'visible')) {
   if (s7) s7.item(0).style.visibility = 'hidden';
   if (s7) s7.item(1).style.visibility = 'hidden';
  }
 } else {
  if (s1) s1.style.visibility = ''; 
  if (s2) s2.style.visibility = '';
  if ((l.style.visibility != 'visible') && (f.style.visibility != 'visible')) {if (s3) s3.style.visibility = '';}
  if ((d1.style.visibility == 'visible') && (d2.style.visibility == 'hidden') && (d3.style.visibility == 'hidden')) {
   if (s4) s4.item(0).style.visibility = '';
   if (s5) s5.item(0).style.visibility = '';
   if (s6) s6.item(0).style.visibility = '';
  }
  if ((d2.style.visibility == 'visible') || (d3.style.visibility == 'visible')) {
   if (s7) s7.item(0).style.visibility = '';
   if (s7) s7.item(1).style.visibility = '';
  }
 }
}

function showModalAccountPanel(show,defaultPersonalAcc)
{
 var d = document.getElementById('modalPanelCreateAccountWrapper');
 var p = document.getElementById('modalPanelCreateAccount');
 var pa = document.getElementById('createPersonalAccForm');
 var da = document.getElementById('createDealerAccForm');
 
 if (show == true) {
  if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version == 6)) {showHideSelects(false);}
  setModalAccountPanelSize();
  d.style.visibility = 'visible';
  p.style.visibility = 'visible';
  if (defaultPersonalAcc == true)
  {
  	showPersonalAccFormCreate();
  }
  else 
  {
  	 showCompanyAccFormCreate();
  } 
 } else {
  if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version == 6)) {showHideSelects(true);}
  p.style.visibility = 'hidden';
  d.style.height = '0px';
  d.style.width = '0px';
  d.style.visibility = 'hidden';
  pa.style.visibility = 'hidden';
  da.style.visibility = 'hidden';
  pa.style.display = 'none';
  da.style.display = 'none';
 }
}

function showPersonalAccFormCreate() {
 var pa = document.getElementById('createPersonalAccForm');
 var da = document.getElementById('createDealerAccForm');
 var ptl = document.getElementById('pAccTabLeft');
 var ptm = document.getElementById('pAccTabMiddle');
 var ptr = document.getElementById('pAccTabRight');
 var ctl = document.getElementById('cAccTabLeft');
 var ctm = document.getElementById('cAccTabMiddle');
 var ctr = document.getElementById('cAccTabRight');
 
 ptl.style.background = 'url(img/createacctab_left.gif)';
 ptm.style.backgroundColor = '#ebebeb';
 ptr.style.background = 'url(img/createacctab_right.gif)';
 ctl.style.background = 'none';
 ctm.style.backgroundColor = '#979797';
 ctr.style.background = 'none';
 
 da.style.visibility = 'hidden';
 da.style.height = '10px';
 da.style.display= 'none';
 pa.style.visibility = 'visible';
 pa.style.display= 'inline';
 pa.style.height = 'auto';
}

function showCompanyAccFormCreate() {
 var pa = document.getElementById('createPersonalAccForm');
 var da = document.getElementById('createDealerAccForm');
 var ptl = document.getElementById('pAccTabLeft');
 var ptm = document.getElementById('pAccTabMiddle');
 var ptr = document.getElementById('pAccTabRight');
 var ctl = document.getElementById('cAccTabLeft');
 var ctm = document.getElementById('cAccTabMiddle');
 var ctr = document.getElementById('cAccTabRight');
 
 ctl.style.background = 'url(img/createacctab_left.gif)';
 ctm.style.backgroundColor = '#ebebeb';
 ctr.style.background = 'url(img/createacctab_right.gif)';
 ptl.style.background = 'none';
 ptm.style.backgroundColor = '#979797';
 ptr.style.background = 'none';
 
 pa.style.visibility = 'hidden';
 pa.style.display= 'none';
 pa.style.height = '10px';
 da.style.visibility = 'visible';
 da.style.display= 'inline';
 da.style.height = 'auto';
}

function showScrollers(divIDLeft, divIDRight) {
 var l = document.getElementById(divIDLeft);
 var r = document.getElementById(divIDRight);
 if (l && r) {
  l.style.width = '10px';
  r.style.width = '10px';
  l.innerHTML = '<div style="position:relative;" onclick="scrollDiv(1,100,\'scrollContentSubCat\',\'scrollWrapperSubCat\');"><img border="0" style="cursor: pointer;" alt="Scroll left" title="Scroll left" src="img/continue_arrow_left.gif"/></div>';
  r.innerHTML = '<div style="position:relative;width:20px;" onclick="scrollDiv(0,100,\'scrollContentSubCat\',\'scrollWrapperSubCat\');"><img border="0" style="cursor: pointer;" alt="Scroll right" title="Scroll right" src="img/continue_arrow_right.gif"/></div>';
 }
}

function hideScrollers(divIDLeft, divIDRight) {
 var l = document.getElementById(divIDLeft);
 var r = document.getElementById(divIDRight);
 if (l && r) {
  l.style.width = '0px';
  r.style.width = '0px';
  l.innerHTML = '';
  r.innerHTML = '';
 }
}

function showMainScrollers(divIDLeft, divIDRight) {
 var l = document.getElementById(divIDLeft);
 var r = document.getElementById(divIDRight);
 if (l && r) {
  l.style.width = '10px';
  r.style.width = '10px';
  l.innerHTML = '<div style="position:relative;" onclick="scrollDiv(1,100,\'scrollContentMainCat\',\'scrollWrapperMainCat\');"><img border="0" style="cursor: pointer;" alt="Scroll left" title="Scroll left" src="img/continue_arrow_left.gif"/></div>';
  r.innerHTML = '<div style="position:relative;" onclick="scrollDiv(0,100,\'scrollContentMainCat\',\'scrollWrapperMainCat\');"><img border="0" style="cursor: pointer;" alt="Scroll right" title="Scroll right" src="img/continue_arrow_right.gif"/></div>';
 }
}

function hideMainScrollers(divIDLeft, divIDRight) 
{
 var l = document.getElementById(divIDLeft);
 var r = document.getElementById(divIDRight);
 if (l && r) {
  l.style.width = '0px';
  r.style.width = '0px';
  l.innerHTML = '';
  r.innerHTML = '';
 }
}

function showHideScrollers(resetScrollDivMargin) {
 if (resetScrollDivMargin == true) {
  var sd = document.getElementById('scrollContentSubCat');
  if (sd) {
	sd.style.marginLeft = '0px';  
  }
 }
 var w	= getCategoriesListWidth('subCategories','span');
 var s = document.getElementById('scrollWrapperSubCat');
 if (s) {
  if (w > parseInt(s.style.width)) showScrollers('scrollSubsLeftTD','scrollSubsRightTD'); else hideScrollers('scrollSubsLeftTD','scrollSubsRightTD');
 }
}

function showHideMainCatScrollers() {
 var w	= getCategoriesListWidth('mainCategories','ul');
 var s = document.getElementById('maincat_Menu_Wrapper_Div');
 if (s) {
  if (w > parseInt(s.style.width)) showMainScrollers('scrollLeftTD','scrollRightTD'); else hideMainScrollers('scrollLeftTD','scrollRightTD');
 }
}

function getCategoriesListWidth(divID,tagName) {
	var d = document.getElementById(divID);
	var subWidth = 0;
  if (d) {	
	var tags = d.getElementsByTagName(tagName);
	for (var i = 0; i < tags.length; i++) {
	 subWidth = subWidth + tags.item(i).scrollWidth; 	
	}
  }
  return subWidth;
} 

function parseScript(_source) {
	 var source = _source;
	 var scripts = new Array();
	 
	 // Strip out tags
	 while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
	  var s = source.indexOf("<script");
	  var s_e = source.indexOf(">", s);
	  var e = source.indexOf("</script", s);
	  var e_e = source.indexOf(">", e);
	  
	  // Add to scripts array
	  scripts.push(source.substring(s_e+1, e));
	  // Strip from source
	  source = source.substring(0, s) + source.substring(e_e+1);
	 }
	 
	 // Loop through every script collected and eval it
	 for(var i=0; i<scripts.length; i++) {
	  try {
	   eval(scripts[i]);
	  }
	  catch(ex) {
	   // do what you want here when a script fails
	  }
	 }
	 
	 // Return the cleaned source
	 return source;
}

/////// -> AJAX request.
//-> Have two arguments.
//-> 1 argument: TYPE-String, NAME-url, CONTAIN-request's url.
//-> 2 argument: TYPE-String, NAME-sec, CONTAIN-name of section which will contain the result.
//-> 3 argument: TYPE-Boolean, ..., CONTAIN-type of request (true or false).
var inProgress=false;
function fillup(url, sec, ajaxLoader, synchroType)
{
	var newxmlHttp=getXMLHttpRequest();

	inProgress=true;
	/*loaderEff(ajaxLoader);*/
	var content=document.getElementById(sec);

	newxmlHttp.onreadystatechange=function()
	{
		if(newxmlHttp.readyState==4)
		{
			if(content)
			{ 
				content.innerHTML=parseScript(newxmlHttp.responseText);
				if (content.id == 'subCategories') {
					showHideScrollers(true);
				}
			}
			inProgress=false;
			/*loaderEff(ajaxLoader);*/
			newxmlHttp=null;
		}
	}

newxmlHttp.open("GET", url, true);
newxmlHttp.send(null);
}

/////// -> Return XMLHttpRequest (object) ...
function getXMLHttpRequest()
{
	var xmlhttp=null;
	if (window.XMLHttpRequest && !document.all)		// Non-IE
	{
		xmlhttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)					// IE
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.opera)							// Opera
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		alert('SORRY, ajax requests not supported by browser...');
	}
	return xmlhttp;
}

/*function loaderEff(tagID)
{
	var objLoaderContainer=document.getElementById(tagID);
	if(inProgress==false)
	{
		objLoaderContainer.style.visibility='hidden';
	}
	else if(inProgress==true)
	{
		objLoaderContainer.style.visibility='visible';
	}
	else
	{
		objLoaderContainer.style.visibility='hidden';
	}
}*/

function scrollDiv(direction,step,divID, divWrapper)
{
 /* direction: 0 = left scroll; 1 = right scroll*/
     var md = document.getElementById(divID); 
     var wrapper = document.getElementById(divWrapper);
     var width = parseInt(md.style.width);
     var wrpWidth = parseInt(wrapper.style.width);
     var scrStep = -step;
     var mrg = 0;
        
     mrg = parseInt(md.style.marginLeft); 
   
     if ((Math.abs(mrg) + wrpWidth <= width) || (direction == 1)) {
         if (direction == 0) {
           mrg = mrg + scrStep;
         } else if (mrg < 0) {
           mrg = mrg - scrStep;
         }
    }
    md.style.marginLeft = mrg + 'px';
}

function showSubcategories(categoryID,divID)
{
	var url = 'ajax/generateSubCategories.php?mcat='+categoryID;
	fillup(url,divID,'ajaxLoader',false);
}

function checkAllSubCategories(subCatID)
{
 var d = document.getElementById('subCategories');
 var checks = d.getElementsByTagName('input');
 var s = document.getElementById(subCatID);
 
 if (d && s) {
 for (var i = 0; i < checks.length; i++) {
  if ((checks.item(i).type == "checkbox") && (checks.item(i).id != s.id)) {	 
   if (s.checked == true) {
	checks.item(i).checked = true; 
   } else {
	checks.item(i).checked = false;  
   }
  }
 }
 }
}

var additionalSiteSpacer = 0; 

function getProductsPerPage() {
 var divID = document.getElementById('resultsPerPageID');
 var productsNumber = parseInt((screen.availWidth-19-154-40)/251);
 var blankSpace = screen.availWidth-19-154-40-(productsNumber*251);
 additionalSiteSpacer = parseInt(blankSpace/2);
 fillup('ajax/generateResPerPage.php?res='+productsNumber, divID, 'ajaxLoader', true);
}

function showFaqAnswer(faqID, linkID)
{
	var url = 'ajax/generateFaqAnswer.php?id='+faqID;
	fillup(url, linkID,'ajaxLoader',true);
}

function activeFaqLink(tableID, ID)
{
	var linkId = document.getElementById(ID);
	var tableId = document.getElementById(tableID);
	var l = tableId.getElementsByTagName('a');
	
	for (var i=0;i < l.length;i++) 
	{
	 if (l.item(i).id != ID)
	 {
	  l.item(i).style.color = '#393939';
	  l.item(i).style.fontWeight = 'normal';
	 }		
	}
	
	linkId.style.color='#97241F';
	linkId.style.fontWeight = 'bold';
}

function checkSubCategoryAll(subCatID)
{
 var s = document.getElementById(subCatID);
 var a = document.getElementById('subcat0');
 
 if (s && a && (s.checked == false)) {
  a.checked = false; 
 } else if (s && a) {
  
  var d = document.getElementById('subCategories');
  var checks = d.getElementsByTagName('input');
  
  if (d) {
  
  var allchecked = true;
  
  for (var i = 0; i < checks.length; i++) {
   if ((checks.item(i).type == "checkbox") && (checks.item(i).id != a.id)) {	 
    if (checks.item(i).checked == false) {
 	 allchecked = false; 
    }
   }
  }
  
  if (allchecked == true) {
   a.checked = true;	  
  }
  
  } // if d
  
 }
}

function markTab(cat,divID,el)
{
 var catID = cat.toString();
 var elID = el.toString();
 var d = document.getElementById(divID);
 
 if (d) {
 
 var divElements = d.getElementsByTagName('li');

 for (var i=0; i < divElements.length; i++) {
 
  if (divElements.item(i).id.substr(elID.length) == catID) {
	  switch (divID) {
	  case 'mainCategories':
		  divElements.item(i).className = 'category_Tab_Active';
		  break;
	  case 'subCategories':
		  divElements.item(i).className = 'sub_category_Tab_Active';
		  break;
	  case 'iFinderTabs':
		  divElements.item(i).className = 'iFinderTabs_Item_Active';
		  break;
	  }	  
  } else {
	  switch (divID) {
	  case 'mainCategories':
		  divElements.item(i).className = 'category_Tab_Inactive';
		  break;
	  case 'subCategories':
		  divElements.item(i).className = 'sub_category_Tab_Inactive';
		  break;
	  case 'iFinderTabs':
		  divElements.item(i).className = 'iFinderTabs_Item';
		  break;
	  }
  }
 }
 
 }
}

function showTab(tab,divID)
{
 var d = document.getElementById(divID);
 if (d) {
 
 var divElements = d.getElementsByTagName('div');
 var tabID = tab.toString();
 var adv = document.getElementById('iFinderAdvSearch');
 var selects = adv.getElementsByTagName('select');
 
 for (var i=0; i < divElements.length; i++) {
  if (divElements.item(i).id.substr(divID.length) == tabID) {
   divElements.item(i).style.visibility = 'visible';
  } else if (divElements.item(i).id.substr(0,divID.length) == divID) {
   divElements.item(i).style.visibility = 'hidden';  
  }
 }
 
 if (adv && (adv.style.visibility == 'visible') && (tab != 0)) {
  for (var i=0; i < selects.length; i++) {
   selects.item(i).style.visibility = 'hidden'; 
  }
 } else if (adv && (adv.style.visibility == 'visible') && (tab == 0)) {
  for (var i=0; i < selects.length; i++) {
   selects.item(i).style.visibility = 'visible'; 
  } 
 }
 
 }
}

function showHidePanel(divID)
{
 var d = document.getElementById(divID); 
 var adv = document.getElementById('iFinderAdvSearch');
 var selects = adv.getElementsByTagName('select');
 
 if (d) {	 
  if  (d.style.visibility == 'hidden') {
   
   d.style.visibility = 'visible';
  } else {
   d.style.visibility = 'hidden'; 
  }
 
  if (adv && (adv.style.visibility == 'visible') ) {
   for (var i=0; i < selects.length; i++) {
    selects.item(i).style.visibility = 'visible'; 
   }
  } else if (adv && (adv.style.visibility == 'hidden')) {
   for (var i=0; i < selects.length; i++) {
   selects.item(i).style.visibility = 'hidden'; 
  } 
 }
  
 }
}

function refreshBoxesPosition() 
{
	if (document.getElementById('baseTableID')) {
     if (BrowserDetect.browser == 'Explorer') {
      //document.getElementById('baseTableID').style.width = screen.availWidth - (screen.availWidth > 1024 ? 0 : 19) + 'px';
	document.getElementById('baseTableID').style.width = screen.availWidth -  21 + 'px';
     } else {  
	  document.getElementById('baseTableID').style.minWidth = screen.availWidth - (screen.availWidth > 1024 ? 17 : 19) + 'px';
     }
	}
	
	if (document.getElementById('loginBox')) {
	 var l = document.getElementById('loginBox');
	 var f = document.getElementById('feedBox');
	 var lc = document.getElementById('loginLink');
	 var la = document.getElementById('topMenu_LoginBox_ArrowUp');
	 var fc = document.getElementById('feedLink');
	 var fa = document.getElementById('topMenu_FeedBox_ArrowUp');
	 /*var s = document.getElementById('selectSortByID');*/
	 
	  if (BrowserDetect.browser == 'Explorer') {
	   if (BrowserDetect.version == 6) {
	    l.style.left = (Left(lc)-10)+"px";
	    f.style.left = (Left(fc)+50)+"px";
	    la.style.left = Left(lc)+"px";
	    fa.style.left = (Left(fc)+220)+"px";
	    
	   /* if ((f.style.visible == 'visible') && (!((Left(f)+f.offsetWidth < Left(s)) || (Left(f) > Left(s)+s.offsetWidth)))) 
	     { s.style.visibility = 'hidden';} 
	    if ((l.style.visible == 'visible') && (!((Left(l)+l.offsetWidth < Left(s)) || (Left(l) > Left(s)+s.offsetWidth)))) 
	     { s.style.visibility = 'hidden';}*/
	   }
	   if (BrowserDetect.version == 7) {
	    l.style.marginLeft = (lc.offsetLeft-10)+"px";
	    f.style.marginLeft = (fc.offsetLeft-170)+"px";
	    la.style.marginLeft = lc.offsetLeft+"px";
	    fa.style.marginLeft = fc.offsetLeft+"px";
	   }
	  } else {
	   l.style.marginLeft = (lc.offsetLeft-10)+"px";
	   f.style.marginLeft = (fc.offsetLeft-170)+"px";
	   la.style.marginLeft = lc.offsetLeft+"px";
	   fa.style.marginLeft = fc.offsetLeft+"px";
	  } 
	}

	// refresh the widths of instrument finder panels

	var wrapper = document.getElementById('iFinder_Menu_Wrapper');
	var productBigImageHolder = document.getElementById('video_preview');
	
	document.getElementById('iFinderContent0').style.width = wrapper.scrollWidth + 'px';
	document.getElementById('iFinderContent1').style.width = wrapper.scrollWidth + 'px';
	document.getElementById('iFinderContent2').style.width = wrapper.scrollWidth + 'px';
	document.getElementById('iFinderContent3').style.width = wrapper.scrollWidth + 'px';
	document.getElementById('iFinderAdvSearch').style.width = wrapper.scrollWidth + 'px';
	document.getElementById('maincat_Menu_Wrapper_Div').style.width = (wrapper.scrollWidth-20) + 'px';
	document.getElementById('scrollWrapperSubCat').style.width = (wrapper.scrollWidth-60) + 'px';
	document.getElementById('scrollWrapperMainCat').style.width = (wrapper.scrollWidth-60) + 'px';
	
	if (productBigImageHolder) {
	if (document.getElementById('wrapperAll')) 
		document.getElementById('wrapperAll').style.width = (productBigImageHolder.scrollWidth-40) + 'px';
	if (document.getElementById('wrapperVideo')) 
	document.getElementById('wrapperVideo').style.width = (productBigImageHolder.scrollWidth-40) + 'px';
	if (document.getElementById('wrapperImage')) 
		document.getElementById('wrapperImage').style.width = (productBigImageHolder.scrollWidth-40) + 'px';
	}
	
	showHideScrollers(false);
	showHideMainCatScrollers();
}

function showHideBox(divID,show,obj,margin)
{
	 var d = document.getElementById(divID);
	 var errMsg = document.getElementById('loginFormErrId');
	 //var s = document.getElementById('selectSortByID');
	 
	 if (show == true) {
	  if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version == 6)) {
	   if (divID == 'feedBox') {
	    margin = margin +50;	
	   }
	    if (divID == 'topMenu_FeedBox_ArrowUp') {
	    margin = margin +210;	
	   }
	   d.style.left = (Left(obj)+margin)+"px";
	  } else {
	   if (divID == 'feedBox') {
	    margin = margin - 170;	
	   }
	   d.style.marginLeft = (obj.offsetLeft+margin)+"px";  
	  }
	  
	  d.style.visibility = 'visible';
	  /*if ((divID == 'feedBox') && (d.offsetLeft <= s.offsetLeft)) {s.style.visibility = 'hidden';}*/
	  if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version == 6)) {
	   /*if (!((Left(d)+d.offsetWidth < Left(s)) || (Left(d) > Left(s)+s.offsetWidth))) { s.style.visibility = 'hidden';}*/
	   //s.style.visibility = 'hidden';
	  }
	   if (errMsg && errMsg.style.visibility == 'hidden')
	  {
	  	errMsg.style.visibility = 'visible';
	  }
	 } else {
	  d.style.visibility = 'hidden';
	  if (errMsg && errMsg.style.visibility == 'visible')
	  {
	  	errMsg.style.visibility = 'hidden';
	  }
	  /*if (divID == 'feedBox') {s.style.visibility = 'visible';}*/
	  //if ((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version == 6)) {s.style.visibility = 'visible';}
	 }
}


function showTopMenuBox(divID,divArrow,obj) {
	 var d = document.getElementById(divID);
	 var dErr = document.getElementById('loginFormErrId');
	 
	 if (divID != 'feedBox') {
	  showHideBox('feedBox',false,obj,0);
	  showHideBox('topMenu_FeedBox_ArrowUp',false,obj,10);
	 }
	 if (divID != 'loginBox') {
	  showHideBox('loginBox',false,obj,0);
	  showHideBox('topMenu_LoginBox_ArrowUp',false,obj,10);
	 }
	/* if (divID != '') {
	  showHideBox('',false);
	  showHideBox('',false);
	 }*/
	 if (d && d.style.visibility == 'visible') {
	  showHideBox(divID,false,obj,0);
	  showHideBox(divArrow,false,obj,10);
	 } else if (d) {
	  showHideBox(divID,true,obj,0);
	  showHideBox(divArrow,true,obj,10);	 
	 }
}

function showSubCatSpacer(divID,show) {
	 var d = document.getElementById(divID);
	 var m = document.getElementById('maincat_Menu_Wrapper_Div');
	 if (show == true) {
	  //d.innerHTML = '<div style="height:35px;"></div>';
	  m.style.height = '64px';
	 } else {
	  //d.innerHTML = '';
	  m.style.height = '30px';
	 }
}

function showSelectedIcon(iconDivID) {
 var d = document.getElementById(iconDivID);
 d.style.visibility = 'visible';
}

function hideSelectedIcon(iconDivID) {
 var d = document.getElementById(iconDivID);
 d.style.visibility = 'hidden';
}

function searchPointerFocus(objCurrent)
{
	
	if(objCurrent.value==document.getElementById('advancedSearchFor__hidd').value || objCurrent.value==document.getElementById('advancedSearchFirstYear__hidd').value || objCurrent.value==document.getElementById('advancedSearchFirstPrice__hidd').value || ( document.getElementById('refineSearchCategory_hidd') && objCurrent.value==document.getElementById('refineSearchCategory_hidd').value))
	{
		objCurrent.value='';
	}	
}

function searchPointerFocus2(objCurrent)
{
	
	if(objCurrent.value==document.getElementById('refineSearchCategory_hidd').value || objCurrent.value==document.getElementById('refineSearchSubCategory_hidd').value)
	{
		objCurrent.value='';
	}	
}

function searchPointerBlur(objCurrent)
{
	if(objCurrent.value.match(/^\s+$/) || objCurrent.value=='')
	{
		if(objCurrent.attributes['checkKey'].nodeValue=='search')
		{
			objCurrent.value=document.getElementById('advancedSearchFor__hidd').value;
		}
		else if(objCurrent.attributes['checkKey'].nodeValue=='year')
		{
			objCurrent.value=document.getElementById('advancedSearchFirstYear__hidd').value;
		}
		else if(objCurrent.attributes['checkKey'].nodeValue=='price')
		{
			objCurrent.value=document.getElementById('advancedSearchFirstPrice__hidd').value;
		}
		else if(objCurrent.attributes['checkKey'].nodeValue=='categories__')
		{
			objCurrent.value=document.getElementById('refineSearchCategory_hidd').value;
		}
		else if(objCurrent.attributes['checkKey'].nodeValue=='subCategories__')
		{
			objCurrent.value=document.getElementById('refineSearchSubCategory_hidd').value;
		}
	}
	if(objCurrent.value.match(/^\s+/))
	{
		objCurrent.value=objCurrent.value.replace(/^\s+/,'');
	}
}

function showDealerProfile() {
 /*document.getElementById('activeTab').value = 0;*/
 document.getElementById('dealerProfileTab').style.backgroundColor = '#b0b0b0';
 document.getElementById('dealerInventoryTab').style.backgroundColor = '#636363';
 document.getElementById('dealerInventoryTabText').style.color = '#FFFFFF';
 document.getElementById('dealerProfileTabText').style.color = '#000000';
 
 document.getElementById('dealerProfile').style.height = 'auto';
 document.getElementById('dealerProfile').style.display = 'inline';
 if (BrowserDetect.browser == 'Explorer')  {
  document.getElementById('dealerProfile').style.display = 'inline-block';
 }
 document.getElementById('dealerProfile').style.position = '';
 document.getElementById('dealerProfile').style.visibility = 'visible';
 
 document.getElementById('dealerInventory').style.visibility = 'hidden';
 document.getElementById('dealerInventory').style.display = 'none';
 document.getElementById('dealerInventory').style.height = '10px';
 document.getElementById('dealerInventory').style.position = 'absolute';
}

function showDealerInventory() {
 /*document.getElementById('activeTab').value = 1;*/
 document.getElementById('dealerProfileTab').style.backgroundColor = '#636363';
 document.getElementById('dealerInventoryTab').style.backgroundColor = '#b0b0b0';
 document.getElementById('dealerProfileTabText').style.color = '#FFFFFF';
 document.getElementById('dealerInventoryTabText').style.color = '#000000';
 document.getElementById('dealerInventoryTab').style.backgroundColor = '#b0b0b0';
 
 document.getElementById('dealerProfile').style.visibility = 'hidden';
 document.getElementById('dealerProfile').style.display = 'none';
 document.getElementById('dealerProfile').style.height = '10px';
 document.getElementById('dealerProfile').style.position = 'absolute';
 
 document.getElementById('dealerInventory').style.height = 'auto';
 document.getElementById('dealerInventory').style.width = 'auto';
 document.getElementById('dealerInventory').style.position = '';
 document.getElementById('dealerInventory').style.display = 'inline';
 if (BrowserDetect.browser == 'Explorer') {
  document.getElementById('dealerInventory').style.display = 'inline-block';
 }
 document.getElementById('dealerInventory').style.visibility = 'visible';
}

function showHideDealerDetailsTab(divID,imgID) {
 var d = document.getElementById(divID);

  if (d) {
  var img = document.getElementById(imgID);
  if (d.style.visibility == 'hidden') {
    if (img) {
	 img.src = 'img/continue_arrow_up.gif';  
    }
	d.style.height = 'auto';
	d.style.position = '';
	/*d.style.display = 'inline';*/
	/*d.style.display = 'inline-block';*/
	d.style.visibility = 'visible';  
  } else {
    if (img) {
	 img.src = 'img/continue_arrow_down.gif';  
    }
	d.style.position = 'absolute';
	/*d.style.display = 'none';*/
	d.style.height = '0px';
	d.style.visibility = 'hidden';  
  }
 }
}

function showFCK(divID,targetTagID) {
 var d = document.getElementById(divID);
 var td = document.getElementById(targetTagID);	
 
 if (d) {
   if (BrowserDetect.browser == 'Opera') {
    d.style.left = (td.left)+'px';
    d.style.top = (td.top)+'px';
   } else {
    d.style.left = (td.offsetLeft+10)+'px';
    d.style.top = (td.offsetTop)+'px';
   }
   if (d.style.visibility == 'hidden') { d.style.visibility = 'visible'; } 
 }
}

function showMediaCenter(divID, edititem) {
	
 var allm = document.getElementById('mediaCenterAll');
 var videom = document.getElementById('mediaCenterVideo');
 var imagem = document.getElementById('mediaCenterImage');
 var mmc = document.getElementById('mediaCenterMP3');
 var ta = document.getElementById('aMediaCenterAll');
 var tv = document.getElementById('aMediaCenterVideo');
 var ti = document.getElementById('aMediaCenterImage');
 var tm = document.getElementById('aMediaCenterMP3');
 
 if (allm && videom && imagem && ta && tv && ti || edititem == true) {
  if (divID != 'mediaCenterAll') {
   allm.style.visibility = 'hidden';
   allm.style.position = 'absolute';
   /*ta.style.border = 'none';
   ta.style.backgroundColor = '#636363';*/
   ta.style.fontWeight = 'normal';
  } else {
   allm.style.visibility = 'visible';
   allm.style.position = 'relative';
  /* ta.style.border = 'solid 1px #FFFFFF';
   ta.style.backgroundColor = '#4F4F4F';*/
   ta.style.fontWeight = 'bold';
  }
  if (divID != 'mediaCenterVideo') {
   videom.style.visibility = 'hidden';
   videom.style.position = 'absolute';
   /*tv.style.border = 'none';
   tv.style.backgroundColor = '#636363';*/
   tv.style.fontWeight = 'normal';
  } else {
   videom.style.visibility = 'visible';
   videom.style.position = 'relative';
   /*tv.style.border = 'solid 1px #FFFFFF';
   tv.style.backgroundColor = '#4F4F4F';*/
   tv.style.fontWeight = 'bold';
  }
  if (divID != 'mediaCenterImage') {
   imagem.style.visibility = 'hidden';
   imagem.style.position = 'absolute';
  /* ti.style.border = 'none';
   ti.style.backgroundColor = '#636363';*/
   ti.style.fontWeight = 'normal';
  } else {
   imagem.style.visibility = 'visible';
   imagem.style.position = 'relative';
   /*ti.style.border = 'solid 1px #FFFFFF';
   ti.style.backgroundColor = '#4F4F4F';*/
   ti.style.fontWeight = 'bold';
  }
  if (divID != 'mediaCenterMP3') {
	mmc.style.visibility = 'hidden';
	mmc.style.position  = 'absolute';
	tm.style.fontWeight = 'normal';
  } else {
	  mmc.style.visibility = 'visible';
	  mmc.style.position = 'relative';
	  tm.style.fontWeight = 'bold';
  }
 }
}

function showHideProductDescription(descriptionDiv) {
  var d = document.getElementById(descriptionDiv);
  if (d) {
   if (d.style.maxHeight != '') d.style.maxHeight = ''; else d.style.maxHeight = '200px';	  
  }
}

function refreshImages()
{
var search="?"+(new Date()).getTime();
for(var i=0;i<document.images.length;document.images[i++].src+=search);
}

var so;

function createPlayer(divID,videoURL, setMP3) {
	var d = document.getElementById(divID);
	if (d) {
	 var pWidth = '' + d.scrollWidth + '';
	
	  if (document.getElementById('tdPreviewMedia')) {
	   pWidth = '490'; 
	  }	else pWidth = '430'; 
	
	} else {
	 var pWidth = '430';	
	}
	so = new SWFObject('script/flash/jw/player.swf','mpl',pWidth,'370','7');
	so.addParam('allowfullscreen','true');
	  if (setMP3 == true)
	  {	  	
	  	so. addParam('flashvars',"file="+videoURL+"&playlist=bottom&repeat=list&plugins=revolt-1&skin=script/flash/jw/skins/magma/magma.swf&backcolor=000000&frontcolor=ffffff&lightcolor=cccccc&autostart=true");
	  	so.addParam("displayheight","100");
	  	so.addParam("wmode","transparent");
	  	so.addVariable("autostart","true");
	  	so.addParam("showicons","true");
	  }
	  else
	  {
		so.addParam('allowfullscreen','true');
		so.addParam("wmode","transparent");
	  	so. addParam('flashvars',"file="+videoURL+"&skin=script/flash/jw/skins/magma/magma.swf&backcolor=ffffff&frontcolor=000000&lightcolor=8E1817&autostart=true");
	  }
	  so.write('flashbanner');
 }

 function createCommonPlayer(divID,width,height,videoURL, setMP3) {
	so = new SWFObject('script/flash/jw/player.swf','mpl',width,height,'7');
	so.addParam('allowfullscreen','true');
	so.addParam('wmode','transparent');
	  if (setMP3 == true)
	  {	  	
	  	so. addParam('flashvars',"file="+videoURL+"&playlist=bottom&repeat=list&backcolor=000000&frontcolor=ffffff&lightcolor=cccccc&autostart=true");
	  	so.addParam("displayheight","100");
	  	so.addVariable("autostart","true");
	  	so.addParam("showicons","true");
	  }
	  else
	  {
		so.addParam('allowfullscreen','true');
		//skin=script/flash/jw/skins/magma/magma.swf&
	  	so. addParam('flashvars',"file="+videoURL+"&backcolor=ffffff&frontcolor=000000&lightcolor=CCCCCC&skin=script/flash/jw/skins/magma/magma.swf&autostart=true");
	  }
	  so.write(divID);
 }
 
function videoShowHide(show, videoURL, divID, setMP3,text)
{
	var d=document.getElementById(divID);
	var divIMG = document.getElementById('flashbanner');
	
	divIMG.innerHTML = '';
	
	if (d) 
	{
		if (show == true)
		{         
			d.style.visibility = 'visible';
			createPlayer(divID,videoURL, setMP3);		
			if (text != null && text != '') divIMG.innerHTML += '<br /><br />'+ text + '<br /><br />';
		}
		else
		{
			so = document.getElementById('mpl');
			so.sendEvent("STOP");
			d.style.visibility='hidden';

		}
	}
}

function videoShowHideInEditItem(show, videoURL, divID, setMP3, text, UrlName, flag_video) {
	var d=document.getElementById(divID);
	var divIMG = document.getElementById('flashbanner');
	var textareaId = document.getElementById('mediaDescriptionId');
	var v = document.getElementById('videoUrlPanelId');
	var inputUrlId = document.getElementById('mediaUrlId');
	var flag = document.getElementById('itemFlagId');
	var media = document.getElementById('mediaTypeId');
	var mn = document.getElementById('chosenMP3Id');
	var fupload = document.getElementById('fileUploadId');
	
	divIMG.innerHTML = '';
	mn.style.visibility = 'hidden';
	
	if (d) 
	{
		if (show == true)
		{         
			d.style.visibility = 'visible';
			d.style.display = 'block';
			d.style.height = 'auto';
			v.style.visibility = 'visible';
			v.style.display = 'block';
			v.style.height = 'auto';
			createPlayer(divID,videoURL, setMP3);	
			textareaId.name = 'productVideoDescription_'+flag_video;
			textareaId.value = text;
			inputUrlId.name = UrlName;
			inputUrlId.value = videoURL;
			flag.value = flag_video;
			media.value='video';
			fupload.name = 'uploadVideos_'+flag_video;
		}
		else
		{
			so = document.getElementById('mpl');
			so.sendEvent("STOP");
			d.style.visibility='hidden';
			d.style.display = 'none';
			d.style.height = '0px';
			v.style.visibility = 'hidden';
			v.style.display = 'none';
			v.style.height = '0px';
		}
	}
}

function showMp3PlayerInEditItem(show, mp3URL, divID, text, mp3Name, flagMp3) {
	var d=document.getElementById(divID);
	var divIMG = document.getElementById('flashbanner');
	var textareaId = document.getElementById('mediaDescriptionId');
	var flag = document.getElementById('itemFlagId');
	var media = document.getElementById('mediaTypeId');
	var mn = document.getElementById('chosenMP3Id');
	var v=document.getElementById('videoUrlPanelId');
	var fupload = document.getElementById('fileUploadId');
	
	mn.innerHTML = '';
	divIMG.innerHTML = '';
	v.style.visibility = 'hidden';
	
	if (d) 
	{
		if (show == true)
		{         
			d.style.visibility = 'visible';
			createPlayer(divID,mp3URL, true);	
			textareaId.name = 'descriptionMP3_'+flagMp3;
			textareaId.value = text;
			flag.value = flagMp3;
			media.value='mp3';
			mn.style.visibility = 'visible';
			mn.innerHTML = mp3Name;
			fupload.name='productMP3Field'+flagMp3;
		}
		else
		{
			so = document.getElementById('mpl');
			so.sendEvent("STOP");
			d.style.visibility='hidden';
			mn.innerHTML = '';
			mn.style.visibility = 'hidden';
		}
	}
}

 function scrollDiv(direction,step,divID, divWrapper)
 {
          /* direction: 0 = left scroll; 1 = right scroll*/
          var md = document.getElementById(divID); 
          var wrapper = document.getElementById(divWrapper);
          var width = parseInt(md.style.width);
          var wrpWidth = parseInt(wrapper.style.width);
          var scrStep = -step;
          var mrg = 0;
             
          mrg = parseInt(md.style.marginLeft); 
        
          if ((Math.abs(mrg) + wrpWidth <= width) || (direction == 1)) {
              if (direction == 0) {
                mrg = mrg + scrStep;
              } else if (mrg < 0) {
                mrg = mrg - scrStep;
              }
         }
         md.style.marginLeft = mrg + 'px';
  }
  function myCheckFunction(objIMG, hiddID)
{
	var hiddenResultOfCurrentCheckbox=document.getElementById(hiddID);
	
	var dot = objIMG.src.lastIndexOf("/");
	var ext = objIMG.src.substring(dot,objIMG.src.length);
	
	if(ext!='/check_on.gif')
	{
		objIMG.src='img/check_on.gif';
		hiddenResultOfCurrentCheckbox.value='tmp_item_unchecked';
		
		addRemoveSelectedItems('on', hiddID);
	}
	else
	{
		objIMG.src='img/check_off.gif';
		hiddenResultOfCurrentCheckbox.value='tmp_item_checked';
		addRemoveSelectedItems('off', hiddID);
	}

}
  
  /*
  Change posiotion of passed element.
  passedPointersID - pointer's ID.
  passedPanelsID - container's ID.
  */
  var pos_LEFT=0;
  var pos_TOP=0;

  function panelPositioner(passedPointersID, passedPanelsID)
  {
  	var intLeftPosition=0;
  	var intTopPosition=0;
  	var currObjPointer=document.getElementById(passedPointersID);
  	var currPanelForPositioning=document.getElementById(passedPanelsID);
  	
  	intTopPosition = currObjPointer.offsetHeight;
  	if(currObjPointer.offsetParent)
  	{
  		intLeftPosition += currObjPointer.offsetLeft;
  		intTopPosition += currObjPointer.offsetTop;
  		
  		var parent = currObjPointer.offsetParent;
  		
  		while(parent)
  		{
  			intLeftPosition += parent.offsetLeft;
  			intTopPosition += parent.offsetTop;
  			parent = parent.offsetParent;
  		}
  		
  		intLeftPosition += document.documentElement.scrollLeft + document.body.scrollLeft;
  		intTopPosition += document.documentElement.scrollTop + document.body.scrollTop;
  		intLeftPosition -= document.documentElement.scrollLeft;
  		intTopPosition -= document.documentElement.scrollTop;
  		
  		
  		if(document.all) 	// IE
{
	if(passedPointersID=='myPointerAdvMenu')
{
	intTopPosition+=pos_TOP;
	intLeftPosition+=pos_LEFT;
}
else if (passedPointersID=='myPointerCatMenu')
	{
		intTopPosition+=pos_TOP;
		intLeftPosition+=pos_LEFT;
	}
	else
	{
		intTopPosition+=pos_TOP;
		intLeftPosition+=pos_LEFT;
	}
}
if(!document.all) 	// !IE
{
	if(passedPointersID=='myPointerAdvMenu')
{
	intTopPosition+=pos_TOP;
	intLeftPosition+=eval(pos_LEFT-1);
}
else if (passedPointersID=='myPointerCatMenu')
	{
		intTopPosition+=pos_TOP;
		intLeftPosition+=eval(pos_LEFT-1);
	}
	else
	{
		intTopPosition+=pos_TOP;
		intLeftPosition+=pos_LEFT;
	}
}
if(window.opera)	//	Opera
{
	if(passedPointersID=='myPointerAdvMenu')
{
	intTopPosition+=pos_TOP;
	intLeftPosition+=eval(pos_LEFT-1);
}
else if (passedPointersID=='myPointerCatMenu')
	{
		intTopPosition+=pos_TOP;
		intLeftPosition+=eval(pos_LEFT-1);
	}
	else
	{
		intTopPosition+=pos_TOP;
		intLeftPosition+=pos_LEFT;
	}
}

currPanelForPositioning.style.left=intLeftPosition+'px';
currPanelForPositioning.style.top=intTopPosition+'px';
currPanelForPositioning.style.visibility='visible';
  		
  	}
  	pos_LEFT=0;
  	pos_TOP=0;

  }

function restorePositioner(passedPanelsID)
{
	var currPanelForPositioning=document.getElementById(passedPanelsID);
	currPanelForPositioning.style.left=0+'px';
	currPanelForPositioning.style.top=0+'px';
	currPanelForPositioning.style.visibility='hidden';
	
}

function addRemoveSelectedItems(onofParam, productID)
{
	var objHiddField=document.getElementById('all_checked_items');
	var tempProductID=productID.split('_');
	
	if(onofParam=='on')
	{
		if(objHiddField.value=='')
		{
			objHiddField.value=tempProductID[1];
		}
		else
		{
			objHiddField.value=(objHiddField.value+','+tempProductID[1]);
		}
	}
	else if(onofParam=='off')
	{
		var arrAllTempIDs=objHiddField.value.split(',');
		var intArrAllTempIDs=arrAllTempIDs.length;
		var strTempRemainIDs='';
		
		for(i=0; i<intArrAllTempIDs; i++)
		{
			if(arrAllTempIDs[i]!=tempProductID[1])
			{
				if(strTempRemainIDs!='')
				{
					strTempRemainIDs+=(','+arrAllTempIDs[i]);
				}
				else
				{
					strTempRemainIDs=arrAllTempIDs[i];
				}
			}
		}
		
		objHiddField.value=strTempRemainIDs;
	}
}

function imgZoomingEffect(tmpSRC)
{
	var position_=eval(tmpSRC.lastIndexOf('/')+1);
	var thumbnailIMGName=tmpSRC.substr(position_);
	var bigIMGName=splitIMGName(thumbnailIMGName);
	var imgPath=tmpSRC.substr(0, eval(tmpSRC.lastIndexOf('/')+1));
	
	var objIMG=document.getElementById('thumbnailZoomID');		//Izobrajenieto koeto se qwqwa thumbnail.
	objIMG.attributes['class'].nodeValue='thumbnailZoomVSB';	//Setva se class-a na izobrajenieto.
	objIMG.attributes['src'].nodeValue=imgPath+bigIMGName;
	
	//alert(eval(objIMG.height));
	pos_LEFT=140;
	pos_TOP=-eval(objIMG.height+12);
	panelPositioner(('item_'+bigIMGName.split('_')[1]), 'thumbnailZoomID');
}
function imgHiddZoomingEffect()
{
	var objIMG=document.getElementById('thumbnailZoomID');
	objIMG.attributes['class'].nodeValue='thumbnailZoomHID';
	restorePositioner('thumbnailZoomID');
}
function loadOriginalImage(objSelectedIMG) {
 var strIMGName = document.getElementById(objSelectedIMG).attributes['src'].nodeValue;
 strIMGName = strIMGName.replace(/Big/,"Original");
 imgWin = window.open(strIMGName,'vrPIC','toolbar=no,location=no,resizable=yes');
 /*imgWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><img src="'+strIMGName+'" onerror="window.close();" /></body></html>');
 imgWin.document.close();
*/// alert(strIMGName+" win:"+imgWin.document.all);
}

var originalWidth = 0;
var originalHeight = 0;

function setBigThumbSize(oW,oH) {
 document.getElementById('BASEIMG').width = "0";
 document.getElementById('BASEIMG').height = "0";
 document.getElementById('BASEIMG').attributes['src'].nodeValue = "";
 originalWidth = oW;
 originalHeight = oH;
}

function selectBigItemPicture(imgSRC,text)
{
	var divID = document.getElementById('flashbanner');
	divID.innerHTML = "<a onclick=\'bigImage();\' style=\'cursor:pointer;\' ><img id=\'BASEIMG\' src=\'"+imgSRC+"\' border=\'0\' style=\'cursor: url(img/cursors/magnifier.cur), pointer;#cursor: url(img/cursors/magnifier.cur); margin-top: 10px; margin-bottom: 10px;\' alt=\'Click to see bigger picture\' title=\'Click to see bigger picture\' /></a><br /><br />"+text;
}

function selectBigEditItemPicture(imgSRC, value, flagImg) {
	var divID = document.getElementById('flashbanner');
	var vp = document.getElementById('video_preview');
	var textareaId = document.getElementById('mediaDescriptionId');
	var file = document.getElementById('fileUploadId');
	var flag = document.getElementById('itemFlagId');
	var media = document.getElementById('mediaTypeId');
	var v = document.getElementById('videoUrlPanelId');
	var mn = document.getElementById('chosenMP3Id');
	
	refreshImages();
	
	if (v) {
 	v.style.visibility = 'hidden';
	v.style.display = 'none';
	v.style.height = '0px';
	}
	
	if (vp) {
	 vp.style.visibility = 'hidden';
	 vp.style.display = 'none';
	 vp.style.height = '0px';	
	}

	if (mn) mn.style.visibility = 'hidden';
	
	divID.innerHTML = "<a onclick=\'bigImage();\' style=\'cursor:pointer;\' ><img id=\'BASEIMG\' src=\'"+imgSRC+"\' border=\'0\' style=\'cursor: url(img/cursors/magnifier.cur), pointer;#cursor: url(img/cursors/magnifier.cur); margin-top: 10px; margin-bottom: 10px;\' alt=\'Click to see bigger picture\' title=\'Click to see bigger picture\' /></a><br /><br />";
	if (textareaId) {
	 textareaId.name='productImageDescription_'+flagImg;
	 textareaId.value=value;
	}
	if (file) file.name='uploadPictures_'+flagImg;
	if (flag) flag.value=flagImg;
	if (media) media.value='picture';
}

function selectBigOfferPicture(imgSRC, offer_id) {
	var divID = document.getElementById('flashbanner');
	divID.innerHTML = "<a onclick=\'bigOfferImage("+offer_id+");\' style=\'cursor:pointer;\' ><img id=\'BASEIMG\' src=\'"+imgSRC+"\' border=\'0\' style=\'cursor: url(img/cursors/magnifier.cur), pointer;#cursor: url(img/cursors/magnifier.cur); margin-top: 10px; margin-bottom: 10px;\' alt=\'Click to see bigger picture\' title=\'Click to see bigger picture\' /></a>";
}

function loadThisImg(objSelectedIMG)
{
	var containerTABLE=objSelectedIMG.parentNode.parentNode.parentNode;
	var containersTD=containerTABLE.rows[0].cells;
	var intIndex=objSelectedIMG.parentNode.cellIndex;
	var strIMGName=objSelectedIMG.attributes['src'].nodeValue;
	var strIMGPath=strIMGName.substr(0, eval(strIMGName.lastIndexOf('/')+1));
	
	for(i=0; i<containersTD.length; i++)
	{
		containersTD[i].attributes['class'].nodeValue='pdoduct_under_img_eff';
	}

	containersTD[intIndex].attributes['class'].nodeValue='pdoduct_under_img_eff_S';
	
	splitIMGName(strIMGName.substr(eval(strIMGName.lastIndexOf('/')+1)));
	
	orginal_name = strIMGPath+splitIMGorginal(strIMGName.substr(eval(strIMGName.lastIndexOf('/')+1)));
	/*document.getElementById('BASEIMG').parentNode.href = orginal_name;*/
	
      document.getElementById('BASEIMG').attributes['src'].nodeValue = strIMGPath+splitIMGName(strIMGName.substr(eval(strIMGName.lastIndexOf('/')+1)));
      document.getElementById('BASEIMG').width = originalWidth.toString();
      document.getElementById('BASEIMG').height = originalHeight.toString();

	/*
	img_fake_obj = document.getElementById('fake_img');
	small_src = new Array();
	for(i in document.getElementById('smal_img').childNodes[0].childNodes[1].childNodes){
		if(i.length <= 2){
			tml_src = document.getElementById('smal_img').childNodes[0].childNodes[1].childNodes[i].firstChild.src;
			small_src[i] = splitIMGorginal(tml_src.substr(eval(tml_src.lastIndexOf('/')+1)));
		
		}
	}
	
	
	i = 0;
	for(i in small_src){
		if(i.length <= 2){
			temp_str = img_fake_obj.childNodes[i].href;
			if(temp_str.substr(eval(temp_str.lastIndexOf('/')+1)) == orginal_name.substr(eval(orginal_name.lastIndexOf('/')+1))){
				childObj = img_fake_obj.childNodes[i];
				img_fake_obj.removeChild(childObj);
			} 
		
			if(temp_str.substr(eval(temp_str.lastIndexOf('/')+1)) != orginal_name.substr(eval(orginal_name.lastIndexOf('/')+1))
				&& temp_str.substr(eval(temp_str.lastIndexOf('/')+1)) != small_src[i]){
				a = document.createElement('a');
				a.setAttribute('href', strIMGPath+small_src[i]);
				a.setAttribute('class', 'nyroModal');
				a.setAttribute('rel', 'gal');
				document.getElementById('fake_img').appendChild(a);
			}
			
			
			
		}
	} */

}

function splitIMGName(strIMGName)
{
	var strTempAttributes=strIMGName.substr(7);
	var strNewStringForReturn='productBig'+strTempAttributes;
	
	return strNewStringForReturn;
}

function splitIMGorginal(strIMGName)
{
	var strTempAttributes=strIMGName.substr(7);
	var strNewStringForReturn='productOriginal'+strTempAttributes;
	
	return strNewStringForReturn;
}

function loadThisUserOfferImg(objSelectedIMG)
{
	var containerTABLE=objSelectedIMG.parentNode.parentNode.parentNode;
	var containersTD=containerTABLE.rows[0].cells;
	var intIndex=objSelectedIMG.parentNode.cellIndex;
	var strIMGName=objSelectedIMG.attributes['src'].nodeValue;
	var strIMGPath=strIMGName.substr(0, eval(strIMGName.lastIndexOf('/')+1));
	var strBigIMGName=document.getElementById('bigImageLoader').value;
	
	for(i=0; i<containersTD.length; i++)
	{
		containersTD[i].attributes['class'].nodeValue='pdoduct_under_img_eff';
	}

	containersTD[intIndex].attributes['class'].nodeValue='pdoduct_under_img_eff_S';
	
      document.getElementById('BASEIMG').attributes['src'].nodeValue = strIMGPath+strBigIMGName;
      document.getElementById('BASEIMG').width = originalWidth.toString();
      document.getElementById('BASEIMG').height = originalHeight.toString();
}

function showChangePassword(divID)
{
	var button = document.getElementById('changePassButtonId');
	var url = 'ajax/generateChangePassword.php';
	
	fillup(url,divID,'ajaxLoader',false);
	button.style.visibility = 'hidden';
}

function visualLoginErrors(errors)
{
	var divId = document.getElementById('loginFormErrId');
	divId.style.visibility='visible';
	divId.innerHTML = errors;
}

function showCategoriesDropDowns(categoryID, productID, divID) {
	var url = 'ajax/generateCategoriesDropDowns.php?cat='+categoryID+'&prod='+productID;
	fillup(url,divID,'ajaxLoader',false);
}

function checkAllMail()
{
	var objTblContainer=document.getElementById('mailListForm___');
	var pole=objTblContainer.getElementsByTagName('input');	// Instance of requisites ...
	
	for(i=0; i<pole.length; i++)
	{
		if(pole[i].type=='checkbox')					// Crawl the CHECKBOX ...
		{
			pole[i].checked=true;
		}
	}
}

function uncheckAllMail()
{
	var objTblContainer=document.getElementById('mailListForm___');
	var pole=objTblContainer.getElementsByTagName('input');	// Instance of requisites ...
	
	for(i=0; i<pole.length; i++)
	{
		if(pole[i].type=='checkbox')					// Crawl the CHECKBOX ...
		{
			pole[i].checked=false;
		}
	}
}

function disableYearInput() {
	var newYear = document.getElementById('newYearId');
	var formName = document.getElementById('editProduct');
	
	if (newYear.checked == true) formName.productYear.disabled=true;
	if (newYear.checked == false) formName.productYear.disabled=false;
}