 function isBlank(str){
        var len = str.length
        var i
        for (i=0;i<len;++i){
                if (str.charAt(i) != " ") return false;
                }
        return true
        }

 function trim(inputString) {
    // Removes leading and trailing spaces from the passed string. Also removes
    // consecutive spaces and replaces it with one space. If something besides
    // a string is passed in (null, custom object, etc.) then return the input.
    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") { // Check for spaces at the beginning of the string
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length-1, retValue.length);
    while (ch == " ") { // Check for spaces at the end of the string
        retValue = retValue.substring(0, retValue.length-1);
        ch = retValue.substring(retValue.length-1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) {
        // Note that there are two spaces in the string -
        //look for multiple spaces within the string
        retValue = retValue.substring(0, retValue.indexOf("  ")) +
            retValue.substring(retValue.indexOf("  ")+1, retValue.length);
        // Again, there are two spaces in each of the strings
            }
    return retValue; // Return the trimmed string back to the user
}
function emailCheck(emailStr) {
                var emailPat=/^(.+)@(.+)$/
                var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
                var validChars="\[^\\s" + specialChars + "\]"
                var quotedUser="(\"[^\"]*\")"
                var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
                var atom=validChars + '+'
                var word="(" + atom + "|" + quotedUser + ")"
                var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
                var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
                var matchArray=emailStr.match(emailPat)
                if (matchArray==null) {
                                alert("Email address seems incorrect (check @ and .'s)")
                                return false
                }
                var user=matchArray[1]
                var domain=matchArray[2]
                

                if (user.match(userPat)==null) {
                    alert(" The username in the email doesn't seem to be valid")
                    return false
                }
                var IPArray=domain.match(ipDomainPat)
                if (IPArray!=null) {
                    // this is an IP address
                          for (var i=1;i<=4;i++) {
                            if (IPArray[i]>255) {
                                //alert(" Destination IP address is invalid ")
                                alert(" Please check the email address ")
                                return false
                            }
                    }
                    return true
                }
                

                // Domain is symbolic name
                var domainArray=domain.match(domainPat)
                if (domainArray==null) {
                        alert(" The domain name in the email address doesn't seem to be valid ")
                    return false
                }
                

                /* domain name seems valid, but now make sure that it ends in a
                   three-letter word (like com, edu, gov) or a two-letter word,
                   representing country (uk, nl), and that there's a hostname preceding 
                   the domain or country. */
                

                /* Now we need to break up the domain to get a count of how many atoms
                   it consists of. */
                var atomPat=new RegExp(atom,"g")
                var domArr=domain.match(atomPat)
                var len=domArr.length
                if (domArr[domArr.length-1].length<2 || 
                    domArr[domArr.length-1].length>3) {
                   // the address must end in a two letter or three letter word.
                   alert(" The email must end in a three-letter domain, or two letter country")
                   return false
                }
                

                // Make sure there's a host name preceding the domain.
                if (len<2) {
                   var errStr=" Email is missing a hostname!"
                   alert(errStr)
                   return false
		}
                return true;
	}

function setTicker(ticker){
	var tick = ticker;
	window.opener.document.getElementById('ticker').value = tick ;
	self.close();
}

function openLogin(url){
	var tp = (screen.height-450)/2;
	var lt = (screen.width-740)/2 +100;
	newwinG = window.open(url, 'newwinG', 'height=200,width=300,left='+lt+',top='+tp+',scrollbars=no,resizable=yes');		
}

function changePasswd() {
	newwindow=window.open('changePassword.php','changePass','height=420,width=400,scrollbars=0');
	newwindow.moveTo(80,50);
	if (window.focus) {newwindow.focus()}
	return false;		 
}

function openHLogin(url){
	//passing the parameter to the hidden iframe
		window.open("waitmessage.php", 'newwinG', 'height=200,width=300,left=200,top=300,scrollbars=no,resizable=yes');
		top.parent.hlogin.location.href=url;
}

function openTradingApplet1(openURL, appURL) {
	//newwindow=window.open("openApplet.php",'tradelogin','height=400,width=320,scrollbars=1');
	alert("i am here");
	newwindow=window.open(openURL,'tradelogin','height=10,width=10,scrollbars=0');
	if (window.focus) {top.parent.focus()};
	setTimeout("newwindow.location.href='"+appURL+"'",5000);
	if (window.focus) {newwindow.focus()};
}
