function IsEmailValid(checkThisEmail)
{
	var myEMailIsValid = true;
	var myAtSymbolAt = checkThisEmail.indexOf('@');
	var myLastDotAt = checkThisEmail.lastIndexOf('.');
	var mySpaceAt = checkThisEmail.indexOf(' ');
	var myLength = checkThisEmail.length;
	
	if (myAtSymbolAt < 1 )
	 {myEMailIsValid = false}
	
	if (myLastDotAt < myAtSymbolAt)
	 {myEMailIsValid = false}
	
	if (myLength - myLastDotAt <= 2)
	 {myEMailIsValid = false}
	
	if (mySpaceAt != -1)
	 {myEMailIsValid = false}
	
	return myEMailIsValid
}

function link_hover(field,pic)
{
	document.getElementById(field).src = "gfx/" + pic;
}

function change_pic(field,pic)
{
	document.all(field).src = "gfx/" + pic;
}

function send_mail()
{
	TheForm = document.contact;
	
	if (TheForm.contact_name.value == '')
	{
		alert("Please fill the contact name");
		TheForm.name.focus()
		return;
	}
	if (TheForm.phone.value == '')
	{
		alert("Please fill your phone number");
		TheForm.phone.focus()
		return;
	}
	if (!IsEmailValid(TheForm.email.value))
	{
		alert("Please fill your Email address");
		TheForm.email.focus()
		return;
	}
	
	TheForm.action = "?p=contact_us&cmd=send";
	TheForm.submit();
}

function check_contact_info()
{
	TheForm = document.contact;
	if (TheForm.info.value == 'אחר')
	{
		document.getElementById("other1").style.display = "block";
	}
	else
	{
		document.getElementById("other1").style.display = "none";
	}
}

function check_key(nextfield)
{
	var EnterKey = 13;
	if (window.event.keyCode == EnterKey)
	{
		document.getElementById(nextfield).focus();
	}
}

function fn_login()
{
	TheForm = document.frm_login;
	
	if (!IsEmailValid(TheForm.username.value))
	{
		alert("Please fill the email field currectly");
		TheForm.username.focus();
		return;
	}
	if (TheForm.password.value == '')
	{
		alert("Please fill the password field");
		TheForm.password.focus();
		return;
	}
	
	TheForm.action = "index.php?p=business/operators/login/?cmd=login";
	TheForm.submit();
}

function fn_retreive_password()
{
	TheForm = document.retreive_password;
	
	if (!IsEmailValid(TheForm.user_email.value))
	{
		alert("Please fill the email field currectly");
		TheForm.user_email.focus();
		return;
	}
	
	TheForm.action = "index.php?p=business/operators/retrieve/password/?cmd=send";
	TheForm.submit();
}

function fn_register()
{
	TheForm = document.register;
	
	if (TheForm.user_first_name.value == '')
	{
		alert("Please insert your first name");
		TheForm.user_first_name.focus();
		return;
	}
	if (TheForm.user_last_name.value == '')
	{
		alert("Please insert your last name");
		TheForm.user_last_name.focus();
		return;
	}
	if (TheForm.user_phone.value == '')
	{
		alert("Please insert your phone number");
		TheForm.user_phone.focus();
		return;
	}
	if (!IsEmailValid(TheForm.user_email.value))
	{
		alert("Please insert your valid email address");
		TheForm.user_email.focus();
		return;
	}
	if (TheForm.user_password.value == '')
	{
		alert("Please choose a password");
		TheForm.user_password.focus();
		return;
	}
	if (!TheForm.user_agree.checked)
	{
		alert("You must agree to the privacy statement");
		TheForm.user_agree.focus();
		return;
	}
	
	TheForm.action = "index.php?p=business/operators/register/?cmd=add";
	TheForm.submit();
}

function show_arrow(x,y)
{
	document.getElementById('arrow').style.top = y;
	document.getElementById('arrow').style.left = x;
	document.getElementById('arrow').style.display = "block";
}

function hide_arrow()
{
	document.getElementById('arrow').style.display = "none";
}

function fn_search() {
	TheForm = document. frm_search;

	var cat_id = TheForm.search.value;

	if (cat_id == "50") {
		if (window.confirm("הכניסה מותרת מעל גיל 18, בלחיצה על אישור אני מצהיר/ה כי גלשתי לאתר מרצוני החופשי ועל אחריותי, ולא תהיה לי כל טענה כלפי אתר כדאי")) {
			location = "?p=cat&id=" + cat_id;
		}
	}
	else
	{
		location = "?p=cat&id=" + cat_id;
	}
}

function fn_search1() {
	TheForm = document. frm_search;

	var cat_id = TheForm.search.value;

	if (cat_id == "50") {
		if (window.confirm("הכניסה מותרת מעל גיל 18, בלחיצה על אישור אני מצהיר/ה כי גלשתי לאתר מרצוני החופשי ועל אחריותי, ולא תהיה לי כל טענה כלפי אתר כדאי")) {
			location = "?p=cat&id=" + cat_id;
		}
	}
	else
	{
		location = "?p=cat&id=" + cat_id;
	}
}

function fn_flower_go(i) {
	var url = document.getElementById('url' + i).value;
	var q = document.getElementById('q' + i).value;
	
	window.open(url + q,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');
//	location = url + q;
}

function fn_flower_link_go(i, aff, cat_id) {
	if (document.getElementById('flower_link' + i).value > 0) {
		var url = "pages/counter_link.php?id=" + document.getElementById('flower_link' + i).value + "&aff=" + aff + "&cat_id=" + cat_id;
	
		window.open(url,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');
		//location = url;
	}
	else
	{
		alert('נא ללחוץ על החץ ולבחור אתר');
	}
}

var req;

function loadXMLDoc(url) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		//req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}
}

function add_stat(id, aff, cat_id) {
	var url = "pages/counter.php?id=" + id + "&aff=" + aff + "&cat_id=" + cat_id;

	//window.open(url,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');

	loadXMLDoc(url);
}

function add_stat_flower_link(id, i) {
	var flower_link = document.getElementById('flower_link' + i).value;

	var url = "pages/counter_link.php?id=" + id + "&i=" + flower_link;

	loadXMLDoc(url);
	//window.open(url,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');
}

function fn_flower_link_timer(i) {

	timerID  = setTimeout("fn_flower_link_go(" + i + ")", 5000);
}

function link_timer(i) {

	timerID  = setTimeout("document.frm_f_link" + i + ".submit();", 5000);
}

function aff_register()
{
	TheForm = document.frm_aff_register;
	
	if (TheForm.aff_first_name.value == '')
	{
		alert("נא הזן שם פרטי");
		TheForm.aff_first_name.focus();
		return;
	}
	if (TheForm.aff_last_name.value == '')
	{
		alert("נא הזן שם משפחה");
		TheForm.aff_last_name.focus();
		return;
	}
	if (TheForm.aff_phone_1.value == '')
	{
		alert("נא הזן מספר טלפון");
		TheForm.aff_phone_1.focus();
		return;
	}
	if (!IsEmailValid(TheForm.aff_email.value))
	{
		alert("נא הזן כתובת דואר אלקטרוני תקינה");
		TheForm.aff_email.focus();
		return;
	}
	if (TheForm.aff_url.value == '')
	{
		alert("נא הזן את כתובת אתר האינטרנט");
		TheForm.aff_url.focus();
		return;
	}
	if (TheForm.aff_username.value == '')
	{
		alert("נא הזן שם משתמש");
		TheForm.aff_username.focus();
		return;
	}
	if (TheForm.aff_password.value == '')
	{
		alert("נא הזן סיסמא");
		TheForm.aff_password.focus();
		return;
	}
	if (TheForm.event_agree.checked == false)
	{
		alert("עליך להסכים להסכם האתר");
		TheForm.event_agree.focus();
		return;
	}

	TheForm.action = "index.php?p=affiliates_register&cmd=add";
	TheForm.submit();
}

function fn_aff_login()
{
	TheForm = document.login;
	
	if (TheForm.aff_email.value == '')
	{
		alert("נא הזן אימייל");
		TheForm.aff_email.focus();
		return;
	}
	if (TheForm.aff_password.value == '')
	{
		alert("נא הזן סיסמא");
		TheForm.aff_password.focus();
		return;
	}
	
	TheForm.action = "index.php?p=affiliates_admin&cmd=login";
	TheForm.submit();
}

function fn_aff_retreive_password()
{
	TheForm = document.retreive_password;
	
	if (TheForm.aff_email.value == '')
	{
		alert("נא הזן כתובת דואר אלקטרוני");
		TheForm.aff_email.focus();
		return;
	}
	
	TheForm.action = "index.php?p=affiliates_retreive_password&cmd=send";
	TheForm.submit();
}

function change_aff_link()
{
	TheForm = document.frm_aff_register;

	TheForm.aff_link.value = 'http://kedai.co.il/?aff=' + TheForm.aff_username.value;
}
function fn_admin_switch_aff()
{
	var admin_aff_id = document.getElementById('admin_aff_id').value;
	location = "index.php?p=affiliates_admin&cmd=set_aff&admin_aff_id=" + admin_aff_id;
}

function send_a_friend()
{
	TheForm = document.contact;
	
	if (TheForm.name.value == '')
	{
		alert("אנא משלאו את שמכם");
		TheForm.name.focus()
		return;
	}
	if (!IsEmailValid(TheForm.email.value))
	{
		alert("אנא מלאו את כתובת האימייל שלכם");
		TheForm.email.focus()
		return;
	}
	if (TheForm.friend_name.value == '')
	{
		alert("אנא מלאו את שם חברכם");
		TheForm.friend_name.focus()
		return;
	}
	if (!IsEmailValid(TheForm.friend_email.value))
	{
		alert("אנא מלאו את כתובת האימייל של חברכם");
		TheForm.friend_email.focus()
		return;
	}
	
	TheForm.action = "index.php?p=tell_a_friend&cmd=send";
	TheForm.submit();
}

function fn_flower_change() {
	TheForm = document.frm_aff_register;
	
	if (TheForm.aff_flower_id.value != '0' && TheForm.aff_flower_id.value != '-1') {
		document.getElementById('aff_link_title').style.display = "block";	
		document.getElementById('aff_link_url').style.display = "block";	
	}
	else
	{
		document.getElementById('aff_link_title').style.display = "none";	
		document.getElementById('aff_link_url').style.display = "none";	
	}
}

function view_category() {
	TheForm = document.frm_aff_register;
	
	var id = TheForm.aff_category_id.value;

	if (id != "0") {
		var url = "?p=cat&id=" + id;
		window.open(url,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');
	}
	else
	{
		alert("נא לבחור קטגוריה לצפייה");	
	}
}

function show_explain() {
	document.getElementById('explain').style.display = "block";
}

function hide_explain() {
	document.getElementById('explain').style.display = "none";
}

function save_affiliate() {
	TheForm = document.frm_aff_register;
	
	if (TheForm.aff_first_name.value == '')
	{
		alert("נא הזן שם פרטי");
		TheForm.aff_first_name.focus();
		return;
	}
	if (TheForm.aff_last_name.value == '')
	{
		alert("נא הזן שם משפחה");
		TheForm.aff_last_name.focus();
		return;
	}
	if (TheForm.aff_phone_1.value == '')
	{
		alert("נא הזן מספר טלפון");
		TheForm.aff_phone_1.focus();
		return;
	}
	if (TheForm.aff_url.value == '')
	{
		alert("נא הזן את כתובת אתר האינטרנט");
		TheForm.aff_url.focus();
		return;
	}
	if (TheForm.aff_password.value == '')
	{
		alert("נא הזן סיסמא");
		TheForm.aff_password.focus();
		return;
	}

	TheForm.action = "index.php?p=affiliates_admin&cmd=save";
	TheForm.submit();
}


function c_register()
{
	TheForm = document.frm_c_register;
	
	if (TheForm.c_first_name.value == '')
	{
		alert("נא הזן שם פרטי");
		TheForm.c_first_name.focus();
		return;
	}
	if (TheForm.c_last_name.value == '')
	{
		alert("נא הזן שם משפחה");
		TheForm.c_last_name.focus();
		return;
	}
	if (TheForm.c_phone_1.value == '')
	{
		alert("נא הזן מספר טלפון");
		TheForm.c_phone_1.focus();
		return;
	}
	if (!IsEmailValid(TheForm.c_email.value))
	{
		alert("נא הזן כתובת דואר אלקטרוני תקינה");
		TheForm.c_email.focus();
		return;
	}
	if (TheForm.c_url.value == '')
	{
		alert("נא הזן את כתובת אתר האינטרנט");
		TheForm.c_url.focus();
		return;
	}
	if (TheForm.c_password.value == '')
	{
		alert("נא הזן סיסמא");
		TheForm.c_password.focus();
		return;
	}
	if (TheForm.event_agree.checked == false)
	{
		alert("עליך להסכים להסכם האתר");
		TheForm.event_agree.focus();
		return;
	}

	TheForm.action = "index.php?p=clients_register&cmd=add";
	TheForm.submit();
}

function fn_c_login()
{
	TheForm = document.login;
	
	if (TheForm.c_email.value == '')
	{
		alert("נא הזן אימייל");
		TheForm.c_email.focus();
		return;
	}
	if (TheForm.c_password.value == '')
	{
		alert("נא הזן סיסמא");
		TheForm.c_password.focus();
		return;
	}
	
	TheForm.action = "index.php?p=clients_admin&cmd=login";
	TheForm.submit();
}

function fn_c_retreive_password()
{
	TheForm = document.retreive_password;
	
	if (TheForm.c_email.value == '')
	{
		alert("נא הזן כתובת דואר אלקטרוני");
		TheForm.c_email.focus();
		return;
	}
	
	TheForm.action = "index.php?p=clients_retreive_password&cmd=send";
	TheForm.submit();
}

function change_c_link()
{
	TheForm = document.frm_c_register;

	TheForm.c_link.value = 'http://kedai.co.il/?c=' + TheForm.c_username.value;
}
function fn_admin_switch_c()
{
	var admin_c_id = document.getElementById('admin_c_id').value;
	location = "index.php?p=clients_admin&cmd=set_c&admin_c_id=" + admin_c_id;
}

function save_client() {
	TheForm = document.frm_c_register;
	
	if (TheForm.c_first_name.value == '')
	{
		alert("נא הזן שם פרטי");
		TheForm.c_first_name.focus();
		return;
	}
	if (TheForm.c_last_name.value == '')
	{
		alert("נא הזן שם משפחה");
		TheForm.c_last_name.focus();
		return;
	}
	if (TheForm.c_phone_1.value == '')
	{
		alert("נא הזן מספר טלפון");
		TheForm.c_phone_1.focus();
		return;
	}
	if (TheForm.c_url.value == '')
	{
		alert("נא הזן את כתובת אתר האינטרנט");
		TheForm.c_url.focus();
		return;
	}
	if (TheForm.c_password.value == '')
	{
		alert("נא הזן סיסמא");
		TheForm.c_password.focus();
		return;
	}

	TheForm.action = "index.php?p=clients_admin&cmd=save";
	TheForm.submit();
}

function fn_top_search()
{
	TheForm = document.frm_top_search;

	var searchsite;
	var q = TheForm.c.value;

	if (TheForm.search_type[0].checked) {
		searchsite = "http://www.google.com/search?q=";
	}
	if (TheForm.search_type[1].checked) {
		searchsite = "http://search.yahoo.com/search?p=";
	}
	if (TheForm.search_type[2].checked) {
		searchsite = "http://search.msn.com/results.aspx?q=";
	}
	if (TheForm.search_type[3].checked) {
		searchsite = "http://www.amazon.com/gp/search/002-1200532-9283251?search-alias=aps&keywords=";
	}
	if (TheForm.search_type[4].checked) {
		searchsite = "http://en.wikipedia.org/wiki/";
	}
	if (TheForm.search_type[5].checked) {
		searchsite = "http://www.answers.com/main/ntquery?s=";
	}
	if (TheForm.search_type[6].checked) {
		searchsite = "http://www.ask.com/web?q=";
	}
//	if (TheForm.search_type[7].checked) {
//		searchsite = "http://search.ebay.com//search/search.dll?from=R40&satitle=";
//	}

	var url = searchsite + q;
	
	window.open(url,'searchwindow')
}

function choose_radio(id) {
	TheForm = document.frm_top_search;

	TheForm.search_type[id].checked = true;
}

function fn_rollit() {
	thisMovie(flower).Play();
}

function fn_rollit_flower() {
	TheForm = document.frm_top_search;

	var cat_id = TheForm.cat_id.value;
	
	location = "rollit.php?cat_id=" + cat_id;
}

function fn_rollit_again() {
	TheForm = document.frm_top;

	var cat_id = TheForm.cat_id.value;
	
	var url = "rollitagain.php?cat_id=" + cat_id;

	window.open(url,'rollit_site');
}

function favorite(url)
{
	bookmarkurl=url
	bookmarktitle="Yambok - All you need, in just one click"
	if (document.all)
	window.external.AddFavorite(bookmarkurl,bookmarktitle)

	count_favorite();
}

function add_site()
{
	var TheForm = document.register;

	if (TheForm.title.value == '')
	{
		alert("אנא מלא את כותרת האתר");
		TheForm.title.focus();
		return;
	}
	if (TheForm.url.value == '' || TheForm.url.value == 'http://')
	{
		alert("אנא הזן את כתובת האתר");
		TheForm.url.focus();
		return;
	}
	if (!IsEmailValid(TheForm.email.value))
	{
		alert("אנא הזן כתובת דואר אלקטרוני");
		TheForm.email.focus()
		return;
	}
	if (TheForm.cat_id.value == '0')
	{
		alert("אנא בחר קטגוריה");
		TheForm.cat_id.focus();
		return;
	}
	if (!TheForm.agree.checked)
	{
		alert("עליך להסכים לתנאי השימוש");
		TheForm.agree.focus();
		return;
	}
	
	TheForm.action = "index.php?p=add&cmd=add";
	TheForm.submit();
}

function show_cat(div_id, show_id, hide_id, id, t) {
	//document.getElementById(div_id).style.display = 'block';
	document.getElementById(show_id).style.display = 'none';
	document.getElementById(hide_id).style.display = 'block';

	ajax.update(t+'_sub_cats.php?id='+id, div_id);

	Effect.BlindDown(div_id);
}


function show_cat_new_by_imagerow(div_id, show_id, hide_id, id, t) {
	//document.getElementById(div_id).style.display = 'block';
	document.getElementById(show_id).style.display = 'none';
	document.getElementById(hide_id).style.display = 'block';
	var file_see = t+'_sub_cats.php?id='+id;
	ajax.update(file_see, div_id);
	Effect.BlindDown(div_id);
}


function texual_show_cat(div_id, show_id, hide_id) {
	//document.getElementById(div_id).style.display = 'block';
	document.getElementById(show_id).style.display = 'none';
	document.getElementById(hide_id).style.display = 'block';

	Effect.BlindDown(div_id);
}

function hide_cat(div_id, show_id, hide_id) {
	//document.getElementById(div_id).style.display = 'none';	
	document.getElementById(show_id).style.display = 'block';	
	document.getElementById(hide_id).style.display = 'none';	

	Effect.BlindUp(div_id);
}

function update_link(id) {
	var url = 'update_link.php?id=' + id;
	window.open(url,'link');	
}

function count_homepage() {
	var url = "counter.php?cmd=homepage";
	loadXMLDoc(url);
}

function count_favorite() {
	var url = "counter.php?cmd=favorite";
	loadXMLDoc(url);
}

