function clearSearch(obj) {
	if (obj.value == "search") {
		obj.value = "";
	}
}

function fillSearch(obj) {
	if (obj.value.length == 0) {
		obj.value = "search";
	}
}

function openWin(url,width,height) {
	window.open(url,'niceWin','height='+height+',width='+width+',status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}

function openWinVtrenz(a,width,height) {
	window.open(a.href,'niceWin','height='+height+',width='+width+',status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}

function videoWin(video) {
	window.open('/playmedia.php?v='+video,'logos','height=460,width=400,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no');
}

// submit 'formname' form to 'url' page
function submitForm(formname,url) {
	this.document[formname].action = url;
	this.document[formname].submit();
};

// checkes if string includes invalid charecters
// returs true when there are no invalid charecters 
function isValidChars(testie) {
	var invalid = /[<>'|]/
	return !invalid.test(testie);
};

// checkes if string is syntex valid email
// returns true when the email is syntex valid
function isValidEmail(testie) {
	var invalid = new RegExp("^[-0-9a-z_][-0-9a-z_.]*[^.]@[0-9a-z_][-0-9a-z.]*[0-9a-z_]\.[0-9a-z_]{2,3}$", "i");
	return (invalid.test(testie));
};

// checks if the a string is a number
// returns true when the string is a valid number
// canBeEmpty - optional when set to 'true' will allow empty string
// else will not alow empty string
function isNumber(testie,canBeEmpty) {
	if (canBeEmpty) {
		var valid = /^[0-9-. ]*$/
	} else {
		var valid = /^[0-9-. ]+$/
	};
	return valid.test(testie);
};

	
// Validate the the 'formName' form 'fieldName' 
// when not valid will alert 'msg'
// type - optional when empty will check if empty
// type = 'number' checks if a number
// type = 'nullnumber' checks if a empty or number
// type = 'email' checks if a valid email
function isValidField(formName,fieldName, msg, type) {
	var valid = true
	var form = eval(document[formName])
	var field = eval(form[fieldName])
	var value = field.value

	switch (type) {
		case 'number' :
			if (!isNumber(value)) {
				valid = false;
			}
			break;
		case 'nullnumber' :
			if (!isNumber(value,true)) {
				valid = false;
			}
			break;
		case 'email' :
			if (!isValidEmail(value)) {
				valid = false;
			}
			break;
		case 'chk' :
			if (!field.checked) {
				valid = false;
			}else{
				valid = true;	
			}
			break;
		case 'radiobtn' :	
			if (field[0].checked || field[1].checked) {
				valid = true;
			}else{
				valid = false;	
			}
			break;	
		
		case 'multiradiobtn':
		/*
		var arro=document.getElementsByName(fieldName);
			valid=false;
			for(var j=0;j<field.length;j++)
			{
			  if(field[j].checked)
			  {
				valid=true;
				break;
			  }
			}
			break;
		*/
		
		var arro=document.getElementsByName(fieldName);
			var ctr=0;
			for(var j=0;j<arro.length;j++){
			  if(arro[j].checked){
				ctr++;
				break;
			  }
			}
			if(ctr==0){
				valid = false;
			}else{
				valid = true;	
			}
		break;
		

		default :
			if (value.length == 0) {
				valid = false;
			}
	} 
	if (!valid) {
		alert(msg);
		if(type!='radiobtn' && type!='multiradiobtn'){
			field.focus();
		}else{
			field[1].focus();
		}
		return false
	}  else {
		return true
	}
}

// clear form
function clearForm(formName) {
	var form = eval(document[formName]) 
	form.reset()

}



function alphanumeric(e){
var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if(!((unicode == 45 || (unicode >= 48 && unicode <= 57) || (unicode >= 65 && unicode <= 90) || (unicode >= 97 && unicode <= 122) || unicode == 32))){
			alert("Only alphanumeric characters are permitted");
			return false //disable key press
		}
	}
}
