//Custom JavaScript Functions by Shawn Olson
//Copyright 2006
//http://www.shawnolson.net
//If you copy any functions from this page into your scripts, you must provide credit to Shawn Olson & http://www.shawnolson.net
//This file may not be used on adult sites
//or any site that incites hate
//or sites that are not child-friendly
//*******************************************

	function stripCharacter(words,character) {
	//documentation for this script at http://www.shawnolson.net/a/499/
	  var spaces = words.length;
	  for(var x = 1; x<spaces; ++x){
	   words = words.replace(character, "");   
	 }
	 return words;
    }
	
	function changecss(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
	 }	
	}
	
	function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
	
function checkUncheckSome(controller,theElements) {
	//Programmed by Shawn Olson
	//Copyright (c) 2006
	//Permission to use this function provided that it always includes this credit text
	//  http://www.shawnolson.net
	//Find more JavaScripts at http://www.shawnolson.net/topics/Javascript/
	
	
	//theElements is an array of objects designated as a comma separated list of their IDs
	//If an element in theElements is not a checkbox, then it is assumed
	//that the function is recursive for that object and will check/uncheck
	//all checkboxes contained in that element
	
	
     var formElements = theElements.split(',');
	 var theController = document.getElementById(controller);
	 for(var z=0; z<formElements.length;z++){
	  theItem = document.getElementById(formElements[z]);
	  if(theItem){
	  if(theItem.type){
        if(theItem.type == 'checkbox' && theItem.id != theController.id){
	     theItem.checked = theController.checked;
	    }
	  } else {

	    var nextArray = '';
	     for(var x=0;x <theItem.childNodes.length;x++){
	      if(theItem.childNodes[x]){
	        if (theItem.childNodes[x].id){
	          nextArray += theItem.childNodes[x].id+',';
		    }
	      }
	     }
	     checkUncheckSome(controller,nextArray);
	   
	   }
	  
	  }
     }
    }
	
	
	
	
	function changeImgSize(objectId,newWidth,newHeight) {
	  imgString = 'theImg = document.getElementById("'+objectId+'")';
	  eval(imgString);
	  oldWidth = theImg.width;
	  oldHeight = theImg.height;
	  if(newWidth>0){
	   theImg.width = newWidth;
	  } 
	  if(newHeight>0){
	   theImg.height = newHeight;
	  } 
	
	}
	
	function changeColor(theObj,newColor){
	  eval('var theObject = document.getElementById("'+theObj+'")');
	  if(theObject.style.backgroundColor==null){theBG='white';}else{theBG=theObject.style.backgroundColor;}
	  if(theObject.style.color==null){theColor='black';}else{theColor=theObject.style.color;}
	  //alert(theObject.style.color+' '+theObject.style.backgroundColor);
      switch(theColor){
	    case newColor:
		  switch(theBG){
			case 'white':
		      theObject.style.color = 'black';
		    break;
			case 'black':
			  theObject.style.color = 'white';
			  break;
			default:
			  theObject.style.color = 'black';
			  break;
		  }
		  break;
	    default:
		  theObject.style.color = newColor;
		  break;
	  }
	}

 function show_hide(monid, itemid){
   
   mon_item = document.getElementById(monid);
   fitem = document.getElementById(itemid);
//    alert(document.getElementById(itemid));
//    alert(document.getElementById(monid).checked); 
    if (mon_item.checked){
      fitem.disabled=false;
    }
    else
      fitem.disabled=true;
 }
  function add_custom_program(num){
      prog = document.getElementById('custom_program');
      
      num.value++;
      
      var newdiv = document.createElement('div');
      newdiv.setAttribute("id","cprogram_"+num.value); 
      new_program = '<input type="text" name="new_program[]" maxlength="254" size="40" />&nbsp;';
      
      new_percent = '<select name="new_percent[]"><option value="0"> - </option><option value="<10">&lt;10%</option>';
        for (i=10; i<=100; i=i+10){
            new_percent = new_percent + '<option value="' + i + '">' + i + '%</option>';
        }
      new_percent = new_percent + '</select>&nbsp;&nbsp;<a id="act_button" href="#" onClick="remove_custom_program('+ num.value +'); return false;">- Ištrinti</a>';
      
      newdiv.innerHTML = new_program + new_percent;      
      prog.appendChild(newdiv);     
  }
  
  function add_other_files(num){
    ofiles = document.getElementById('other_files_id');
    
    num.value++;
    var newdiv = document.createElement('div');
    newdiv.setAttribute("id", "other_files_"+num.value);    
    newfield = '<input type="text" size="40" name="other_files_desc[]" maxlength="254" style="color: #808080; font-size: 12px;" onFocus="if (this.value==\'Aprašymas\') {this.value=\'\';}" value="Aprašymas" \/>  <input type="file" size="1" name="other_files[]" \/>';
    newfield = newfield + '&nbsp;&nbsp;<a id="act_button" href="#" onClick="remove_other_file('+ num.value + '); return false;">- Ištrinti</a>';
    
    newdiv.innerHTML = newfield;
    ofiles.appendChild(newdiv);
  }
  
  function remove_other_file(num){
    ofiles = document.getElementById('other_files_id');
    olddiv = document.getElementById('other_files_'+ num);
    ofiles.removeChild(olddiv);
    document.getElementById('ofiles').value--;  
  }
  
  function remove_custom_program(num){
    prog = document.getElementById('custom_program');
     
    olddiv = document.getElementById('cprogram_' + num);
     
    prog.removeChild(olddiv);
    
    document.getElementById('custom_count').value--;
  }
