function get_file(from,to) 
{
	from.form.elements[to].value = from.value
}

function _id(id)
{
	return document.getElementById(id).value
}
function traveller()
{
	alert('vfdfgf');
}
function _set_value(id,value)
{
	document.getElementById(id).value = value	
}
function confirmation() {
	var answer = confirm("Are You sure to delete this user")
		if(answer == true )
		{
		//alert("i m in if!");
		//window.location ="{site_url}admin/admin_innkeeper";
		}
		else
		{
		//alert("Thanks for sticking around!");
		}
		return answer;
		
}
function _inner_html(id)
{
	return document.getElementById(id).innerHTML
}

function _set_inner_html(id,value)
{
	document.getElementById(id).innerHTML = value	
}

function _name_len(name)
{
	return document.getElementsByName(name).length
}

function _checked(id)
{
	return document.getElementById(id).checked
}

function _set_checked(id)
{
	document.getElementById(id).checked = 'checked';
}

function _unset_checked(id)
{
	document.getElementById(id).checked = '';
}

function popup(url, width, height, args)
{
    if (!width) {
        width = 600;
    }
    var screen_width = screen.width;
    if (width > (screen_width - 75)) {
        width = screen_width - 75;
    }

    if (!height) {
        height = 500;
    }
    var screen_width = screen.width;
    if (width > (screen_width - 75)) {
        width = screen_width - 75;
    }

    var now = new Date();
    var name = now.getTime();

    if (url.indexOf('?') == -1) {
        var glue = '?';
    } else {
        var glue = '&';
    }

    if (args != "") {
        url = url + glue + args + "&uniq=" + name;
    } else {
        url = url + glue + "uniq=" + name;
    }

    param = "toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height + ",left=0,top=0";
    win = window.open(url, name, param);
    if (!win) {
        alert("The image save window can not be opened. Perhaps you have set your browser to block popup windows?");
    } else {
        if (!eval("win.opener")) {
            win.opener = self;
        }
        win.focus();
    }
}

function insert_contacts()
{
	var cnt = _name_len('contacts');
	var user_contacts = '';

	if(cnt == 1)
	{
		if(document.contact.contacts.checked)
		{
			user_contacts += document.contact.contacts.value
		}
	}
	else if(cnt > 1)
	{
		for(var i=0;i<cnt;i++)
		{
			if(document.contact.contacts[i].checked)
			{
				user_contacts += document.contact.contacts[i].value+','
			}
		}
		user_contacts = user_contacts.substr(0,user_contacts.length-1)
	}
	if(user_contacts != '')
	{
		window.opener.document['compose']['to_user_id'].value = user_contacts
		parent.window.close();
	}
	else
	{
		alert('Please select contacts')
	}
}

function _to_upper(name)
{
	return document.write(name.toUpperCase());
}

function _to_lower(name)
{
	return document.write(name.toLowerCase());
}

function select_all(form_obj,field_name,field_all,field_id)
{
	var cnt = form_obj[field_name].length;
	var i=0;
	
	if(_checked(field_all))
	{
		if(cnt > 1)
		{
			for(i=0;i<cnt;i++)
			{
				_set_checked(field_id+i)
			}
		}
		else
		{
			_set_checked(field_id+i)
		}
	}
	else
	{
		if(cnt > 1)
		{
			for(var i=0;i<cnt;i++)
			{
				_unset_checked(field_id+i)
			}
		}
		else
		{
			_unset_checked(field_id+0)
		}
	}
}


function validate_messages_count(form_obj,field_name,field_all,field_id)
{
	var cnt = form_obj[field_name].length;
	if(cnt == undefined)
	{
		cnt = _name_len(form_obj.id);
	}
	var count = 0;
	var i=0;

	if(cnt == 1)
	{
		if(_checked(field_id+i))
			{
				count++;
			}
	}
	else if(cnt > 1)
	{
		for(i=0;i<cnt;i++)
		{
			if(_checked(field_id+i))
			{
				count++;
			}
		}
	}
	else
	{
		return false;
	}

	if(count > 0)
	{
		return confirm('Are you sure You want to delete these message(s)?');
	}
	else
	{
		alert('Please select message(s)')
		return false;
	}
}

function set_select_all(form_obj,field_name,field_all,field_id)
{
	var cnt = form_obj[field_name].length;
	
	if(cnt == undefined)
	{
		cnt = _name_len(form_obj.id);
	}
	var count = 0;
	var i=0;
	
	if(cnt == 1)
	{
		if(_checked(field_id+i))
		{
			_set_checked(field_all)
		}
		else
		{
			_unset_checked(field_all)
		}
	}
	else if(cnt > 1)
	{
		for(i=0;i<cnt;i++)
		{
			if(_checked(field_id+i))
			{
				count++;
			}
			if(cnt == count)
			{
				_set_checked(field_all)
			}
			else
			{
				_unset_checked(field_all)
			}
		}
		
		
	}
}

if (typeof jQuery != 'undefined') {  
    // jQuery is loaded  
    $(document).ready(function() {
	
	/* prashant - hide flash message on click itself */
	$('.flash_msg').click(function(){
		$('.flash_msg').hide('slow');	
	});
});
}

	

function numbersonly(e, decimal) 
{
	var key;
	var keychar;
	
	if (window.event) 
	{
	   key = window.event.keyCode;
	}
	else if (e) 
	{
	   key = e.which;
	}
	else 
	{
	   return true;
	}
	keychar = String.fromCharCode(key);
	
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) 
	{
	   return true;
	}
	else if ((("0123456789").indexOf(keychar) > -1)) 
	{
	   return true;
	}
	else if (decimal && (keychar == ".")) 
	{ 
	  return true;
	}
	else
	   return false;
}


function ativaOptionsDisabled(){
    var sels = document.getElementsByTagName('select');
    for(var i=0; i < sels.length; i++){
        sels[i].onchange= function(){ //pra se mudar pro desabilitado
            if(this.options[this.selectedIndex].disabled){
                if(this.options.length<=1){
                    this.selectedIndex = -1;
                }else if(this.selectedIndex < this.options.length - 1){
                    this.selectedIndex++;
                }else{
                    this.selectedIndex--;
                }
            }
        }
        if(sels[i].options[sels[i].selectedIndex].disabled){
            //se o selecionado atual é desabilitado chamo o onchange
            sels[i].onchange();
        }    
        for(var j=0; j < sels[i].options.length; j++){ //colocando o estilo
            if(sels[i].options[j].disabled){
                sels[i].options[j].style.color = '#CCC';
            }
        }
    }
}

if(navigator.appName == 'Microsoft Internet Explorer')
{
	window.attachEvent("onload", ativaOptionsDisabled)
}
