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("אימייל לא תקין");
            aField.focus
            return false;
        }
    } 
    else if(checkType=='N') {
       if((isNaN(aField.value) )) {
            alert("מספר לא חוקי");
            aField.focus
            return false;
        }
    }

    else if(checkType=='PHONE') {
        //var regex = /[0-9]+\-[0-9]+/;
        var regex = /0[0-9][0-9]?\-[0-9]+/;
        if(!regex.test(aField.value)) {
            //alert("מספר טלפון לא חוקי יש להשתמש בקידומת,מינוס ומספר");
            aField.focus
            return false;
        } 
    }
    else if(checkType=='MOBILE') {
        //var regex = /[0-9]+\-[0-9]+/;
        var regex = /0[0-9][0-9]\-?[0-9]+/;
        if(!regex.test(aField.value)) {
            //alert("מספר סלולארי לא חוקי יש להשתמש בקידומת,מינוס ומספר");
            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 checkAll(form)
{
    var j;
 	for (j=0; document.forms[2].elements[j]!=null; j++)
		{
			if(document.forms[2].elements[j].type=="checkbox" )
			{
				document.forms[2].elements[j].checked=true;
			}
		}
	
}
function uncheckAll(form)
{
    var j;
	for (j=0; document.forms[2].elements[j]!=null; j++)
		{
			if(document.forms[2].elements[j].type=="checkbox" )
			{
				document.forms[2].elements[j].checked=false;
			}
		}
	
}

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;
	
}

function toggleDiv2(divid){
	var div=document.getElementById(divid);
	
	if (div.style.display=='block'){
		div.style.display='none';
	}
	else{
		div.style.display='block';
	}
}

function ajax_add_to_basket(asset_id,message)
{
    //alert(fields);                               
   var res;
        //alert();
	xmlFile = "xml_funcs.php?check_type=add_basket&asset_id="+asset_id  ;
    //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;
    document.getElementById('basket_count').innerHTML = res;
    
	}
    
    // end funaction
    if(res>'0') {
        alert(message); 
    }
}



function ajax_remove_from_basket(asset_id)
{
    //alert(fields);
   var res;
        //alert();
	xmlFile = "xml_funcs.php?check_type=remove_basket&asset_id="+asset_id  ;
    //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;
    document.getElementById('basket_count').innerHTML = res;
    
	}
    
    // end funaction
    if(res>'0') {
       alert("הנכס נמחק מן הסל"); 
    }
}
