﻿// JScript File

function General_Function(HostName, CurrentUrl) {
    hostname1 = HostName;
    CurrentUrl = CurrentUrl.toLowerCase();
    hostname1 = HostName;
    //ChangeLargeImage(HostName, CurrentUrl); //for item detail page.
    if ((CurrentUrl.indexOf("propertysearchlist.aspx") >= 0) || (CurrentUrl.indexOf('customer/propertylist.aspx') >=0) || (CurrentUrl.indexOf('viewpublicproperty.aspx') >=0))
    {
        for (var i = 0; i < document.images.length; i++) {
            img = document.images[i];

            if (img.id.indexOf("imgPropertyPicture") >= 0) 
            {
                w = img.width;
                h = img.height;
//                if (img.src.indexOf(HostName) >= 0) 
//                {
//                    //img.src = "http://" + HostName + "/App_Themes/Default/Images/img-not-avail-small.jpg";
//                    //img.style.width = "45px";
//                }
//                else 
                if ((w <= 28) || (h <= 30)) 
                {
                    img.src = HostName + "/App_Themes/Default/Images/img-not-avail-small.jpg";
                }
                img.style.width = "200px";
                img.style.height = "150px";
            }
        }
    }
    else if (CurrentUrl.indexOf('propertydetail.aspx') >= 0)
    {
        for (var i = 0; i < document.images.length; i++) {
            img = document.images[i];
            if (img.id.indexOf("imgPropertyPicture") >= 0) 
            {
                w = img.width;
                h = img.height;
//                if (img.src.indexOf(HostName) >= 0) 
//                {
//                    //img.src = "http://" + HostName + "/App_Themes/Default/Images/img-not-avail-small.jpg";
//                    //img.style.width = "45px";
//                }
//                else 
                if ((w <= 28) || (h <= 30)) 
                {
                    img.src = HostName + "/App_Themes/Default/Images/img-not-avail-small.jpg";
                }
                img.style.width = "320px";
                img.style.height = "240px";
            }
        }
    }
    else if ((CurrentUrl.indexOf('propertyreqforcustomer.aspx') >= 0)  ||  (CurrentUrl.indexOf('propertyassociation.aspx')>=0))
    {
        for (var i = 0; i < document.images.length; i++) {
            img = document.images[i];

            if (img.id.indexOf("imgPropertyPicture") >= 0) 
            {
               
                w = img.width;
                h = img.height;
//                if (img.src.indexOf(HostName) >= 0) 
//                {
//                    //img.src = "http://" + HostName + "/App_Themes/Default/Images/img-not-avail-small.jpg";
//                    //img.style.width = "45px";
//                }
//                else 
                if ((w <= 28) || (h <= 30)) 
                {
                    img.src = HostName + "/App_Themes/Default/Images/img-not-avail-small.jpg";
                }
                img.style.width = "100px";
                img.style.height = "100px";
            }
        }
    }
}



function ChangeLargeImage(HostName, CurrentUrl) {
    CurrentUrl = CurrentUrl.toLowerCase();

    if (CurrentUrl.indexOf("viewdetails.aspx") >= 0) {

        var LargeImg = document.getElementById("ctl00_ContentPlaceHolder1_imgLargePhoto");

        if (LargeImg) {
            w = LargeImg.width;
            h = LargeImg.height;

            if (LargeImg.src == "") {
                LargeImg.src = "http://" + HostName + "/App_Themes/Default/Images/img-not-available-big.jpg";
            }

            if (w > 205) {
                LargeImg.style.width = "205px";
            }
            if (h > 303) {
                LargeImg.style.height = "303px";
            }
        }
    }
}


//Function to check the Max value of the multiline Textbox
function CheckMaxLength(e, txt,max) 
{   
    var e = e || window.event;
     if (txt.value.length >= max && e.keyCode != 8)
     {
       txt.value = txt.value.slice(0,max);
       return false;
       }
       else
       {
       return true;
       }
}

        function AllowDecimal(strElement,Length,DigitAfterDecimal,event)
        {        
          var DigitBeforeDecimal = parseInt(Length) - parseInt(DigitAfterDecimal) ;
                
                 // First element cannot be '.'
                        if(strElement.value  =='' )
                        {
                             if(event.keyCode >= 48 && event.keyCode <= 57)
                             {
                               window.event.returnValue = true;
                               return true;
                             }
                             else
                             {
                             window.event.returnValue = false;
                             return false;
                             }
                        }
                               
                    else
                    {
                      //if total length of text box equals length parameter + 1
                        if(strElement.value.length == Length + 1)
                        {
                         window.event.returnValue = false;
                         return false;
                        }
                         else
                         {
                          // if '.' is pressed
                             if(event.keyCode == 46)
                              {
                               // if there is already one '.'
                               if(strElement.value.indexOf('.') >= 0)
                                {
                                 window.event.returnValue = false;
                                 return false;
                                }
                                else
                                {
                                    window.event.returnValue = true;
                                    return true;
                                }
                               } 
                             
                             
                            if(event.keyCode >= 48 && event.keyCode <= 57)
                              {
                                //if  '.' is already entered..
                                  if(strElement.value.indexOf('.') >= 0)
                                   {
                                     //if digits after '.' are equal to  DigitAfterDecimal parameter...
                                       if(strElement.value.length == (strElement.value.indexOf('.')+ 1 + DigitAfterDecimal))
                                        {
                                          window.event.returnValue = false;
                                          return false;
                                        }
                                        else
                                        {
                                        window.event.returnValue = true;
                                        return true;
                                        }
                                   
                                   }
                                 //if textbox contais digits and not '.', and length of digits has reached to DigitBeforeDecimal parameter
                                 if(strElement.value.length == DigitBeforeDecimal && strElement.value.indexOf('.') < 0 )
                                   {
                                    window.event.returnValue = false;
                                    return false;
                                   } 
                                   else
                                   {
                                  window.event.returnValue = true;
                                  return true;
                                  }
                               }
                              else
                              {
                               window.event.returnValue = false;
                               return false;
                              }
                         }
                   }
        }
        
        

//Function to check the Decimal value of 
function isDecimal(ctl,max,decPoint)
{
    var str = "^\\d{0," + max + "}(\\.\\d{0," + decPoint + "})?$";
    var re=new RegExp(str);
    if(!(re.test(ctl.value)))
    {   
        //negative + positive value validation
        //return /^[-+]?\d{3,5}(\.\d{1,3})?$/.test(str);        
        ctl.value="";
        //alert("not match");
    }    
}

function isInt(ctrl,max)
{
    //var str="^([0-9]*|\d*\d{1}?\d*)$";
     var str = "^\\d{0," + max + "}?$";
    var re=new RegExp(str);
    if(!(re.test(ctrl.value)))
    {
       ctrl.value="";    
    }
}

function dollarAmount(form, field) 
{ // idea by Vinod Satapara   

    Num = "" + eval("document." + form + "." + field + ".value");
    dec = Num.indexOf(".");
    var decValue = Num.substring(0, dec);
    end = ((dec > -1) ? "" + Num.substring(dec,Num.length) : ".00");
    if(Num!='')
    {   

    Num = "" + Num.replace('$','').replace(',','');
    Num="" + parseInt(trimNumber(Num));
    var temp1 = "";
    var temp2 = "";
 
   
        if (end.length == 2) end += "0";
        if (end.length == 1) end += "00";
        if (end == "") end += ".00";

        var count = 0;
        for (var k = Num.length-1; k >= 0; k--) {
        var oneChar = Num.charAt(k);
        if (count == 3) {
        temp1 += ",";
        temp1 += oneChar;
        count = 1;
        continue;
    }
    else 
    {
        temp1 += oneChar;
        count ++;
    }
    }
    for (var k = temp1.length-1; k >= 0; k--) 
    {
        var oneChar = temp1.charAt(k);
        temp2 += oneChar;
    }
    
    if(!isNaN(parseInt(temp2)))
    {
    temp2 = "$" + temp2 + end;
    }
    else
    {    
    temp2 = "$0" + end;
    }
    eval("document." + form + "." + field + ".value = '" + temp2 + "';");
      
     } 
     }
     
function trimNumber(s)
{
  while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
  return s;
}

function MaskNumber(strElement, Length, evt) {

           var KeyID = evt.which ? evt.which : evt.keyCode;
           //alert(KeyID)
           if (!(KeyID == 9 || KeyID == 44 || KeyID == 8  || (KeyID >= 48 && KeyID <= 57))) return false;
           if (strElement.value.length == Length + 1) { if (KeyID == 35 || KeyID == 36 || KeyID == 37 || KeyID == 39 || KeyID == 9 || KeyID == 44 || KeyID == 8) return true; else return false; }
           if (strElement.value.length >= 14) return false;
           
       }