

function tz_testFormRequiredAndSubmit(formName, testFields)
{
	if (tz_testFormRequired(testFields))
	{
		var f = document.forms[formName];
		f.submit();
	}
}


function tz_testFormRequired(testFields)
{
	//alert("test");
var arrTestFields = testFields;
	var obj;
	var name = "";
//alert("test");
	if (arrTestFields)
	for (i=0; i < arrTestFields.length; i++)
	{
		name = "fields["+arrTestFields[i]+"]";
//alert("name:"+name);
		obj = document.getElementById(name);
		if (!obj) 
		{
			alert("Unknown field "+name);
			return false;
		}
		if (!tz_testFormField(obj,name))
		{
			obj.focus();
			alert(obj.title + " is required");
			return false;
		}
	}
	return true;
}

function tz_testFormField(obj, name)
{
	var type = obj.type;
	type = type.toUpperCase();
	//alert(type);
	if (type=="TEXT")
		return tz_testFormText(obj);
	else if (type=="CHECKBOX")
		return tz_testFormCheckBox(obj);
	else if (type=="RADIO") {
		obj = document.forms[0].elements[name];
		return tz_testFormRadio(obj); //ByName(name);
 	} else if (type=="TEXTAREA")
		return tz_testFormTextarea(obj);
	else if (type=="SELECTOR" || type=="SELECT-ONE")
		return tz_testFormSelector(obj);
	else {
		alert ("Unkown type "+type);
		return false;
	}
}	

function tz_testFormText(obj)
{
	return obj.value!="";
}

function tz_testFormCheckbox(obj)
{
	return obj.checked;
}

/*
function tz_testFormRadio(collection) {

 // var collection = document.getElementById(name);
  alert(collection.length);
  for (i=0;i<collection.length;i++) {
    	if (collection[i].checked)
   	 	return true;
  }
  return false;
}
*/

function tz_testFormRadio(obj)
{
//alert(getCheckedValue(obj));
	return (getCheckedValue(obj)!="");
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}




function tz_testFormRadioByName(name) {

  var collection = document.getElementById(name);
  //alert(document.getElementById(name).length);
  for (i=0;i<collection.length;i++) {
  if (collection[i].checked)
    	return true;
  }
  return false;
}

function tz_formRadioValue(radioObj)
{
	//alert("radio");
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
	
  	for (i=0;i<radioObj.length;i++) {
  		//alert(radioObj[i].value);
    	if (radioObj[i].checked)
    		return(radioObj[i].value);
  	}
	return false;
}

function tz_formSelectorValue(name)
{
 	var obj = document.getElementById(name);
	if (obj.selectedIndex)
 		return obj.options[obj.selectedIndex].value;
	return '';
}


function tz_testFormTextarea(obj)
{
	return obj.value!="";
}

function tz_testFormSelector(obj)
{
	if (obj.selectedIndex == -1)
		return false;
	return (obj.options[obj.selectedIndex].value != 0);
}

function testValidEmail ()
{
	return true;
}

function tz_checkEmail(email){
	
	if(email.indexOf('@')>-1){
		if(email.indexOf('.',email.indexOf('@'))<0)
			return false;
	}
	else{
		return false;
	}
	return true;

}


function popup(url) 
{
 params  = 'width='+screen.width;
 params += ', height='+screen.height;
 params += ', top=0, left=0'
 params += ', fullscreen=yes';

 newwin=window.open(url,'windowname4', params);
 if (window.focus) {
	 newwin.focus()
}


 
 return false;
}



