
// =====================================       colection version 1.0

//return: object of given id
function zm_findObjById(strID) {
	if (is.dom && document.getElementById(strID))
		return document.getElementById(strID)
	if (is.ie4 && document.all(strID))
		return document.all(strID)
	return false
}


//============================================    
//==================			Macromedia
//============================================

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

// =============================================
// =============================================

//action -> laisvas parametru skaicius, trecias ir toliau param. yra elementu ID stringai, keiciamos jų savybių reikšmės
//prop:		element property, pvz.: "style.display"
//value:		value of that property, pvz.: "none"
//father:	free number of parameters: strings, elements ID
function PropChangeArgs(prop,value) {
	var obj
	var args = PropChangeArgs.arguments
	
	for (var i=2; i<args.length; i++) 
	{
		if (!zm_findObjById(args[i])) continue
		if (is.dom)
			eval("document.getElementById(\'" + args[i] + "\')." + prop + "=\'" + value + "\'")
		if (is.ie4)
			eval("document.all(\'" + args[i] + "\')." + prop + "=\'" + value + "\'")
	}
}


//action -> set all element's in array property to value
//prop:		element property, pvz.: "style.display"
//value:	value of that property, pvz.: "none"
//idsArray:	array of elements ID strings
function PropChangeArray(prop,value,idsArray) {
	for (var i=0; i<idsArray.length; i++) {
		if (!zm_findObjById(idsArray[i])) continue
		eval("zm_findObjById(idsArray[i])." + prop + "='" + value + "'")
	}
}

// ===================================================
// ===================================================

//return			<-		elementu masyva
function creat_elements_colection(tag,id_subst) {
	//var qa_mark = 'item'
	var elems_array = new Array()
	all_tags = document.getElementsByTagName(tag)
	
	for (var i=0; i < all_tags.length; i++) {
		if (all_tags[i].id.indexOf(id_subst) != -1) {
			alert(all_tags[i].id)
			elems_array[elems_array.length] = all_tags[i]
		}
	}
}

//==================================================================
//==============================================			CSS
//==================================================================


//action -> laisvas parametru skaicius, elementu ID stringai, keiciamos ju style.display reiksmes
//	pvz.:		obj_prop_switch('className','aaa','style1','style1')
function obj_prop_switch(prop,obj_str,v1,v2) {
	var obj
	if (!zm_findObjById(obj_str)) {
		alert('puslapyje nėra  -  ' + obj_str)
		return
	}
	else obj = zm_findObjById(obj_str)
	eval('var obj_prop = obj.' + prop)
	var new_value = obj_prop == v1 ? v2 : v1
	eval('obj.' + prop + '= new_value')
}


//keičia objektų class'ę
//obj - nuoroda į objektą, arba this arba objekto ID (ne tekstas, t. y. ne kabutėse)
//classas - stringas, claso pavadinimas
function KeistiClass(strID,classas) {
	var obj = zm_findObjById(strID)
	obj.className = classas;
}


//prop: string, CSS property Display value, that will be set
//free number of parameters: string, elements id
function CSSdisplaySet(prop) {
	var obj;
	var args = CSSdisplaySet.arguments
	for (var i=1; i<args.length; i++) {
		obj = zm_findObjById(args[i])
		if (obj) obj.style.display = prop
	}
}


//arrayForHide: Array, those elements are strings, containers id's, which will be hidden
//strID: element id, that will be display
//nera tikrinama ar antrojo parametro ID yra pirmojo parametro masyve, apskritai turetu taip buti
function ElemsDisplaySwitch(arrayForHide,strID) {
	for (var i=0; i<arrayForHide.length; i++) 
		CSSdisplaySet("none",arrayForHide[i])
	CSSdisplaySet("",strID)
}


//action -> laisvas parametru skaicius, elementu ID stringai, keiciamos ju style.display reiksmes
function style_display_switch() {
	var obj, args = style_display_switch.arguments
	for (var i=0; i<args.length; i++) {
		if (!zm_findObjById(args[i])) {
			alert('puslapyje nėra  -  ' + args[i])
			continue
		}
		else obj = zm_findObjById(args[i])
		obj.style.display = obj.style.display == 'none' ? 'block' : 'none'
	}
}




