//jb 21.06.06
function showImgPNG(imgID,backImgURL)
{
	var img = document.getElementById(imgID);
	
	var isIE = navigator.userAgent.indexOf('MSIE');
	
	if(isIE < 0) {
		img.style.backgroundImage = "url('" + backImgURL + "')";
	} else {
		//
	  }
	  
	img.style.backgroundRepeat = 'no-repeat';
	img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + backImgURL + '", sizingMethod="crop")';
}

//jb 31.05.06
function manageUserAddress(formID, userAddressID, actionMode, onEvent)
{
	var form = document.getElementById(formID);
	
	if(userAddressID) {
		form['UserAddressID'].value = userAddressID;
		if(onEvent=='submit') {
			if(actionMode) {
				form['actionMode'].value = actionMode;
			}
			
			form.submit();
		}
		if(onEvent=='confirm') {
			var confirmRS = confirm('Delete this address?');
			if(confirmRS) {
				if(actionMode) {
					form['actionMode'].value = actionMode;
				}
				
				form.submit();
			}
		}
		
	}
	
	return false;
}
//jb 31.05.06

//jb 2.04.06 
//equalize products columns in one lines heights
function equalizeProductColumns(productsPerLine)
{
	var productList = document.getElementById('product_list');
	var productListChildsCount = productList.childNodes.length;
	var iProduct = 0; var curProduct = ''; var prevProduct = '';
	for(var i=1;i<=productListChildsCount;i++) {
		child = productList.childNodes[i];
		if(child.className=='product_box') {
			iProduct++;
			mod2 = Math.floor(iProduct/2);
			if(mod2*2==iProduct) { //if is 2-x number
				thisProductHeight = child.offsetHeight;
				prevProductHeight = productList.childNodes[curProduct].offsetHeight;
				if(thisProductHeight<prevProductHeight) {
					child.style.height = prevProductHeight+'px';
				}
				//alert(productList.childNodes[curProduct].offsetHeight);
			} else {
				mod3 = Math.floor(iProduct/3);
				if(productsPerLine==3 && mod3*3==iProduct) { //if is 3-x number
					thisProductHeight = child.offsetHeight;
					secondProductHeight = productList.childNodes[curProduct].offsetHeight;
					firstProductHeight = productList.childNodes[prevProduct].offsetHeight;
					prevProductHeight = Math.max(secondProductHeight,firstProductHeight);
					if(thisProductHeight<prevProductHeight) {
						child.style.height = prevProductHeight+'px';
					}
					//alert(productList.childNodes[curProduct].offsetHeight);
				}
			  }
			if(curProduct!='') {
				prevProduct = curProduct;
			}
			curProduct = i;
		}
	}
}
//jb 2.04.06

function submitonce(theform){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById)
	{
		//screen thru every element in the form, and hunt down "submit" and "reset"
		for (i=0;i<theform.length;i++)
		{
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
			//disable em
			tempobj.disabled=true
		}
	}
}

function popup(url,w,h,sb)
{
	atr = '';
	atr = atr + 'toolbar=no,';
	if (sb)
	{
		atr = atr + 'scrollbars=yes,';
	}
	else
	{
		atr = atr + 'scrollbars=no,';
	}
	atr = atr + 'location=no,';
	atr = atr + 'statusbar=no,';
	atr = atr + 'menubar=no,';
	atr = atr + 'resizable=yes,';
	if (w) {
	atr = atr + 'width='+w+',';
	atr = atr + 'height='+h;
	}
	else{
	atr = atr + 'width=770,';
	atr = atr + 'height=560';
	}
	new_window=window.open(url,'_blank',atr);
	new_window.focus();
}

function popupimg (url)
{
	popup(url,1,1);
}

function goopener (url)
{
window.opener.focus();
window.opener.location=url;
window.close();
}
function closepopup ()
{
window.opener.focus();
window.close();
}
function goback (url) {
window.location=url;
}

function gosearch (module,url)
{
	if (document.searchform.searchword.value)
		{
			if (module == 'article')
			{
				window.location=url+'&filtr='+document.searchform.searchword.value;
			}
		}
}


function SetFocus() {
  if (document.forms.length > 0) {
    var field = document.forms[0];
    for (i=0; i<field.length; i++) {
      if ( (field.elements[i].type != "image") && 
           (field.elements[i].type != "hidden") && 
           (field.elements[i].type != "reset") && 
           (field.elements[i].type != "submit") ) {

        document.forms[0].elements[i].focus();

        if ( (field.elements[i].type == "text") || 
             (field.elements[i].type == "password") )
          document.forms[0].elements[i].select();
        
        break;
      }
    }
  }
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// end images rollover efects functions

/**
 * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
 * This function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the sql query to submit
 onclick="return confirmlink(this, 'DROP TABLE `tslc_oeuvre`')
 *
 * @return  boolean  whether to run the query or not
 */

function confirmlink(theLink, theSqlQuery)
{
    // Confirmation is not required in the configuration file
alert ('test');
    var is_confirmed = confirm(theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function

function selectLink(formName, formField, confirmText, positions){
//Redirect browser to the link in the VALUE of the formFiled of the formName

//positions - comma separated option ids, like: 2,3,5, which will be confirmed
//in case if you have more options to delete...
	var val = document.forms[formName].elements[formField].value;
	var del = document.forms[formName].elements[formField].selectedIndex;
	
	var optionsToConfirm = positions.split(",");
	var conf=0;
	
	for(i=0; i<optionsToConfirm.length; i++)
	{
		if(del == parseInt(optionsToConfirm[i])) { conf=1; }
	}

	if(confirmText && conf )
	{
		if(confirm(confirmText)) {location.replace(val);} else { return false; }
	}
	else
	{
		location.replace(val);
	}
}

//jb 10.04.06
function deleteItem(form, text, itemID)
{
	
	var is_confirmed = confirm(text);
	if (form.name!='')
	{
    if (is_confirmed) {
		document.forms[form].actionMode.value = 'delete';
		document.forms[form].deletedCartItemID.value = itemID;
        document.forms[form].submit();
      }
	}
	else
	{
		id_form=document.getElementById(form);
		if (is_confirmed) {
		id_form.actionMode.value = 'delete';
		id_form.deletedCartItemID.value = itemID;
        id_form.submit();
      }
	}
	
}

function confirmDelete(form, text)
{
    var is_confirmed = confirm(text);
	
	var formName=form;
	
    if (is_confirmed) {
        document.forms[formName].submit();
    }
} 


function convertToAlias(fieldInput,fieldResult){
	fieldInputObj = document.getElementById(fieldInput);
	fieldResultObj = document.getElementById(fieldResult);
	if(fieldResultObj.value==""){
		var ref=fieldInputObj.value;
		var i=0;
		while(ref.length > i){
			ref=ref.replace(' ','-');
			ref=ref.replace('&','-');
			i=i+1;
		}
		ref=ref.substring(0,50);
		//fieldResultObj.value=ref.toUpperCase();
		fieldResultObj.value = ref;
	}
}

function changeTarget(){
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i < anchors.length; i++) { 
 var anchor = anchors[i];
 if (anchor.getAttribute("href") && 
     anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
     }

}
