function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function ajax_connect(url,post_string,function_str)
{

	xmlHttp= new GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return false;
		}
		xmlHttp.onreadystatechange= function()
		{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{ 
				var result=xmlHttp.responseText;
                                
				eval("function_str(result)") ;

			}
					
		}
		
		
		xmlHttp.open("POST",url);
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8'); 
		xmlHttp.send(post_string);
}


function get_element(id)
{
	return document.getElementById(id);
}

 
function validate_text_field(id)
{
	
	if (get_element(id).value.length==0)
	{
		return false;
	}
	else
	{
		return get_element(id).value;
	}
	
}

function get_multiselect_values(id)
{
	var select_filed=get_element(id);
	var arSelected = new Array();
	alert (select_filed);
	 while (select_filed.selectedIndex != -1)
          {
              if (select_filed.selectedIndex != 0) arSelected.push(select_filed.options[select_filed.selectedIndex].value);
              select_filed.options[select_filed.selectedIndex].selected = false;
          }
	
	if (arSelected.length <= 0 )
	{
		return false;
	}
	else
	{
		return arSelected;
	}
	
}

function get_select_value(id)
{
  
	var select_filed=get_element(id);
    
	if (select_filed.selectedIndex <= 0) {
			
			return false;
	}
	else
	{
			return select_filed.options[select_filed.selectedIndex].value;
	}
	
}


function  get_mail(id)
{
	var mail = get_element(id).value;
	if (mail.length==0)
	{
		return false;
	}
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (mail.length==0 || !(filter.test(mail)) )
	{
		return false;
	}
	else
	{
		return mail;
	}
}

function get_checkboxes_value(id)
{
	var check_boxes=get_element(id);
	var c_value = new Array();
	for (var i=0; i < check_boxes.length; i++)
	{
		if (check_boxes[i].checked)
                 {
                    c_value.push(check_boxes[i].value);
                 }
        }
   
   if (c_value.length==0)
   {
		return false;
   }
   else
   {
	 return c_value;
   }

}
    


function hide_element(id)
{
	get_element(id).style.display="none";
}

function show_element(id)
{
	get_element(id).style.display='';
}

function show_div(id)
{
	get_element(id).style.visibility='visible';
}

function hide_div(id)
{
	get_element(id).style.visibility='hidden';
}



function empty_select(id)
{

	var select_object=get_element(id); 
	for (i=select_object.length; i >= 0;i--)
	{
		select_object.remove(select_object.options[i]);
	}
}

function insertOption(option_text,option_value,select_id)
{
	var select_option=document.createElement('option');
	select_option.text=option_text;
	select_option.value=option_value;
	var select_object=get_element(select_id);
		try
		  {
			select_object.add(select_option,null); // standards compliant
		  }
		catch(ex)
		  {
			select_object.add(select_option); // IE only
		  }
}

function get_fck_content(fck_name)
{
	var content= FCKeditorAPI.GetInstance(fck_name).GetHTML() ;
	return  content;
}

function dispaly_error(error_place_id,error_message,item_id)
{
	var error_container=get_element(error_place_id);

	
	error_container.style.display='';
	
	error_container.style.visibility='visible';
	error_container.innerHTML=error_message;
	if (item_id)
	{
		get_element(item_id).focus();
	}	
}

function check_ifNumber(id)
{
	if (get_element(id).value.length==0)
	{
		return false;
	}
	else if(isNaN(get_element(id).value))
	{
			return false;
	}
	else
	{
		return get_element(id).value;
	}
	
}

function get_check_boxes(name) {

boxes = document.getElementsByName(name);

boxes_num =boxes.length;
txt = ""

for (i = 0; i < boxes_num; i++) 
{

	if (boxes[i].checked) 
		{
			txt = txt + boxes[i].value + ":"
		}
}

txt=txt.substring(0,((txt.length)-1));
	return txt
}

function get_radio_values(name)
{
		radio = document.getElementsByName(name);

		radio_num =radio.length;
		txt = ""
		var x=0;
		for (i = 0; i < radio_num; i++) 
		{

			if (radio[i].checked) 
				{
					return   radio[i].value ;
					x=1;
				}
		}

		if (x==0)
		{
		return false;
		}

}

function resetEditors()
{
    // If the editor API does not exist, there are no editors
    if (typeof FCKeditorAPI == "undefined") return;

    // Loop through all FCK instances, in case there are several editors
    for (var sEditorName in FCKeditorAPI.__Instances)
    {
        // The initial value that was set when the form was created
        // is stored in a hidden <INPUT> with the same name as the
        // editor (the editor itself is in an <IFRAME> with ___Frame
        // appended to the name.  Check whether that INPUT exists
        if (document.getElementById(sEditorName))
        {
            // Get the initial value
            var sInitialValue = document.getElementById(sEditorName).value;

            // Overwrite the editor's current value
            FCKeditorAPI.__Instances[sEditorName].SetHTML(sInitialValue);
        }
    }
} 



function reset_element(id)
{
	if (get_element(id)!=null)
	{
		if (get_element(id).type=='checkbox' || get_element(id).type=='radio')
		{
			element = document.getElementsByName(id);

			element_num =element.length;
		
			for (i = 0; i < element_num; i++) 
			{
				element[i].checked=false;
			}

		}
		else
		{
				get_element(id).value="";
		}
	}
}

function set_upload_img(filed_name,img_name)
{
	window.opener.get_element(filed_name).value=img_name;
	setTimeout('window.close()',2000);
}


function format_post()
{
	var form_elements=document.forms[0].elements;
	
	for (var i=0 ; i < form_elements.length ; i++)
	{
	
		alert (document.forms[0].elements[i].name);
	}
}

function compare_date(from_date,to_data)
{   
    form_array=from_date.split("-");
    var from_formated_date=new Date(form_array[0],form_array[1],form_array[2]);
    
    to_array=to_data.split("-");
    var to_formated_date=new Date(to_array[0],to_array[1],to_array[2]);
    
    if (to_formated_date <= from_formated_date)
        {
          return false;
        }
        else
        {
            return true;
        }   
    
    
}


function reset_table_content(table_id)
{
    get_element(table_id).innerHTML="";
}

function set_table_content(table_content,table_id)
{
     get_element(table_id).innerHTML=table_content;
}

function changeClass (elementID, newClass) {
	var element = document.getElementById(elementID);
	
	element.setAttribute("class", newClass); //For Most Browsers
	element.setAttribute("className", newClass); //For IE; harmless to other browsers.
}


