//alert('Functions attached!');
/*function selectedText(textName) {
	alert(textName);
}*/

// Initial variables
var lastDisp = "selectText";
var lastTd = "";
var selected_Pictogramms = new Array();

// A getcontentData.php tölti fel ezt az aktuális kép adatokkal
var sizes = new Array();
/*sizes[0] = "0dik element";
sizes[1] = "1dik element";*/




function toggle(id) {
	//alert(id)
	if (document.getElementById(id).style.display == "none")  {
		document.getElementById(id).style.display = "";
		if (lastDisp != "") document.getElementById(lastDisp).style.display = "none";
		lastDisp = id;}
		
		else {
		document.getElementById(id).style.display = "none";
		lastDisp = "";
		}
}
function check(aForm) {
	alert(aForm.addgroup.value)
	/**/
}

function toggleLayer( id ) {
    var elem, vis;

    if( document.getElementById ) // this is the way the standards work
        elem = document.getElementById( id );
    else if( document.all ) // this is the way old msie versions work
        elem = document.all[id];
    else if( document.layers ) // this is the way nn4 works
        elem = document.layers[id];

    vis = elem.style;
    
    // if the style.display value is blank we try to figure it out here
    if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
        vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';

    vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function selectPictogramm(getId,formName) {
	var tdId = 'pictogramm'+getId;
	var pictelem, pictvis;
	
	//alert(formName+' select pictogramm'+getId);
	 /* if( document.getElementById ) // this is the way the standards work
		pictelem = document.getElementById( getId );
	  else if( document.all ) // this is the way old msie versions work
		  pictelem = document.all[getId];
	  else if( document.layers ) // this is the way nn4 works
		pictelem = document.layers[getId];
	  pictvis = pictelem.style;
	  // if the style.display value is blank we try to figure it out here
	  if(pictvis.display==''&& pictelem.offsetWidth!=undefined && pictelem.offsetHeight!=undefined)
		pictvis.display = (pictelem.offsetWidth != 0 && pictelem.offsetHeight!=0)?'block':'none';
	  pictvis.display = (pictvis.display==''||pictvis.display=='block')?'none':'block';*/

	if (document.getElementById(tdId).style.backgroundColor != 'lightgreen') {
		document.getElementById(tdId).style.backgroundColor = 'lightgreen';
		selected_Pictogramms[getId] = true;
	} else {
		document.getElementById(tdId).style.backgroundColor = '#dddddd';
		selected_Pictogramms[getId] = false;
	}
	document.getElementById('elementVariations').value = selected_Pictogramms.join("|");
	//document.imageupload.elemVariationId.value=getId;
}
	
function validate(this_form) { 
        //alert('begin validate...');
	//alert ('Validation of '+this_form.name);
		if (this_form.imagefile.value==null || this_form.imagefile.value=="") {
			alert('Nem választottál képet!'); return false;
		}
		else if (this_form.cim.value==null || this_form.cim.value=="") {
			alert('Nem adtál a képnek címet!'); return false;
		}
		else if (this_form.masterFurnitureId.value==null || this_form.masterFurnitureId.value=="") {
			alert('Nem választottál termék azonosítót!'); return false;
		}
	//alert('begin toggle...');
	toggleLayer('progress');
	return true;
}
	
function validateContent(myForm) {
	valid = true;
	//alert ('Validation');
		if (myForm.item_name.value==null || myForm.item_name.value=="") {
			alert('Nem adtál meg tétel azonosítónevet!'); valid = false;
		}
		else if (myForm.nameStr.value==null || myForm.nameStr.value=="") {
			alert('Nem adtad meg a termék nevét!'); valid = false;
		}
	
	//alert(valid);
	return valid;
}



/* change opacity */
function lightup(imageobject, opacity){
    if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
    imageobject.style.MozOpacity=opacity/100
    else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4)
    imageobject.filters.alpha.opacity=opacity
}


/*function sizeTo(layerName, img, iHeight, iWidth, animate) {
//http://www.siteexperts.com/tips/elements/ts21/page1.asp
	alert(layerName);
   var ie4 = (document.all)
   if (ie4) {
     var targetLayer = document.all[layerName]
     // Locate the image to resize
     var el = targetLayer.children.tags("IMG")[0]
     // Add a clip sub-object. This is used to hide browser differences.
     el.clip = new Object      
   }
   else {
     // You can't just resize the image. In Netscape we manipulate
     // the positioned DIV the image is displayed within.
     var el = document.layers[layerName]
     // Add a style object. This is used to hide browser differences
     el.style = new Object
     // Store current height and width in IE compatible properties
     el.style.pixelHeight = el.offsetHeight = el.clip.height 
     el.style.pixelWidth = el.offsetWidth = el.clip.width
   }
   if (!animate) { // No animation, just change image size
      if (ie4) { 
        // Change image size directly in IE
        el.style.pixelWidth = iWidth; el.style.pixelHeight = iHeight
      }
      else {
        // Create new image with new size in Netscape
        el.document.write("<img src='" + img + "' width="+iWidth+" height="+iHeight+">");
        el.document.close();   
      }
   }
   else
   if ((el.offsetHeight != iHeight) || (el.offsetWidth != iWidth)) {
      // Notice we set both the style and clip sub-objects. The clip
      // object is used in Netscape, the style object is used in IE.
      // By setting both directly we do not need to distinguish between
      // browsers.
      if (el.offsetHeight < iHeight) 
        el.style.pixelHeight = el.clip.height = el.offsetHeight + 1;
      if (el.offsetWidth < iWidth) 
        el.style.pixelWidth = el.clip.width = el.offsetWidth + 1;
      if (el.offsetHeight > iHeight) 
        el.style.pixelHeight = el.clip.height = el.offsetHeight - 1;
      if (el.offsetWidth > iWidth) 
        el.style.pixelWidth = el.clip.width = el.offsetWidth  - 1;
      // IE already resized the image when we set the style properties
      // In Netscape we need to write out a new image with the new size
      if (!ie4) {
        el.document.write("<img src='" + img + "' width="+el.style.pixelWidth+" height="+el.style.pixelHeight+">");
        el.document.close();
      }
      // Continue animation
      setTimeout('sizeTo("' + layerName + '","'+img+'",'+iHeight+','+iWidth+','+animate+')',10);
  } 
}*/

function changeImage(path,boxw,boxh,imgw,imgh,imgid) {
	//alert(path+", "+boxw+", "+boxh+", "+imgw+", "+imgh+", "+imgid)
	
	//First, change the pic
	document.getElementById(imgid).src=path;
	
	// Change its sizes according to the image box ratio
	// This script just scale down!
	ratio = imgh / imgw
	//alert(imgw+" x "+imgh)
	
	if (imgh > boxh) {
		imgh = boxh
		imgw = Math.round(imgh / ratio)
	} 

	else {
		if (imgw > boxw) {
			imgw = boxw
			imgh = Math.round(imgw * ratio)
		}
	}
	
	document.getElementById(imgid).width=imgw
	document.getElementById(imgid).height=imgh
	//alert(ratio)
	//alert("-> "+document.getElementById(imgid).width+" x "+document.getElementById(imgid).height)

}

/*function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
		if (field == field.form.elements[i])
		break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else return true;
} */

/*function validate(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which;
  key = String.fromCharCode( key );
  var regex = /[0-9]|\./;
  if( !regex.test(key) ) {
    theEvent.returnValue = false;
    theEvent.preventDefault();
  }
}*/


function handleEnter (field, evt) {
	//alert(field.name);
	var keyCode = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
	
	var theEvent = evt || window.evt;
	var key = theEvent.keyCode || theEvent.which;
	key = String.fromCharCode( key );
	var regex = /[0-9]|\./;
	//alert(keyCode);
  
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
		if (field == field.form.elements[i])
		break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else if( !regex.test(key) && field.name=='price' && keyCode != 8 && keyCode != 37 && keyCode != 39 && keyCode != 46) {
    theEvent.returnValue = false;
    theEvent.preventDefault();
  }

	else return true;
} 


