function setFocus() {
	document.getElementById("cse-search-box").q.focus();
}

// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// whole form

function checkContactForm(theForm) {
	var why = "";
	why += checkName(theForm.name.value);
//	why += checkPassword(theForm.pass.value, theForm.pass2.value);
	why += checkEmail(theForm.email.value);
	why += checkSubject(theForm.subject.value);
	why += checkMessage(theForm.message.value);
	/*   why += checkPhone(theForm.phone.value);
	    why += isEmpty(theForm.notempty.value);
	why += isDifferent(theForm.different.value);
	for (i=0, n=theForm.radios.length; i<n; i++) {
		if (theForm.radios[i].checked) {
			var checkvalue = theForm.radios[i].value;
			break;
		} 
	}
	why += checkRadio(checkvalue);
	why += checkDropdown(theForm.choose.selectedIndex);*/
	if (why != "") {
		alert(why);
		return false;
	}
	return true;
}

// email

function checkEmail (strng) {
	var error="";
	if (strng == "") {
		error = "Пропущена строка: \" Электронная почта\"\n";
	}
	
	var emailFilter=/^.+@.+\..{2,4}$/;
	if (!(emailFilter.test(strng))) { 
		error = "Неправильный электронный адрес\n";
	}
	else {
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (strng.match(illegalChars)) {
			error = "Неправильный электронный адрес\n";
		}
	}
	return error;    
}

function checkName (strng) {
	var error = "";
	if (strng == "") {
		error = "Пропущена строка: \"  Имя \"\n";
	}
	
	return error;
}

function checkSubject (strng) {
	var error = "";
	if (strng == "") {
		error = "Пропущена строка : \" Тема \"\n";
	}
	
	return error;
}

function checkMessage (strng) {
	var error = "";
	if (strng == "") {
		error = "Пропущена строка  : \" Сообщение \"\n";
	}
	
	return error;
}

// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter a phone number.\n";
	}
	
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
		error = "The phone number contains illegal characters.";
		
	}
	if (!(stripped.length == 10)) {
		error = "The phone number is the wrong length. Make sure you included an area code.\n";
	} 
	return error;
}


// password 
function checkPassword (strng, strng2) {
	var error = "";

	var illegalChars = /[\W_]/; // allow only letters and numbers
	
	// checking length
	if ((strng.length < 4) || (strng.length > 10)) {
		error = "אורך סיסמא צריך להיות בין 4-8 תווים\n";
	}
	// checking legal characters
	else if (illegalChars.test(strng)) {
		error = "סיסמא יכולה להכיל אותיות באנגלית ומספרים בלבד\n";
	} 
	// checking that the two  passwords match
	else if (strng != strng2) {
		error = "אישור סיסמא שגוי\n";
	}
	return error;    
}    

// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
	var error = "";

	var illegal1 = /[^a-zA-Z_\-\s0-9א-ת]/;
	if ((strng.length < 1) || (strng.length > 20)) {
		error = "אורך שם משתמש צריך להיות בין 1-20 תווים\n";
	}
	else if (illegal1.test(strng)) {
		error = "שם משתמש יכול להכיל אותיות בעברית או אנגלית, מספרים, רווח, קו תחתי וסימן מינוס בלבד\n";
	} 
	return error;
}       


// non-empty textbox

function isEmpty(strng) {
	var error = "";
	if (strng.length == 0) {
		error = "The mandatory text area has not been filled in.\n"
	}
	return error;	  
}

// was textbox altered

function isDifferent(strng) {
	var error = ""; 
	if (strng != "Can\'t touch this!") {
		error = "You altered the inviolate text area.\n";
	}
	return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
	var error = "";
	if (!(checkvalue)) {
		error = "Please check a radio button.\n";
	}
	return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
	var error = "";
	if (choice == 0) {
		error = "You didn't choose an option from the drop-down list.\n";
	}    
	return error;
}    



