var formblock;
var forminputs;

function prepare() {
formblock= document.getElementById('browse_form');
forminputs = formblock.getElementsByTagName('input');
}

function select_all(name, value) {
for (i = 0; i < forminputs.length; i++) {
// regex here to check name attribute
var regex = new RegExp(name, "i");
if (regex.test(forminputs[i].getAttribute('name'))) {
if (value == '1') {
forminputs[i].checked = true;
} else {
forminputs[i].checked = false;
}
}
}
}

if (window.addEventListener) {
window.addEventListener("load", prepare, false);
} else if (window.attachEvent) {
window.attachEvent("onload", prepare)
} else if (document.getElementById) {
window.onload = prepare;
}


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 removeObject(divNum) {

	var d = document.getElementById('myDiv');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);

}

function addArticleCatSelect(currCategory) {
  var ni = document.getElementById('myDiv');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = '<select name="cat_id[]">'+currCategory+'</select>[<a href="javascript:;" onclick="removeObject(\''+divIdName+'\');">-</a>]';
  ni.appendChild(newdiv);
}




function Toggle_It(itemID){
		
  if ((document.getElementById(itemID).style.display == 'inline'))
  {
	document.getElementById(itemID).style.display = 'none';
  } else {
	document.getElementById(itemID).style.display = 'inline';
  } 
  
}// end function



/*
	DREAMWEAVER SCRIPTS
*/
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


/* ORDER SCRIPTS  */

//input validation on key event
//restricting character input to specified restriction type
function restrictChars(thisObj, e, restrictionType)
{                        
	//check if event object exists        
	//get keycode char
	var code = window.event ? window.event.keyCode : e.which;
	//get equivalent char from character code
	var character = String.fromCharCode(code);
	//var thisVal = parseInt(thisObj.value.toString() + character.toString());                                    
	//check restriction type                        
	if (code != 8 && code != 37 && code != 39 && code != 9 && code != 13) //backspace
	{            
		if (restrictionType == 'd')
		{
			if (code >= 48 && code <= 57)//digits only from 0-9
			{
				return true;
			}
			else
			{
				return false;
			}   
		}   
		else
		{
			if (restrictionType == 'a')
			{                    
				if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code == 32)
				{
					return true;
				}
				else
				{
					return false;
				}                    
			}
		}         
	}   
	return true;                     
}
function show_dialog(_w, _title, _url, e)
{
	//prevent default
	e.preventDefault();
	//preload dialog view via ajax request
	$.get(_url, {}, function(view){
		$('#dialog').html(view);
	});
	//show dialog
	$('#dialog').dialog({
		title : _title,
		width : _w,
		modal : true,
		resizable : false,
		closeOnEscape : true,
		close : function () {$('#dialog').dialog('destroy'); }
	});
}
function close_dialog(id)
{
	$('#'+id).dialog('close');
}



