var reWhitespace = /^\s+$/

// BOI, followed by one or more digits, followed by EOI.
var reInteger = /^\d+$/
var ktInt = /^(([\+\-]\d+(\.\d*)?)|((\+\|\-)?(\d*\.)?\d+))$/


function openPopup(popupName, url, options) {
  // var options = 'resizable=1,menubar=1,toolbar=1,location=1,status=1,directories=1,width=800,height=400 ';
  if (url != '') {
    var newwin;
    newwin = window.open(url, popupName ,options);
    newwin.focus();
  }
}

function ObjVisible (f) {

	if (document.layers) {
		document.layers['f'].visibility='hidden';
	} else {
		f.visibility='hidden';
		alert (f.visibility);
	}	

}

function extendBody() {

}


function changeImg (f,f1,imgpath,strdida,normalpath) {


	myImage = new Image();
    myImage.src = imgpath;
	f.src = myImage.src;
	f.alt = strdida;
	f1.value= normalpath;
}

function isEmpty(s)
{
    return ((s == null) || (s.length == 0))
}

function isWhitespace (s)

{   // Is s empty?
    return (isEmpty(s) || reWhitespace.test(s));
}

function isKtInteger (s)

{   var i;
    f = ktInt.test(s)

    return f
}

function trim(s)
{
var idx1;
var idx2;

    for(idx1=0;idx1<s.length;idx1++)
        if(s.charAt(idx1)!=' ')
            break;

    for(idx2=s.length-1;idx2>0;idx2--){
        if(s.charAt(idx2)!=' ')
            break;
    }

    if(idx2<idx1) return "";
    else if (idx1==idx2)
        if (s.charAt(idx1) == ' ') return "";
        else return (s.charAt(idx1)+"");
    else return s.substring(idx1,idx2+1);
}

function submitFormRegUser(f) {
    totElement = f.elements.length;
    ris=0;
	var flagInt=0;
    var p;
    for (i=0;i < totElement;i++) {
        flagMand=0;
        flagInt=0;
        field=f.elements[i];
		fieldName = field.name;


        if (field.type=='text' || field.type=='file' ) {
            p = eval('f.'+fieldName+'_NUM')
            if (p) {
                if (p.value==1) {
                    flagInt=1;
                }
            }
            p = eval('f.'+fieldName+'_EMAIL')
            if (p) {
                if (p.value==1) {
                    flagInt=2;
                }
            }
            flagMand = eval('f.'+fieldName+'_FMAND.value')
            value = trim(field.value)
        }else if (field.type=='select-one') {
            flagMand = eval('f.'+fieldName+'_FMAND.value')
            value = trim(field.options[field.selectedIndex].value)
        }


        if (flagInt==2 && value!='') {
            if (VerifyEMail(field)==false) {
                index=i;
                i=totElement+1;
                ris=3;
            }
        }

        if (flagInt==1 && value!='') {
            if (isKtInteger(value)==false) {
                index=i;
                i=totElement+1;
                ris=2;
            }
        }

        if (flagMand==1) {
            if (isWhitespace(value)) {
                index=i;
                i=totElement+1;
                ris=1;
            }
        }
    }
    if (ris==0) {
        f.submit();
        return 1
    }else if(ris==2){
        predsc=f.PRE_MSGNUM.value
        postdsc=f.POST_MSGNUM.value
        dsc= eval('f.'+fieldName+'_DSC.value')
        alert (predsc + dsc + postdsc);
        f.elements[index].focus()
    }else if(ris==3){
        predsc=f.PRE_MSGEMAIL.value
        postdsc=f.POST_MSGEMAIL.value
        dsc= eval('f.'+fieldName+'_DSC.value')
        alert (predsc + dsc + postdsc);
        f.elements[index].focus()
    }else{
        predsc=f.PRE_MSG.value
        postdsc=f.POST_MSG.value
        dsc= eval('f.'+fieldName+'_DSC.value')
        alert (predsc + dsc + postdsc);
        f.elements[index].focus()
    }
}



function VerifyEMail(f) {
    var reEmail = /^.+\@.+\..+$/
    return reEmail.test(f.value)
}

function none() {

}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openPopUpPage2(str,ppname, stile) {
     myStr=str;
     myPPName=ppname;
     myStyle=stile;
     // if (popUpPage != 'VOID' ) popUpPage.close();
     popUpPage = window.open(str, ppname,stile);
     popUpPage.focus();
}
