var uagent = navigator.userAgent.toLowerCase();
var isIE = (uagent.indexOf('msie') != -1) ? 1 : 0;
var isFF = (uagent.indexOf('firefox') != -1) ? 1 : 0;
var isMAC = (uagent.indexOf('applewebkit') != -1) ? 1 : 0;
var isCR = (uagent.indexOf('chrome') != -1) ? 1 : 0;

function my_getElementsByClassName(name)
{ 
	var findStack = [], allelm = (document.getElementsByTagName) ? document.getElementsByTagName("*") : document.all;

	for(var i = 0; i<allelm.length; i++)
	{
		if(allelm[i].className == name)
			findStack.push(allelm[i]);
	}
   
	return findStack;
}
		
function window_onload(func)
{
    var oldonload = window.onload; 
    if (typeof window.onload != 'function'){ 
        window.onload = func; 
    }else{ 
        window.onload = function(){        
            if (oldonload){ oldonload(); }             
            func(); 
        } 
    } 
}

function elm(oid)
{
	return (!oid) ? null : document.getElementById(oid);	
}
 
function popup(url, width, height, scroll, pos, name)
{
    if(pos=="fullscreen")
    {
        LeftPosition=0;
        TopPosition=0;
    
        if (isIE)
        {
            width = (screen.width-10);
            height= (screen.height-30);
        }
        else
        {
            width   = (screen.width-5);
            height  = (screen.height-30);
        }
    }    
	else if(pos=="center")
	{
		LeftPosition=(screen.width)?(screen.width-width)/2:100;
		TopPosition=(screen.height ? ((screen.height-height)/2) : 100 ) - 30;
	}
	else
	{
		LeftPosition=100;
		TopPosition=100;
	}
    
	scroll = (scroll == null) ? "no" : scroll;	
	
	var	name = (name != null) ? name : "popupwin";
	argvs='width='+width+',height='+height+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	window.open(url, name, argvs).focus();
}


function setall(oform, osource, odest)
{

	var oform = elm(oform);
	var svalue = elm(osource).value;
	var oinput = oform.getElementsByTagName('input');

	for (i=0;i<oinput.length;i++)
	{
		var regex = new RegExp(odest, 'i');
		var regex2 = new RegExp('site_add', 'i');
		
		if(regex2.test(oinput[i].getAttribute('name')))
		{
			status = (oinput[i].checked) ? true : false;
		}
		
		if(regex.test(oinput[i].getAttribute('name')) && (status == true) )
		{
			oinput[i].value = svalue;
			if(oinput[i].value != '')
			{
				oinput[i].className = 'text focus';
			}
		}
	}
}

function selectall(oform, oname)
{
	var oform = elm(oform);
	var oinput = oform.getElementsByTagName('input');
	for (i=0;i<oinput.length;i++)
	{
		var regex = new RegExp(oname, 'i');
		if(regex.test(oinput[i].getAttribute('name')))
		{
			if(oinput[i].checked == false)
			{
				oinput[i].checked = true;
			}
			else
			{
				oinput[i].checked = false;
			}
		}
	}
}

function checkboxlist(val, oid)
{
	if (val == elm(oid).value)
	{
		elm(oid).checked=true;
	}
}

function radiolist(val, fields)
{
	for (i=0;i<fields.length;i++)
	{
		if (val == fields[i].value)
		{
			fields[i].checked=true;
			
		}
	}
}

function selectlist(val, oid)
{
	var fields = document.getElementById(oid);
	for ( i = 0; i < fields.options.length; i++ )
	{
		if (val == fields.options[i].value)
		{
			fields.options[i].selected=true;
			/*break;*/
		}
	}
}

