﻿// JScript File
function validateAmort(valuetocheck){
var validChars = /^-?\d+(\.\d+)?$/; 
    if(valuetocheck < 1){
        return false;
    }
    else{
        if (valuetocheck.search(validChars)==-1)       
            return false;
        else
        return true;
    }
}
//area code
function ValidateAreaCode(valuetocheck){
var validChars = /^[0-9]{2,2}$/; 
    if(valuetocheck < 1){
        return false;
    }
    else{
        if (valuetocheck.search(validChars)==-1)       
            return false;
        else
        return true;
    }
}
function ValidateIPLSSearch()
{
    var re5digit=/^\d{6}$/;
    if ((document.getElementById("SearchProps1_txtIPLSNo").value).search(re5digit)==-1)
    {
            alert("Enter 6 digit IPLS (Indiaproperties Listing Service) number");
            return false;
    }
    else
    {
            return true;
    }
}
function ValidateIPLS(valuetocheck)
{
    var re5digit=/^\d{6}$/;
    if (valuetocheck.search(re5digit)==-1)
  return false;
else
    return true;
}
//Add to favorites function on home pages bottom
function CreateBookmarkLink() 
{
title = document.title;
url = window.location.href;

if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
} else if( window.external ) { // IE Favorite
window.external.AddFavorite( url, title); }
else if(window.opera && window.print) { // Opera Hotlist
return true; }
}
//email
function ValidateEmailAddress(valuetocheck){
var re5digit=/^([a-zA-Z0-9][a-zA-Z0-9_]*(\.{0,1})?[a-zA-Z0-9\-_]+)*(\.{0,1})([a-zA-Z0-9\-_])*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|([a-zA-Z0-9\-]+(\.([a-zA-Z]{2,10}))(\.([a-zA-Z]{2,10}))?(\.([a-zA-Z]{2,10}))?))[\s]*$/;
if ((valuetocheck).search(re5digit)==-1)
    return false;
else
    return true; 
}
function ValidateEmail(valuetocheck)
{
    var re5digit=/^([a-zA-Z0-9][a-zA-Z0-9_]*(\.{0,1})?[a-zA-Z0-9\-_]+)*(\.{0,1})@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|([a-zA-Z0-9\-]+(\.([a-zA-Z]{2,10}))(\.([a-zA-Z]{2,10}))?(\.([a-zA-Z]{2,10}))?))[\s]*$/;
    //var re5digit=/^([a-zA-Z0-9][a-zA-Z0-9_]*(\.{0,1})?[a-zA-Z0-9\-_]*)*(\.{0,1})@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|([a-zA-Z0-9\-]+(\.([a-zA-Z]{2,10}))(\.([a-zA-Z]{2,10}))?(\.([a-zA-Z]{2,10}))?))[\s]*$/;
    if ((valuetocheck).search(re5digit)==-1)
        return false;
        
    valuetocheck=valuetocheck.toLowerCase();        
    if((valuetocheck.indexOf("99acres")!= -1)||(valuetocheck.indexOf("indiaproperty")!= -1)||(valuetocheck.indexOf("magicbricks")!= -1)||(valuetocheck.indexOf("makaan")!= -1)||(valuetocheck.indexOf("propertywala")!= -1))
        return false;
    else
        return true; 
}

//phone
function ValidatePhone(valuetocheck)
{
 var validChars = /^([0-9]{8,12})$/;
   if(valuetocheck < 1)
   {
       return false;
	}
    else{
	  if (valuetocheck.search(validChars)==-1)
	    return false;    
	else
        return true;
    }
}

//mobile
function ValidateMobile(areacodetocheck,valuetocheck){
var validMobileChars = /^[1-9]{1}[0-9]{9}$/; 
var validAreaCodeChars = /^[0-9]{2}$/; 
if ((valuetocheck.search(validMobileChars)==-1) || (areacodetocheck.search(validAreaCodeChars) == -1)) 
    return false;
else
    return true;
}
//pin
function ValidatePin(valuetocheck){
var validChars = /^[0-9]{5,6}$/; 
    if(valuetocheck < 1){
        return false;
    }
    else{
        if (valuetocheck.search(validChars)==-1)       
            return false;
        else
        return true;
    }
}
//description 
function ValidateDescription(valuetocheck){
var validChars = /^[a-zA-Z0-9_.,;:\-&\? \s \(\)\[\]\{\}'"\/]+$/; 
if (valuetocheck.search(validChars)==-1)       
  return false;
else
    return true;
}
//name
function ValidateName(valuetocheck){
var validChars = /^[a-zA-Z\-'.\s]+$/; 
if (valuetocheck.search(validChars)==-1)
  return false;
else
    return true;
}
//URL
function ValidateURL(valuetocheck){
var validChars = /^(HTTPS:|https:|HTTP:|http:)\/\/+([\w-]+\.)+[\w-]+(\/[\w- .\/?%&amp;=+~#]*)?$/;
if (valuetocheck.search(validChars)==-1)
  return false;
else
    return true;
}
//only chars
function OnlyChars(valuetocheck){
var validChars = /^[a-zA-Z\s]+$/;
if (valuetocheck.search(validChars)==-1)      
  return false;
else
    return true;
}


//Number
function OnlyNumbers(valuetocheck){
var validNumbers = /(^-?\d\d*$)/;
if (valuetocheck.search(validNumbers)==-1)
    return false;    
else{
    if(parseInt(valuetocheck)>0)
        return true;
    else
        return false;
    }
}

function ValidateBedrooms(controltocheck)
{    
    var field = document.getElementById(controltocheck);
    var valuetocheck = field.value; 
    if(isNaN(valuetocheck))        
        return false;
    else{        
        valuetocheck = parseFloat(valuetocheck); 
        field.value = valuetocheck;
        if(valuetocheck <= 0 || valuetocheck > 99) {       
            return false; 
        }       
        else
        {
            var decimaltochk = /^[0-9]{0,2}(\.[0,5])?$/;
            valuetocheck = valuetocheck +'';        
            if ((valuetocheck).search(decimaltochk)==-1)
                return false;
            else
                return true; 
        }
    }
}
function ValidateAreaP(controltocheck)
{    
    var field = document.getElementById(controltocheck);
    var valuetocheck = field.value; 
    if(isNaN(valuetocheck))        
        return false;
    else{        
        valuetocheck = parseFloat(valuetocheck); 
        field.value = valuetocheck;
        if(valuetocheck <= 0 || valuetocheck > 225) {       
            return false; 
        }       
        else
        {
            var decimaltochk = /^[0-9]{0,2}(\.[0-9]{1,2})?$/;
            valuetocheck = valuetocheck +'';        
            if ((valuetocheck).search(decimaltochk)==-1)
                return false;
            else
                return true; 
        }
    }
}
//Password
function ValidateText(valuetocheck){
var validChars = /^[a-zA-Z0-9]{5,20}$/; 
if (valuetocheck.search(validChars)==-1)       
  return false;
else
    return true;
}

//PANNumber 
function ValidatePan(valuetocheck){
var validChars = /^[a-zA-Z0-9]{10}$/; 
if (valuetocheck.search(validChars)==-1)       
  return false;
else
    return true;
}

//Compare Date

function CompareDates(daycontrol,monthcontrol,yearcontrol,fieldname)
{
   var dt = new Date();
   var dd = document.getElementById(daycontrol);
   var mm = document.getElementById(monthcontrol);
   var yyyy = document.getElementById(yearcontrol);
   var dt = new Date();
   var dt1 = new Date(parseInt(yyyy.value),parseInt(mm.value-1),parseInt(dd.value));      
    var ourdate = new Date(dd.value+"/"+mm.value+"/"+yyyy.value);
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    var Cdate = new Date(month + "/" + day + "/" + year);    
      if(dt1 < Cdate){
        alert(fieldname + " should be greater than today's date");
        return false;
       }
      else
      {
        return true;
      }
   
}

function daysInFebruary (year){
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {		
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
		if (i==1 || i==3 || i==5 || i==7 || i==8 || i==10  || i==12) {this[i] = 31;}
   } 
   return this;
}
function isDate(month,day,year,fieldname){
	var daysInMonth = DaysArray(12)	
	if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false;
	}
return true;
}
function isDateBlank(daycontrol,monthcontrol,yearcontrol,fieldname)
    {
        var dd = document.getElementById(daycontrol);
        var mm = document.getElementById(monthcontrol);
        var yyyy = document.getElementById(yearcontrol);
        if(mm.value==0 && dd.value==0 && yyyy.value==0){           
           return false;
        }
        else
            return true
    }
function ValidateDate(daycontrol,monthcontrol,yearcontrol,fieldname)
{
    var dd = document.getElementById(daycontrol);
    var mm = document.getElementById(monthcontrol);
    var yyyy = document.getElementById(yearcontrol);
    if(mm.value!=0 && dd.value!=0 && yyyy.value!=0) {
    if (isDate(mm.value,dd.value,yyyy.value,fieldname)==false)	        
    	    return false;
        else    
            return true;
    }
    else
        return false;
}

//trim 
function trimstring(strtotrim) {
strtotrim = strtotrim.replace(/^\s+/, '');
strtotrim = strtotrim.replace(/\s+$/, '');
return strtotrim;
}

function trimdata(controltocheck){
var field = document.getElementById(controltocheck);
field.value = trimstring(field.value); 
}
  
//chk blank and action  
function isBlank(controltocheck){
var field = document.getElementById(controltocheck);
field.value = trimstring(field.value); 
if(field.value == ""){   
    field.value = "";
    field.focus();  
    return false;   
}
else
    return true; 
}
function isDropdownSelected(controltocheck)
{
    var field = document.getElementById(controltocheck);
    var valuetocheck = field.value;
    valuetocheck = trimstring(valuetocheck);
    if(valuetocheck == "" || valuetocheck == "0"){
        field.focus();
        return false;
    }
    else
        return true;
}
function isDropdownSelectedNull(controltocheck)
{
    var field = document.getElementById(controltocheck);
    var valuetocheck = field.value;
    valuetocheck = trimstring(valuetocheck);
    if(valuetocheck == ""){
        field.focus();
        return false;
    }
    else
        return true;
}
//character count for text area
function UpdateTextAreaCounter(opt_countedTextBox, opt_countBody, opt_maxSize) {
    var maxSize = opt_maxSize ? opt_maxSize : 500;
    var field = document.getElementById(opt_countedTextBox);
    if (field && field.value.length >= maxSize) {
            field.value = field.value.substring(0, maxSize);
    }
    var txtField = document.getElementById(opt_countBody);
            if (txtField) { 
            txtField.innerHTML = opt_maxSize - field.value.length;
    }
}

function ShowAnimation(bottom, top, ignoreSize, popuptype) {
var location = Sys.UI.DomElement.getLocation(bottom);
top.style.position = 'absolute';
var yloc = location.y;
if(popuptype == 'login')
{
    if(yloc <=120) 
        yloc = yloc + (144-yloc);               
    top.style.top = (yloc) + 'px';
    top.style.left = (location.x -140)+ 'px';
}
if(popuptype == 'advertise')
{
    if(yloc <=458) 
        yloc = yloc + (458-yloc);        
    top.style.top = (yloc) + 'px';
    top.style.left = (location.x + 12)+ 'px';
}
if(popuptype == 'homeloan')
{
       
    if(yloc <=120) 
        yloc = yloc + (120 + yloc);        
    top.style.top = (location.y -440) + 'px';
    top.style.left = (location.x + 10)+ 'px';
}
if (!ignoreSize) {
    top.style.height = bottom.offsetHeight + 'px';
    top.style.width = bottom.offsetWidth + 'px';
}

} 
//Alpha Numeric

function ValidateAlphaNum(valuetocheck){
var validChars = /^[a-zA-Z0-9]+$/;
if (valuetocheck.search(validChars)==-1)
  return false;
else
    return true;
}
function ValidateTerms(valuetocheck){
var validChars = /^[a-zA-Z0-9_.,;:@$%*&\-&\? \s \(\)\[\]\{\}'"\/]+$/; 
if (valuetocheck.search(validChars)==-1)       
  return false;
else
    return true;
}


//DecimalNumber
function decimalvalue(valuetocheck){

var validNumbers1 =/^(?:\d+\.?)|(?:\d\.\d+)$/ ;

if (valuetocheck.search(validNumbers1)==-1)
    return false;    
else{
    if(parseInt(valuetocheck)>0)
        return true;
    else
        return false;
    }
}
//Added by Anagha (30 Mar 2011)
//Date should NOT be greater than today's date. Used in > login\pms\InventoryCheckList.aspx
function CompareWithToday(daycontrol,monthcontrol,yearcontrol)
{
    var dd = document.getElementById(daycontrol);
    var mm = document.getElementById(monthcontrol);
    var yyyy = document.getElementById(yearcontrol);
    var dt1 = new Date(parseInt(yyyy.value),parseInt(mm.value-1),parseInt(dd.value));      
    
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    var Cdate = new Date(month + "/" + day + "/" + year); 
    
    if(dt1 > Cdate)
        return false;
    else
        return true;
}
