var ignore = true;
var magnetoReset = false;
var buttonsReset = false;
var T_COLUMN = 'Sloupec';
var T_ADDCOLUMN = 'Přidat sloupec';
var T_RMCOLUMN = 'Odebrat sloupec';
var T_ADDSHELF = 'Přidat polici';
var T_RMSHELF = 'Odebrat polici';
var magnetoIgnore = true;

function zoom_in(){
	var id = document.getElementById('shelf_id');
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';

	var postvars = 'action=zoom_in&shelf_id=' + id.value;

	buttonsReset = true;
	magnetoReset = true;
	
	if (!send_xmlhttprequest(zoom_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function zoom_out(){
	var id = document.getElementById('shelf_id');
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';

	var postvars = 'action=zoom_out&shelf_id=' + id.value;
	
	buttonsReset = true;
	magnetoReset = true;

	if (!send_xmlhttprequest(zoom_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function zoom_service(xmlhttp) {
	var imageobj = document.getElementById('shelf_image');
	
	if (xmlhttp.readyState == 4) {	
        imageobj.src = document.getElementById('original_img').value + '&' + (new Date()).getTime();
        
        if (buttonsReset) {
			setDndButtons(false);
			buttonsReset = false;
		}	
		
		if (magnetoReset && magneto != null && !magnetoIgnore) {		
			magneto.reset();
			setDndFields();
			magnetoReset = false;
		}
	}
}

function set_name(){
	var bf = document.getElementById('real_name');
	var nw = document.getElementById('false_name');	
	
	nw.value = bf.value;
}

function add_multibox_adv(id_multibox, x, y) {
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';

	var postvars = 'action=add_multibox&multibox=' + id_multibox;
	
	postvars = postvars + '&box[]=' + x + '_' + y;
	
	magnetoReset = true;
	
    if (!send_xmlhttprequest(add_multibox_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function add_multibox(id_multibox){
	var id = document.getElementById('shelf_id');
	var imgsrc, imgtarget;	

	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';

	var postvars = 'action=add_multibox&multibox=' + id_multibox;
	var multibox = document.forms['multibox'].elements['multibox[]'];		
		
	for(var i = 0; i < multibox.length; i++){
		if (multibox[i].checked){
			multibox[i].checked = false;

			document.getElementById('rm_multibox_' + multibox[i].value).setAttribute('class', 'minus cursor');
			imgtarget = document.getElementById('multibox_img_' + multibox[i].value);
			imgsrc = document.getElementById('add_multibox_img_' + id_multibox);
			imgtarget.src = imgsrc.src;

			postvars = postvars + '&box[]=' + multibox[i].value;
		}
	}	
	
	if (!send_xmlhttprequest(add_multibox_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function remove_selected_multibox(){
	var id = document.getElementById('shelf_id');
	var imgsrc, imgtarget;	

	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';

	var postvars = 'action=remove_more_multibox';
	var multibox = document.forms['multibox'].elements['multibox[]'];
    
    imgsrc = document.getElementById('multibox_none');
	
	for(var i = 0; i < multibox.length; i++){
		if (multibox[i].checked){
			multibox[i].checked = false;

			document.getElementById('rm_multibox_' + multibox[i].value).setAttribute('class', 'minusoff cursor');
			imgtarget = document.getElementById('multibox_img_' + multibox[i].value);
			imgtarget.src = imgsrc.src;

			postvars = postvars + '&box[]=' + multibox[i].value;
		}
	}
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function select_multibox(low, high, type){
	var multibox = document.forms['multibox'].elements['multibox[]'];
	
	for(var i = low; i <= high; i++)
		multibox[i].checked = type;
}

function add_multibox_service(xmlhttp) {
	var imageobj = document.getElementById('shelf_image');
	var top, tmp;
	var imgsrc, imgtarget;
	
	if (xmlhttp.readyState == 4) {
		//alert(xmlhttp.responseText);
	
		if (xmlhttp.responseXML != null)
			obj = xmlhttp.responseXML.getElementsByTagName('position');
			if (obj != null && obj.length > 0) {
				top = xmlhttp.responseXML.getElementsByTagName('position').length;
				
				if (top > 0)
					alert(document.getElementById('add_warning').value);
				
				for (i = 0; i < top; i++){
					tmp = xmlhttp.responseXML.getElementsByTagName('position')[i].firstChild.data;
					//document.getElementById('rm_multibox_' + tmp).setAttribute('class', 'minusoff cursor');
					//imgtarget = document.getElementById('multibox_img_' + tmp);
					//imgsrc = document.getElementById('multibox_failed');
					//imgtarget.src = imgsrc.src;
				}
			}
			
			obj = xmlhttp.responseXML.getElementsByTagName('multibox_store');
			if (obj != null && obj.length > 0) {
				for (j = 0; j < obj.length; j++) {
						nodes = obj[j].childNodes;

						for (i = 0; i < nodes.length; i++){
							if (nodes[i].nodeName == 'multibox_index')
								index = nodes[i].firstChild.data;
								
							if (nodes[i].nodeName == 'multibox_value' && nodes[i].firstChild != null)
								document.getElementById('multibox_store_' + index).innerHTML = nodes[i].firstChild.data;
						}
				}
			}
			
			obj = xmlhttp.responseXML.getElementsByTagName('price');
			if (obj != null && obj.length > 0)
				document.getElementById('_total_price').innerHTML = '<strong>' + obj[0].firstChild.data + '</strong>';
				
			obj = xmlhttp.responseXML.getElementsByTagName('credit');
			if (obj != null && obj.length > 0)
				document.getElementById('_credit').innerHTML = '<strong>' + obj[0].firstChild.data + '</strong>';				
				
			obj = xmlhttp.responseXML.getElementsByTagName('discount');
			if (obj != null && obj.length > 0)
				document.getElementById('_discount_price').innerHTML = '<strong>' + obj[0].firstChild.data + '</strong>';
				
			obj = xmlhttp.responseXML.getElementsByTagName('addPrice');
			if (obj != null && obj.length > 0)
				document.getElementById('_add_total_price').innerHTML = '<strong>' + obj[0].firstChild.data + '</strong>';
				
			obj = xmlhttp.responseXML.getElementsByTagName('store');
			
			if (document.getElementById('store_state') != null) {
				if (obj != null && obj.length > 0)
					document.getElementById('store_state').innerHTML = document.getElementById('store_' + obj[0].firstChild.data).value;

				obj = xmlhttp.responseXML.getElementsByTagName('casing');
				if (obj != null && obj.length > 0)
					if (obj[0].firstChild.data == 'true')
						document.getElementById('store_state').innerHTML = document.getElementById('store_state').innerHTML + ' ' + document.getElementById('casing_presence').value;
			}
		
		imageobj.src = document.getElementById('original_img').value + '&' + (new Date()).getTime();
		
		if (magnetoReset && magneto != null && !magnetoIgnore) {		
			magneto.reset();
			setDndFields();
			magnetoReset = false;
		}
	}	
}

function rm_multibox_adv(id_multibox){
	var id = document.getElementById('shelf_id');

	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=rm_multibox&multibox=' + id_multibox;
	
	magnetoReset = true;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function rm_multibox(id_multibox){
	var id = document.getElementById('shelf_id');
	var imgsrc, imgtarget;

	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=rm_multibox&multibox=' + id_multibox;
	
	document.getElementById('rm_multibox_' + id_multibox).setAttribute('class', 'minusoff cursor');
	
	imgtarget = document.getElementById('multibox_img_' + id_multibox);
	imgsrc = document.getElementById('multibox_none');
	imgtarget.src = imgsrc.src;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_shelf_count(index){
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_shelf_count&index=' + index;
	
	var obj = document.getElementById('shelf_count_' + index);
	postvars = postvars + '&count=' + obj.options[obj.selectedIndex].value;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_shelf_count_ar(index, value){
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_shelf_count_ar&index=' + index + '&value=' + value;
	
	var obj = document.getElementById('shelf_count_' + index);
	
	if (obj != null) {
		if (value == 'add') {
			if (obj.options[obj.selectedIndex].value < 15) {
				obj.selectedIndex += 1;
			}
		} else {
			if (obj.options[obj.selectedIndex].value > 3) {
				obj.selectedIndex -= 1;
			}
		}
	}
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_shelf_height(index){
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_shelf_height&index=' + index;
	
	var obj = document.getElementById('shelf_height_' + index);
	postvars = postvars + '&height=' + obj.options[obj.selectedIndex].value;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_shelf_width(index){
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_shelf_width&index=' + index;
	
	var obj = document.getElementById('shelf_width_' + index);
	postvars = postvars + '&width=' + obj.options[obj.selectedIndex].value;
	
	buttonsReset = true;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_shelf_carry(index){
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_shelf_carry&index=' + index;
	
	var obj = document.getElementById('shelf_carry_' + index);
	postvars = postvars + '&carry=' + obj.options[obj.selectedIndex].value;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_shelf_deep(){
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_shelf_deep';
	
	var obj = document.getElementById('group_z');
	postvars = postvars + '&deep=' + obj.options[obj.selectedIndex].value;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_shelf_material(material){
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_shelf_material&material=' + material;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function add(sloupec) {
	var cols = document.getElementById('shelf_edit');
	var id = document.getElementById('shelf_id');

	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var node, nodeText, obj, old, older, i, j, childs, option;
	
	old = cols.value;
	older = old - 1;
	
	if (cols.value < 15){
		cols.value++;
		node = document.createElement('td');
			
		node.appendChild(document.createTextNode(cols.value + '. ' + sloupec));
		node.setAttribute('id', 'row_shelf_name_' + old);
		
		if (document.getElementById('row_shelf_name') != null) {
		
			document.getElementById('row_shelf_name').appendChild(node);
		
			var objects = new Array();
			objects.push('width', 'height', 'carry', 'count');
					
			for (i = 0; i < objects.length; i++){
		
				node = document.createElement('td');
				node.setAttribute('id', 'row_shelf_' + objects[i] + '_' + old);
				document.getElementById('row_shelf_' + objects[i]).appendChild(node);

				node = document.createElement('select');
				node.setAttribute('id', 'shelf_' + objects[i] + '_' + old);
				node.setAttribute('onchange', 'change_shelf_' + objects[i] +'(' + old +');');

				document.getElementById('row_shelf_' + objects[i] + '_' + old).appendChild(node);

				childs = document.getElementById('shelf_' + objects[i] + '_' + older).childNodes;

				node = document.getElementById('shelf_' + objects[i] + '_' + old);

				for (j = 0; j < childs.length; j++) {
					option = childs[j].cloneNode(true);
					node.appendChild(option);
				}
			

				node.options[document.getElementById('shelf_' + objects[i] + '_' + older).selectedIndex].selected = true;
			
			}
		
			node = document.createElement('td');
			node.setAttribute('id', 'row_shelf_light_' + old);
			document.getElementById('row_shelf_light').appendChild(node);
			document.getElementById('row_shelf_light_' + old).innerHTML = document.getElementById('row_shelf_light_' + older).innerHTML;
		}
	}
	
	buttonsReset = true;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, 'action=add_column', headers)) {
		alert('Error in servise');
	}
}

function remove() {
	var obj, node, i;
	var cols = document.getElementById('shelf_edit');
	var id = document.getElementById('shelf_id');

	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var objects = new Array();
	objects.push('name', 'width', 'height', 'carry', 'count', 'light');

	if (cols.value - 1 > 0) {
		cols.value--;

		for (i = 0; i < objects.length; i++){
			obj = document.getElementById('row_shelf_' + objects[i]);
			
			if (obj != null) {
				node = document.getElementById('row_shelf_' + objects[i] + '_' + cols.value);
				obj.removeChild(node);
			}
		}

		//obj = document.getElementById('shelf_header');
		//obj.colSpan++;
	}
	
	buttonsReset = true;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, 'action=rm_column', headers)) {
		alert('Error in servise');
	}
}

function change_back_casing(index) {
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_back_casing&index=' + index;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_front_casing(index) {
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_front_casing&index=' + index;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function change_side_casing(index) {
	var id = document.getElementById('shelf_id');
	
	var headers= new Array();
	headers['Content-type']= 'application/x-www-form-urlencoded';
	headers['Connection']='close';
	
	var postvars = 'action=change_side_casing&index=' + index;
	
	if (!send_xmlhttprequest(refresh_service, 'POST', '/m25_handle.php?id=' + id.value, postvars, headers)) {
		alert('Error in servise');
	}
}

function refresh(){
	if (!send_xmlhttprequest(refresh_image_service, 'POST', '/m25_handle.php?id=' + id.value + '&material=' + material, postvars, headers)) {
		alert('Error in servise');
	}
}

function refresh_service(xmlhttp) {
	var imageobj = document.getElementById('shelf_image');
	var obj, nodes, tmp;
	var i,j, index, inner;
		
	if (xmlhttp.readyState == 4) {
		m25Message(false);
		document.getElementById('store_alternate').innerHTML = '';
		
		if (buttonsReset) {
			//setDndButtons(false);
			buttonsReset = false;
		}		

		//alert(xmlhttp.responseText);
	
		if (xmlhttp.responseXML != null) {
			
			obj = xmlhttp.responseXML.getElementsByTagName('light');
			if (obj != null && obj.length > 0) {
				var index = xmlhttp.responseXML.getElementsByTagName('light_index')[0].firstChild.data;
				var value = xmlhttp.responseXML.getElementsByTagName('light_value')[0].firstChild.data;
				
				var tmp = document.getElementById('row_shelf_light_' + index);
				
				if (tmp != null)
					tmp.innerHTML = value;
			}
			
			
			
			/*obj = xmlhttp.responseXML.getElementsByTagName('multibox_store');
			if (obj != null && obj.length > 0) {
				for (j = 0; j < obj.length; j++) {
						nodes = obj[j].childNodes;

						for (i = 0; i < nodes.length; i++){
							if (nodes[i].nodeName == 'multibox_index')
								index = nodes[i].firstChild.data;
								
							if (nodes[i].nodeName == 'multibox_value')
								document.getElementById('multibox_store_' + index).innerHTML = nodes[i].firstChild.data;
						}
				}
			}*/
			
			
			/*obj = xmlhttp.responseXML.getElementsByTagName('multibox_store');
			if (obj != null && obj.length > 0) {
				var index = xmlhttp.responseXML.getElementsByTagName('multibox_index')[0].firstChild.data;
				var value = xmlhttp.responseXML.getElementsByTagName('multibox_value')[0].firstChild.data;
				
				document.getElementById('multibox_store_' + index).innerHTML = value;
			}*/
			
			
			obj = xmlhttp.responseXML.getElementsByTagName('carry');
			if (obj != null && obj.length > 0) {
				for (j = 0; j < obj.length; j++) {
						nodes = obj[j].childNodes;

						for (i = 0; i < nodes.length; i++){
							if (nodes[i].nodeName == 'carry_index')
								index = nodes[i].firstChild.data;
								
							if (nodes[i].nodeName == 'carry_values') {
								inner = nodes[i].firstChild.data;
								inner = inner.replace("&gt;", '<');
								inner = inner.replace("&lt;", '>');
								
								select_innerHTML(document.getElementById('shelf_carry_' + index), inner);
							}
						}
				}
			}
			
			obj = xmlhttp.responseXML.getElementsByTagName('width');
			if (obj != null && obj.length > 0 && document.getElementById('_total_size') != null)
				document.getElementById('_total_size').innerHTML = obj[0].firstChild.data;
				
			obj = xmlhttp.responseXML.getElementsByTagName('weight');
			if (obj != null && obj.length > 0 && document.getElementById('_total_weight') != null)
				document.getElementById('_total_weight').innerHTML = obj[0].firstChild.data;
				
			obj = xmlhttp.responseXML.getElementsByTagName('alternate');
			if (obj != null && obj.length > 0)
				alert(obj[0].firstChild.data);
				
			obj = xmlhttp.responseXML.getElementsByTagName('price');
			if (obj != null && obj.length > 0)
				document.getElementById('_total_price').innerHTML = '<strong>' + obj[0].firstChild.data + '</strong>';

			obj = xmlhttp.responseXML.getElementsByTagName('credit');
			if (obj != null && obj.length > 0)
				document.getElementById('_credit').innerHTML = '<strong>' + obj[0].firstChild.data + '</strong>';				
			
			obj = xmlhttp.responseXML.getElementsByTagName('discount');
			if (obj != null && obj.length > 0)
				document.getElementById('_discount_price').innerHTML = '<strong>' + obj[0].firstChild.data + '</strong>';
				
			obj = xmlhttp.responseXML.getElementsByTagName('addPrice');
			if (obj != null && obj.length > 0)
				document.getElementById('_add_total_price').innerHTML = '<strong>' + obj[0].firstChild.data + '</strong>';			
				
			if (document.getElementById('store_state') != null) {
				obj = xmlhttp.responseXML.getElementsByTagName('store');
				if (obj != null && obj.length > 0)
					document.getElementById('store_state').innerHTML = document.getElementById('store_' + obj[0].firstChild.data).value;
		
				obj = xmlhttp.responseXML.getElementsByTagName('casing');
				if (obj != null && obj.length > 0)
					if (obj[0].firstChild.data == 'true')
						document.getElementById('store_state').innerHTML = document.getElementById('store_state').innerHTML + ' ' + document.getElementById('casing_presence').value;
			}
			
			obj = xmlhttp.responseXML.getElementsByTagName('alternate_shelf');
			
			if (obj != null && obj.length > 0)
				if (obj[0].firstChild != null){
					document.getElementById('store_alternate').innerHTML = '<button type="button" onclick="m25Message(false);" title="" class="krizek">&nbsp;</button>' + obj[0].firstChild.data;
					m25Message(true);
				}
		}
		
        imageobj.src = document.getElementById('original_img').value + '&' + (new Date()).getTime();
        
        setDndButtons(false);
        
        if (magnetoReset && magneto != null && !magnetoIgnore) {
			magneto.reset();
			setDndFields();
			magnetoReset = false;
		}
	}
}

function m25Message(visible){
	if (visible)
		document.getElementById('store_alternate').style.cssText ='display : block;';
	else
		document.getElementById('store_alternate').style.cssText ='display : none;';
}

function select_innerHTML(objeto,innerHTML){
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.toLowerCase().replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}