﻿//AJAX section
function index_location(id,str,clm,tbl,parent_category)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="../../../include/admin_ajax_oper.php";
var params = "action=index_upd&id="+id+"&index="+str+"&clm="+clm+"&tbl="+tbl+"&super_clm="+parent_category;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}

//----------------------------------------------------------------------------------

function text_update(id,str,clm,tbl)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="../../../include/admin_ajax_oper.php";
var params = "action=q_name&id="+id+"&name="+str+"&clm="+clm+"&tbl="+tbl;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}

//----------------------------------------------------------------------------------

function update_symptom(id,status,session_id)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="../../../include/admin_ajax_oper.php";
var params = "action=symptom&id="+id+"&status="+status+"&session_id="+session_id;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChangeSymptom;
xmlHttp.send(params);
}

//----------------------------------------------------------------------------------

function checkbox_update(id,str,clm,tbl)
{alert(str);
var result;
if (str)	{result="1";}	else	{result="0";}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="../../../include/admin_ajax_oper.php";
var params = "action=q_name&id="+id+"&name="+result+"&clm="+clm+"&tbl="+tbl;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}

//----------------------------------------------------------------------------------

function stateChange() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//eval("document.getElementById('"+div_m+"').innerHTML='הנתון עודכן בשרת';");
		alert(xmlHttp.responseText);
		//alert('הנתון עודכן בהצלחה.');
		window.location.reload();
	}
}

//----------------------------------------------------------------------------------

function stateChangeSymptom() 
{ 
	if (xmlHttp.readyState==0)
	{ 
		//eval("document.getElementById('"+div_m+"').innerHTML='הנתון עודכן בשרת';");
		alert(xmlHttp.responseText);
		//alert('הנתון עודכן בהצלחה.');
	}
}

//----------------------------------------------------------------------------------

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

//-----------------------------------------------------------------------------------
//END of AJAX section

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}


/* Trim Function */
function trim(value)
 {
  var temp = value;
  return temp.replace(/^\s*(\b.*\b|)\s*$/, "$1");
 }
 
 
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


/* validLoginForm Function */
function validRegisterForm(form_id)
  {
   tmp="passForm=document.forms['"+form_id+"'];";
   eval(tmp);
   // Beginning of Regular Expressions Creating
   regular_hebrew=/^([^a-zA-Z0-9_]{1,})$/;
   regular_email_address=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   regular_english=/^([a-zA-Z0-9_]{1,})$/;
   regular_digits=/^([0-9]{1})$/;
  // End of Regular Expressions Creating

   // Beginning of E-mail Address Checking
  temp=trim(passForm.email.value);
  passForm.email.value=temp;
  
      if (!(regular_email_address.test(temp)))
         {
          alert("אנא רשמו כתובת E-mail תקינה.");
          passForm.email.focus();
          return false;
	  }
  // End of E-mail Address Checking
  
   // Beginning of Password Checking
   temp=trim(passForm.password.value);
   passForm.password.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את הסיסמה המבוקשת באותיות לועזיות ובספרות בלבד.");
	passForm.password.focus();
	return false;
      }
   // End of Password Checking

   // Beginning of First Name Address Checking
  temp=trim(passForm.f_name.value);
  passForm.f_name.value=temp;
  if (!(regular_hebrew.test(temp)))
         {
          alert("יש לציין שם פרטי.");
          passForm.f_name.focus();
          return false;
	  }

  // End of First Name Address Checking
  
   // Beginning of Last Name Address Checking
  temp=trim(passForm.l_name.value);
  passForm.l_name.value=temp;
  if (!(regular_hebrew.test(temp)))
         {
          alert("יש לציין שם משפחה.");
          passForm.l_name.focus();
          return false;
	  }
  // End of Last Name Address Checking

  // Beginning of Phone Number Checking
   temp=trim(passForm.phone_1.value);
   passForm.phone_1.value=temp;

   count_digits=0;
   for (i=0; i<=temp.length; i++)
	 {
	  if (regular_digits.test(temp.charAt(i)))
	     { count_digits++; }
	 }

   if (count_digits<9)
	{
	 alert("אנא רשמו את מספר הטלפון שלכם כולל קידומת ב-9 ספרות לפחות.");
	 passForm.phone_1.focus();
	 return false;
	}
   // End of Terms agreeemnet Checking
   
   // Beginning of Last Name Address Checking
  temp=passForm.terms.checked;
   if (!temp)
         {
          alert("יש להסכים לתנאי השימוש על מנת להרשם למערכת.");
          passForm.terms.focus();
          return false;
	  }
  // End of Terms agreeemnet Checking


   return true;
  }
