if (document.all)

	var browser_ie=true

else if (document.layers)

	var browser_nn4=true

else if (document.layers || (!document.all && document.getElementById))

	var browser_nn6=true

    


    
    




function ValidateFields(checkType,aField) {
    if(checkType=='D') {
        var regex = /^(\d{2})\-(\d{2})\-(\d{4})$/;
        if(!regex.test(aField.value)) {
            alert("Not A Valid Date");
            aField.focus
            return false;
        }
    }
    else if(checkType=='EMAIL') {
       var regex =  /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,4}$/
        if(!regex.test(aField.value)) {
            alert("Not a Valid Email Address");
            aField.focus
            return false;
        }
    } 
    else if(checkType=='N') {
       if((isNaN(aField.value) )) {
            alert("Not A Valid Number");
            aField.focus
            return false;
        }
    }

    else if(checkType=='PHONE') {
        var regex = /[0-9]+\-[0-9]+/;
        if(!regex.test(aField.value)) {
            alert("Not A Valid Phone Number");
            aField.focus
            return false;
        } 
    }  
    
    else if(checkType=='TEXT') {
        var regex = /[a-zA-Z]*/;
        if(!regex.test(aField.value)) {
            alert("Not A Valid Name");
            aField.focus
            return false;
        }       
         
    } 
    return true; 
}  

function getFieldsValues(frm,fields) {
    var fieldsArray = new Array();
    var fieldsValues="";
    fieldsArray = fields.split("~");
    i=0;
    //alert(fieldsArray.length);
    while (i < fieldsArray.length ){
        
        frmValue = eval("frm."+fieldsArray[i]+".value");
        fieldsValues=fieldsValues+frmValue+"~";
        i++;
    }
    fieldsValues = fieldsValues.substring(0,fieldsValues.length-1);
    return fieldsValues;
    
}

function call_server(frm,module_id,fields,values,check_type,error_text)
{
    //alert(fields);
    var values = getFieldsValues(frm,fields);
   
    var res;
        //alert();
	xmlFile = "xml_funcs.php?module_id="+module_id+"&fields="+fields+"&values="+values+"&check_type="+check_type  ;
    //document.write (xmlFile);

	if (document.implementation && document.implementation.createDocument)
	{
        xmlDoc = document.implementation.createDocument("", "doc", null);
        xmlDoc.async = false;
		xmlDoc.onload = init;
		xmlDoc.load(xmlFile);
	}
	else if(window.ActiveXObject)
	{
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
        //alert(xmlDoc.load(xmlFile));
		if(xmlDoc.load(xmlFile))
			init();
	}
	else
	{
		alert("Error creating XMLDOM object, browser doesnt support that!");
		return false;
	}
        
   	
    function init()	    {
	res = xmlDoc.getElementsByTagName("ROOT").item(0).firstChild.nodeValue;
    
	}
    
    // end funaction
    if(res=='1') {
        alert(error_text); 
    }
}



//function fill_combo(frm,module_id,fields,values,check_type,error_text)
function fill_combo(frm,field_son,related_table_son,field_to_display,field_to_value,field_father,group_by,multi_tables,multi_tables_conditions,multi_tables_fields_ids,multi_tables_fields_display,father_db_name)
{
    var field_father_value = getFieldsValues(frm,field_father);
    var son = document.getElementById(field_son);
    var res;
    xmlFile = "xml_funcs.php?check_type=fillCombo&related="+related_table_son+"&field_sql="+field_father+"&field_val="+field_father_value+"&field_disp="+field_to_display+"&field_to_value="+field_to_value+"&group_by="+group_by+"&multi_tables="+multi_tables+"&multi_tables_conditions="+multi_tables_conditions+"&multi_tables_fields_ids="+multi_tables_fields_ids+"&multi_tables_fields_display="+multi_tables_fields_display+"&father_db_name="+father_db_name  ;
    //document.write(xmlFile);

	if (document.implementation && document.implementation.createDocument)
	{
        xmlDoc = document.implementation.createDocument("", "combo", null);
        xmlDoc.async = false;
		xmlDoc.onload = init;
		xmlDoc.load(xmlFile);
	}
	else if(window.ActiveXObject)
	{
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
        //alert(xmlDoc.load(xmlFile));
		if(xmlDoc.load(xmlFile))
			init();
	}
	else
	{
		alert("Error creating XMLDOM object, browser doesnt support that!");
		return false;
	}
        
   	
    function init() {
    res = xmlDoc.getElementsByTagName("COMBOITEM");
    }
    
    // end funaction
 
     for (m=son.options.length-1;m>0;m--) 
        son.options[m]=null; 
     for (i=0;i<res.length;i++)
          {
          $comboValue= res[i].getAttribute('itemvalue');
          $comboDisp = res[i].childNodes[0].nodeValue;
          son.options[i]=new Option($comboDisp,$comboValue);
          }
}



function getFullRelatedFieldsForReport(module_id,sub_module_id)
{
    var son   = document.getElementById('full_list_fields');
    //var elem1 = document.getElementById('criteria_field1');

    var res;
    xmlFile = "xml_funcs.php?check_type=getFullRelatedFields&module_id="+module_id+"&sub_module_id="+sub_module_id; 
    //document.write(xmlFile);

	if (document.implementation && document.implementation.createDocument)
	{
        xmlDoc = document.implementation.createDocument("", "combo", null);
        xmlDoc.async = false;
		xmlDoc.onload = init;
		xmlDoc.load(xmlFile);
	}
	else if(window.ActiveXObject)
	{
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
        //alert(xmlDoc.load(xmlFile));
		if(xmlDoc.load(xmlFile))
			init();
	}
	else
	{
		alert("Error creating XMLDOM object, browser doesnt support that!");
		return false;
	}
        
   	
    function init() {
    res = xmlDoc.getElementsByTagName("COMBOITEM");
    }
    
    // end funaction
    i=0;
    var optgroup = document.createElement('optgroup');
    optgroup.label = res[i].childNodes[0].nodeValue; 
    for (i=1;i<res.length;i++)
    {
          $comboValue= res[i].getAttribute('itemvalue');
          $comboDisp = res[i].childNodes[0].nodeValue;
          if($comboValue!=0) {
             opt = new Option($comboDisp,$comboValue);
             optgroup.appendChild(opt);
             son.appendChild(optgroup);
             //elem1.appendChild(optgroup);
             
          }
             
         else {
            var optgroup = document.createElement('optgroup');
            optgroup.label = res[i].childNodes[0].nodeValue; 
             opt = new Option($comboDisp,$comboValue);
             optgroup.appendChild(opt);
             son.appendChild(optgroup);
             //elem1.appendChild(optgroup);

        }
    }
}


function getRelatedModules(module_id)
{
    var son = document.getElementById('sub_module');

    var res;
    xmlFile = "xml_funcs.php?check_type=getRelatedModules&module_id="+module_id; 
    //document.write(xmlFile);

	if (document.implementation && document.implementation.createDocument)
	{
        xmlDoc = document.implementation.createDocument("", "combo", null);
        xmlDoc.async = false;
		xmlDoc.onload = init;
		xmlDoc.load(xmlFile);
	}
	else if(window.ActiveXObject)
	{
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
        //alert(xmlDoc.load(xmlFile));
		if(xmlDoc.load(xmlFile))
			init();
	}
	else
	{
		alert("Error creating XMLDOM object, browser doesnt support that!");
		return false;
	}
        
   	
    function init() {
    res = xmlDoc.getElementsByTagName("COMBOITEM");
    }
    
    // end funaction
 
    for (i=0;i<res.length;i++)
          {
          $comboValue= res[i].getAttribute('itemvalue');
          $comboDisp = res[i].childNodes[0].nodeValue;
          son.options[i]=new Option($comboDisp,$comboValue);
          }
}



function getElement(element_id)
{
	if(document.getElementById)
	{
		return window.document.getElementById(element_id);
	}
	else if (document.all)
	{
		return window.document.all[element_id];
	}
	else if (document.layers)
	{
		return window.document.layers[element_id];
	}
}





// cookies
// name - name of the cookie

// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function validate_alpha(input) {
s = input;
var allowedValues = "1234567890_abcdefghijklmnopqrstuvwxyz";
var i;
for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (allowedValues.indexOf(c)== -1)  {;return false;}
		}
return true;
}




function unLockFields()
{
	var i,j;
	i=0;
	j=0;
	for (i=0; document.forms[i]!=null; i++)
	{
		for (j=0; document.forms[i].elements[j]!=null; j++)
		{
			document.forms[i].elements[j].disabled = false;
			//alert(document.forms[i].elements[j].name);
		}
	}
}


function CleanPage()
{
	var elepointer,i,j;
	i=0;
	j=0;
	for (i=0; document.forms[i]!=null; i++)
	{
		for (j=0; document.forms[i].elements[j]!=null; j++)
		{
			if(document.forms[i].elements[j].type=="text" || document.forms[i].elements[j].type=="textarea")
			{
				CleanStr(document.forms[i].elements[j]);
				//alert(document.forms[i].elements[j].name);
			}
		}
	}
}
//////////////////
// *******************************************
function CleanStr(FldPointer)
{
	var d,StrLeng,e,FldStr;
	d=0;
	StrLeng=0;
	e='';
	buf='';
	FldStr=FldPointer.value;
	StrLeng=FldStr.length;
	for (d=0; d<StrLeng; d++)
	{
		e=FldStr.charAt(d);
		if(e=='"')
		{
			e="``";
		}
		else if(e=="'")
		{
			e="`";
		}
		buf=buf+e;
	 }
	 FldPointer.value=buf;
}
// initialize combo selected index
function InitCombo()
{
	var elepointer,i,j;
	i=0;
	j=0;
	for (i=0; document.forms[i]!=null; i++)
	{
		for (j=0; document.forms[i].elements[j]!=null; j++)
		{
			if(document.forms[i].elements[j].type=="select-one" || document.forms[i].elements[j].type=="select")
			{
				document.forms[i].elements[j].SelectedIndex=0;
				//alert(document.forms[i].elements[j].name);
			}
		}
	}
}


function pop(url,name,w,h,s){
	new_window=window.open(url,name,"statusbar=0,status=0,menubar=no,resizable=yes,scrollbars=yes,width="+w+",height="+h+",left=50,top=50");
	self.new_window.focus(); // for netscape
	new_window.focus() // for explorer
}


function fix_date(i_date){
var fixed_date = i_date ;
var year='',month='',day;
year = fixed_date.value.substring(6,10);
month = fixed_date.value.substring(3,5);
day = fixed_date.value.substring(0,2);
i_date.value = year + "-" + month + "-" + day;

}

function fix_date2(i_date){
var fixed_date=i_date;
var year='',month='',day;
day = fixed_date.value.substring(8,10);
month = fixed_date.value.substring(5,7);
year = fixed_date.value.substring(0,4);
i_date.value = year + "-" + month + "-" + day;

}

isOpen = 0
function folderOnClick(folder,pic)
{
	if(folder.style.display!="none")
	{
		folder.style.display="none";
		document.location.href='#fault_anchor_'+pic;
		isOpen = 0;
	}
	else
	{
		folder.style.display="";
		isOpen = 1;
	}
}


function get_date(i_field) {
var today_date = new Date();
var t_day=today_date.getDate(),t_month=today_date.getMonth()+1;
if(t_day<10){t_day="0"+t_day}
if(t_month<10){t_month="0"+t_month}
i_field.value = t_day+'-'+t_month+'-'+today_date.getYear();
}


function exit() {
document.location.href="index.html";
}

function RemoveParameter(str,param)
{
	var pre,post;

	pre=str.indexOf('&'+param+'=');

	if(pre < 0)
		return str;

	post=str.indexOf('&',pre+1);

	return str.substr(0,pre)+str.substr(post);
}

function SetDate(y,m,d,delta) {
if (delta=='') {delta=0;}

var d1=new Date();
var d2=new Date();

var delta_date=d2.getTime()+(delta*24*60*60*1000);
d2.setTime(delta_date);

d.value=d2.getDate();
m.value=d2.getMonth()+1;
y.value=d2.getYear();

}

var last_div;
function toggleDiv(divid){
	var div=document.getElementById(divid);
    if(document.getElementById(last_div))
	    document.getElementById(last_div).style.display='none';
	div.style.display='block';
    last_div = divid;
	
}

var last_p;
function toggleP(divid){
	var div=document.getElementById(divid);
    if(document.getElementById(last_p))
	    document.getElementById(last_p).className='';
	div.className='open';
    last_p = divid;
	
}


function toggleDiv2(divid){
	var div=document.getElementById(divid);
	
	if (div.style.display=='block'){
		div.style.display='none';
	}
	else{
		div.style.display='block';
	}
}

function toggleP22(divid){
	var div=document.getElementById(divid);
	
	if (div.className=='open'){
		div.className='';
	}
	else{
		div.className='open';
	}
	
}

function toggleP2(divid,buttonid){
	var div=document.getElementById(divid);
    var but=document.getElementById(buttonid);
    
	
	if (div.className=='open'){
		div.className='';
        but.innerHTML='תשובה';
	}
	else{
		div.className='open';
        but.innerHTML='סגור';
	}
	
}

function resize2image(winW,winH,wMod,hMod,fullscreen){

	if (fullscreen){
		endW = screen.availWidth;
		endH = screen.availHeight;
	} else {
		endW = document.images["prodImage"].width + 100;

		endH = document.images["prodImage"].height + 140;
	}
	Deside=0;
	if (Math.abs(winW-endW)> wMod)Deside += 1;
	if (Math.abs(winH-endH)> hMod)Deside += 1;
	
	while ( Deside > 0 )
		{

		if (winW < endW) winW += wMod;
		if (winH < endH) winH += hMod;
		if (winW > endW) winW -= wMod;
		if (winH > endH) winH -= hMod;
		wLeft = (screen.availWidth / 2) - (winW / 2);
		wTop  = (screen.availHeight / 2) - (winH / 2);

		ns4   = (document.layers);
		ie5   = (document.all && document.getElementById);
		ns6   = (!document.all && document.getElementById);
		br    = "";
		if (ns4)br = "NS";

		if (ie5 || ns6)br = "MS";
		if (br == "NS") {
	    	window.resizeTo(winW-10,winH-30);}
		if (br == "MS") {
			window.resizeTo(winW,winH);}
		window.moveTo(wLeft,wTop);
		 

		Deside=0;
		if (Math.abs(winW-endW)> wMod)Deside += 1;
		if (Math.abs(winH-endH)> hMod)Deside += 1;

			 
		};
}


function GetXmlHttpObject() {
    if(window.XMLHttpRequest)    { // code for IE7+, Firefox, Chrome, Opera, Safari
            return new XMLHttpRequest();
        }
        if(window.ActiveXObject) { // code for IE6, IE5
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
        //alert("No Ajax object");
        return null;
}


function processData() {
    if (xmlhttp.readyState==4)  {
        if(!xmlhttp.status==200)  {
            alert("Problem retrieving data:" + xmlhttp.status);       
        }
      	var xmlDoc=xmlhttp.responseXML;
        //alert(xmlDoc);
	    var ajax_id =xmlDoc.getElementsByTagName("ajax_id")[0].childNodes[0].nodeValue;
		switch (ajax_id){
		
			case "country_select":
			
              var types = xmlDoc.getElementsByTagName('category');
  			  var	travel_typeSel = document.getElementById('travel_type');
			//alert(types.length);		 
			  for (i=0;i<types.length;i++)
			  {
				  comboValue= types[i].getElementsByTagName("id").item(0).firstChild.nodeValue;
				  comboDisp = types[i].getElementsByTagName("name").item(0).firstChild.nodeValue;
				  travel_typeSel.options[i+1]=new Option(comboDisp,comboValue);
			  }
			  break;
			case "area_select":
			  var countries=xmlDoc.getElementsByTagName('country');
              var types =xmlDoc.getElementsByTagName('category');
  			  var	countrySel = document.getElementById('country');
  			  var	travel_typeSel = document.getElementById('travel_type');
			  for (i=0;i<types.length;i++)
			  {
				  comboValue= types[i].getElementsByTagName("id").item(0).firstChild.nodeValue;
				  comboDisp = types[i].getElementsByTagName("name").item(0).firstChild.nodeValue;
				  travel_typeSel.options[i+1]=new Option(comboDisp,comboValue);
			  }
			  for (i=0;i<countries.length;i++)
			  {
				  comboValue= countries[i].getElementsByTagName("id").item(0).firstChild.nodeValue;
				  comboDisp = countries[i].getElementsByTagName("name").item(0).firstChild.nodeValue;
				  countrySel.options[i+1]=new Option(comboDisp,comboValue);
			  }
			  break;
		}
    } 
}

function global_ajax(params)
{
    xmlhttp=null;
    xmlhttp=GetXmlHttpObject(); //initializations
   // alert(xmlhttp);

    var res;
   // xmlFile = "xml_funcs.php?check_type=complete";
    xmlFile = "ajax_func.php?"+params;
  // alert(xmlFile);
    if(xmlhttp==null)    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    else {
        xmlhttp.onreadystatechange=processData;    
        xmlhttp.open("GET",xmlFile,true);
        xmlhttp.send(null);
   }
 
}
