/*
fname   - form name
lname - select name
tname - textarea name
*/
function insertValue(fname,lname,tname) {
    var myText    = document.forms[fname].elements[tname];
    var myListBox = document.forms[fname].elements[lname];

	sVal = myListBox.options[myListBox.selectedIndex].value;

    //IE support
    if ( document.selection) {
            myText.focus();
            sel = document.selection.createRange();
            sel.text = sVal;
            //document.sqlform.insert.focus();
    }
    //MOZILLA/NETSCAPE support
    else if (myText.selectionStart || myText.selectionStart == "0") {
            var startPos  = myText.selectionStart;
            var endPos    = myText.selectionEnd;
            var str    = myText.value;

            myText.value = str.substring(0, startPos) + sVal + str.substring(endPos, str.length);
    } else {
            document.forms[fname].elements[tname].value += sVal;
    }

    return true;
}

function sure() {
    return confirm('Are you sure ?');
}

function openWin(url, name, width, height) {
  window.open(url, name, 'left=' + Math.ceil((screen.width - width)/2) + ',top=' + Math.ceil((screen.height - height)/2) + ',width=' + width + ',height=' + height + ',location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,channelmode=0,fullscreen=0');
  return false;
}

function openWin1(url, name, width, height) {
  window.open(url, name, 'left=' + Math.ceil((screen.width - width)/2) + ',top=' + Math.ceil((screen.height - height)/2) + ',width=' + width + ',height=' + height + ',location=1,toolbar=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,channelmode=0,fullscreen=0');
  return false;
}

function checkEmail(oFrm,f1,f2){
	if ( 'undefined' != typeof(oFrm.elements[f1]) && 'undefined' != typeof(oFrm.elements[f2])  ){
		if ( oFrm.elements[f1].value != oFrm.elements[f2].value ){
			alert('Fields `Email` and `Confirm Email` must coincide.');
			return false;
		}
	}
	return true;
}

function getSelectedId( sName ){
	var a = document.getElementsByName(sName);
	for(i=0;i<a.length;++i)
		if(a[i].checked) return a[i].value;
	return 0;
}

function sumbitLogin(oForm, url){
	var t = oForm.target;
	var a = oForm.action;

	oForm.target = 'loginwin';
	oForm.action = url;

	openWin(url, 'loginwin', 500, 300);
	oForm.submit();
	oForm.target = t;
	oForm.action = a;

	return false;
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=450,left = 490,top = 330');");
}