//########### loginpage Validataion Strart
function lTrim(str){
    for (var i=0; str.charAt(i)==" "; i++);
        return str.substring(i,str.length);
}

function rTrim(str){
    for (var i=str.length-1; str.charAt(i)==" "; i--);
        return str.substring(0,i+1);
}

function trim(str){
    //var st=0;
	 st = lTrim(rTrim(str));
	 return st;
}
function emailValidate(fld) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = trim(fld);
    if(reg.test(address) == false) {
        return false;
    }
    return true;
}
/*
function emailValidate(emailStr) {
    alert("emailValidate"+emailStr);
    if(!emailStr){
        //alert('Enter your email ID to start playing');
		document.login.txtEmailid.focus();
        return false;
    }else{
        alert("inside else");
	if((!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailStr)))){
        alert("failure if");
        //alert('Enter your valid email ID to start playing');
		document.login.txtEmailid.focus();
        return false;
	  }else
          alert("success");
        return true;
	}
}
*/
function isEmpty(sValue) {
    if (!lTrim(sValue)) {
        return true;
    }
    return false;
}

function passwordValidate(passStr){
    if(!passStr){
        //alert("Password Cannot Be Empty");
		//document.login.txtPassword.focus();
        return false;
    }else{
        return true;
    }
}
function cpasswordValidate(npassStr,cpassStr){
    if (!npassStr) {
        alert("Password Cannot Be Empty");
		document.login.txtRpassword.focus();
        return false;
    }
    if (!cpassStr) {
        alert("Confirm Password Cannot Be Empty");
		document.login.txtConpassword.focus();
        return false;
    }
    if(npassStr && cpassStr){
        if(npassStr != cpassStr){
            alert("Password And confirm Password Should Be Same");
			document.login.txtConpassword.focus();
            return false;
        }else{
            return true;
        }
       
    }
}

function checkQuantity(){
	
	var qty =document.getElementById('txtStocqty').value;
    if (!isInteger(qty)) {
        alert("Please enetr the valid number");
		//document.login.txtFname.focus();
        return false;
    }else{
        return true;
    }
}
function fnameValidate(fName){
    if (!fName) {
        //alert("First Name Cannot Be Blank");
		//document.login.txtFname.focus();
        return false;
    }else{
        return true;
    }
}
function lnameValidate(lName){
    if (!lName) {
        //alert("Last Name Cannot Be Blank");
		//document.login.txtLname.focus();
        return false;
    }else{
        return true;
    }
}
//########### loginpage Validataion End

//########### Portfolio Validataion Strart
function inputValidate(pName){
	var reg =  /^([A-Za-z_\-\.\'\"\ ]([0-9])*)+$/;
	if(!isValideName(pName) || !isNaN(pName)){
		document.getElementById('porfolio_error').innerHTML="Portfolio Name Cannot Be Blank or Numeric are  not Allowed";
		document.getElementById('txtPortfolioname').focus();
		return false;
	} else if(pName.length > 25 || pName.length < 3) {
		document.getElementById('porfolio_error').innerHTML="Portfolio Name can not be Less Than 3 Characters and More Then 25 Characters";
		document.getElementById('txtPortfolioname').focus();
		return false;
	} else{
		return true;
	}
}
//########### Portfolio Validataion End

//########### Stock Validataion Strart
function inputStockValidate(pName){
	var flag=0;
	if(pName == '0') {
		document.getElementById('buy_first_error').innerHTML="Stock Name Cannot Be valid";
		document.getElementById('txtStockname').focus();
		document.getElementById("buy_first_error").style.display = 'block';
		document.getElementById("no_result").style.display = 'none';
		return false;
	} else if (!pName || pName =='' || !trim(pName))	{
		document.getElementById('buy_first_error').innerHTML = "&nbsp;&nbsp;&nbsp;Stock Name Cannot Be Blank";
		document.getElementById('txtStockname').focus();
		document.getElementById("buy_first_error").style.display = 'block';
		document.getElementById("no_result").style.display = 'none';
		document.getElementById("RETYPE").style.display = 'none';
		return false;

	}  else {
		return true;
	}
	
		/*if (!pName || pName ==''){
			if (!trim(pName)){
				document.getElementById('buy_first_error').innerHTML="Stock Name Cannot Be Blank";
				document.getElementById('txtStockname').focus();
				return false;
			}else{
				return true;
			}
		} else {
			flag=1;
		}
	} else {
		
	}
	*/
}
function inputStockValue(sQty){
	//var myMod = sQty % 1;
	if(isInteger(sQty)) {
		if (sQty==''){
			alert("Stock Quantity Cannot Be Blank");
			return false;
		}else if(sQty<=0 || sQty==0) {
			 alert("Enter the Valid Quantity");
			 return false;
		} else if (!isInteger(sQty)){
			//alert("StockQuantity Cannot Be String");
			alert("Enter the Valid Quantity");
			return false;
		}else{
			return true;
		}
	} 
}
//########### Stock Validataion End
//########### Watch List Validataion Strart
function inputWatchValidate(pName){
	if (!pName){
		//alert("Company Name Cannot Be Blank");
		document.getElementById('wachlist_error').innerHTML="Company Name Cannot Be Blank";
		document.getElementById('co_name').focus();
		return false;
		
	} else if(isDigit(pName)) {
		document.getElementById('wachlist_error').innerHTML="Company Name Cannot Be valid";
		document.getElementById('co_name').focus();
		return false;
	} else{
		return true;
	}
}
function inputWatchMaxValue(sQty){
	if (!sQty){
		document.getElementById('wachlist_error').innerHTML="StockMax Price Cannot Be Blank";
		document.getElementById('maxprice').focus();
		//alert("StockMax Price Cannot Be Blank");
		return false;
	}else if (isNaN(sQty)==true){
		document.getElementById('wachlist_error').innerHTML="StockMax Price Cannot Be String";
		document.getElementById('maxprice').focus();
		//alert("StockMax Price Cannot Be String");
		return false;
	}else{
		return true;
	}
}
function inputWatchMinValue(sQty){
	if (!sQty){
		document.getElementById('wachlist_error').innerHTML="StockMin Price Cannot Be Blank";
		document.getElementById('minprice').focus();
		//alert("StockMin Price Cannot Be Blank");
		return false;
	}else if (isNaN(sQty)==true){
		document.getElementById('wachlist_error').innerHTML="StockMin Price Cannot Be Blank";
		document.getElementById('minprice').focus();
		return false;
	}else{
		return true;
	}
}



 function isInteger (s)
   {
      var i;
      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);
		 if (!isDigit(c)) {
			  //alert("Enter the Valid Quantity");
			 return false;
		 }
      }
		
      return true;
   }

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

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }
	function winnervalidate (page) {
		var query=document.getElementById(page).value;
		if(query=='') {
			document.getElementById("winner_error").innerHTML = 'Please enter the rank no. or team name';
					document.getElementById("winner_error").style.display = 'block';
					//alert('Please enter the rank no. or team name');
					return false;
		} else if(isNaN(query)) {
				if(query.length >2){
				if(!document.getElementById(page).value ) {
					//here validate message for less string in pass 
					document.getElementById("winner_error").innerHTML = 'Please enter the rank no. or team name';
					document.getElementById("winner_error").style.display = 'block';
					//alert('Please enter the rank no. or team name');
					return false;
				}
				
			} else {
					document.getElementById("winner_error").innerHTML = 'Invalid search criteria';
					document.getElementById("winner_error").style.display = 'block';
					return false;
			}
		} else if (query <= 0){
            document.getElementById("winner_error").innerHTML = 'Invalid search criteria';
            document.getElementById("winner_error").style.display = 'block';
            return false;
        }
		return true;
	}

	function noValidation(sQty){
	//var myMod = sQty % 1;  
	if(isInteger(sQty)) {
		if(sQty==0) {
			document.getElementById("buy_sell_error").innerHTML = 'Please enter numerals only.';
			document.getElementById("buy_sell_error").style.display = 'block';
			 //alert("Enter the Valid Quantity");
			 return false;
		} 
	} else if(!sQty) {
			document.getElementById("buy_sell_error").innerHTML = 'Please enter numerals only.';
			document.getElementById("buy_sell_error").style.display = 'block';
			//alert("Stock Quantity Cannot Be Blank");
			return false;
	} else {
		document.getElementById("buy_sell_error").innerHTML = 'Please enter numerals only.';
		document.getElementById("buy_sell_error").style.display = 'block';
		//alert("Stock Quantity Cannot Be Blank");
		return false;
	}
	return true;
}

function isValideName(string) {
	var status=1;
	var iChars = "";
	if(!string) {
		status=0;
	}
	  for (var i = 0; i < string.length; i++) {
		  	if (iChars.indexOf(string.charAt(i)) != -1) 
			{			
				status=0;
				break;
			}
		 }
if(!status)  {
	return false;
} else {
	return true;
}

}
//########### Watch List Validataion End
