
function addOption(selectId, txt, val, selected)
{
    var objOption = new Option(txt, val, selected);
//    var l = document.getElementById(selectId).options.lenght;
    document.getElementById(selectId).options.add(objOption);
    if(selected == true) {
//    	window.alert(txt+' '+document.getElementById(selectId).options.length);
    	document.getElementById(selectId).selectedIndex = (document.getElementById(selectId).options.length-1)
    }

}
function clearOption(selectId, txt, val)
{
//    var objOption = new Option(txt, val);
    document.getElementById(selectId).options.length = 0; //add(objOption);
}


function cnt_symbol(ta_id, counter_id, max_len) {
	elem = document.getElementById(counter_id);
		if(elem) {
			el2 = document.getElementById(ta_id);
			if(el2) {
				elem.value = el2.value.length;
				if(el2.value.length >= max_len) {
					el2.value =  el2.value.substr(0,max_len);
				}
			}
		}
}
                                                                                                                    
function openWindow(url,wnd, width , height)
{
		var feat = '';
		if( !width) {
			width = 200;
		}
		if( !height) {
			height = 100;
		}
		
		if(parseInt(height,10) > 0) {
			feat += 'height='+parseInt(height,10) +';';
		}
		feat += 'location=no;toolbar=no;status=no;resizable=yes;scrollbars=yes;';
		if(parseInt(width,10) > 0) {
			feat += 'width='+ parseInt(width,10) +';';
		}
//		window.alert(feat);
        wnd=this.open(url,wnd,feat);
        wnd.focus();
        return; 
}
function confirmUrl(url,msg)
{
		res=window.confirm(msg);
		if(res==true)
			document.location.href=url;
        return; 
}
function stripSpaces(str) {
    while (str.substring(0,1) == ' ') str = str.substring(1);
    while (str.substring(str.length-1,str.length) == ' ') str = str.substring(0,str.length-1);
    return str;
}
function isEmail(str) {
	var supported = 0;
	if (window.RegExp) 
	{	var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
} 
