﻿// JScript File

function validateEmpty()
{
    var i;
    var a = validateEmpty.arguments; 
    var exists = false;
    for(i=1;i<a.length;i++)
    {
        if (a[i].value != '')
        {
            exists = true;
        }
    }
    if (exists == true)
    {
        return true;
    }
    else
    {
        alert(a[0]);
        return false;
    }
}

function SwapInImage()
{
    var inImg = SwapInImage.arguments; 
    inImg[0].src = inImg[1];
}

function SwapOutImage()
{
    var outImg = SwapOutImage.arguments; 
    outImg[0].src = outImg[1];
}
function checkVar(str)
{
    if(str.id == "ctl00_cph_Main_txtBrouchureDesc")
    {
        document.getElementById("ctl00_cph_Main_st1").innerText = 15 - str.value.length;
    }
    else
    {
        document.getElementById("ctl00_cph_Main_sp2").innerText = 15 - str.value.length;
    }
    if(str.value.length == 15)
    {
        return false;
    }
    else
    {
        return true;
    }
}
function ShowData(str)
{
window.open(str);
}
function ShowImg(imgPath,imgName,imgid,isMainImage)
{
    imgOn = ("" + imgPath);
    document.getElementById("<%=imgShow.ClientID%>").src = '' +imgOn;
    document.getElementById("<%=imgShow.ClientID%>").style.display = "inline";
    document.getElementById("<%=spDesc.ClientID%>").innerText = imgName;
    document.getElementById("<%=hfImageId.ClientID%>").value = imgid;
    document.getElementById("<%=hfMode.ClientID%>").value = "update";
    var varI = document.getElementById("<%=ddlImgDesc.ClientID%>");
    var varChkBox = document.getElementById("<%=chkMainImg.ClientID%>");
    alert(varChkBox);
    if(isMainImage == "1")
    {
        varChkBox.selected = true;
    }
    for(var i=0; i < varI.options.length; i++)
    {
        if(varI.options[i].text == imgName)
        {
            document.getElementById("<%=hfDropDescID.ClientID%>").value = varI.options[i].value;
            varI.options[i].selected = true;  
        }
    }
}
function ShowImage(strControl)
{
document.getElementById("<%=imgShow.ClientID%>").src = strControl.value;
document.getElementById("<%=imgShow.ClientID%>").style.display = "inline";
}

function CheckMaxCharacters(s,maxlength) {
    if (s.value.length > maxlength)
        s.value = s.value.substring(0,maxlength);
    else
       document.getElementById("sp1").innerHTML = maxlength - s.value.length;
}
function CheckMaxCharactersOnly(s,maxlength) {
    if (s.value.length > maxlength)
        s.value = s.value.substring(0,maxlength);
}

function ValidatePrice()  
  {     
    if(document.getElementById("ctl00_cph_Main_lblValidPrice").innerHTML=="invalid price format")
     {
      var txtBox = document.getElementById("ctl00_cph_Main_txtPrice");
      txtBox.focus();
      return false;
     }
  } 
  
function AddCommas(textBxId)
{
    number = RemoveCommas(textBxId.value);
    ValidateAndFormatNumber(number,textBxId);
    number = '' + number;
    if (number.length > 3)
    {
        var numLength = number.length;
        var mod = numLength % 3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length / 3); i++)
        {
            if ((mod == 0) && (i == 0))
                output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
            else
                output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
        }
       textBxId.value=output;
}
}


    function RemoveCommas(num) 
    {
        for (i=1;i<num.length;i++) 
        {  
            num = num.replace(",","");
        }
        return num;
    }
    
    
    function ValidateAndFormatNumber(NumberTextBox,txtBxId)
        {
            if(NumberTextBox == "") return;
            
            UnFormatNumber(NumberTextBox);

            var IsFound = /^-?[0-9]+\.{0,1}[0-9]*$/.test(NumberTextBox);
            if(!IsFound)
            {
               document.getElementById("ctl00_cph_Main_lblValidPrice").innerHTML ="invalid price format";
               resetTextBoxFocus();
                return;             
            }
            else
                {
                    document.getElementById("ctl00_cph_Main_lblValidPrice").innerHTML = "";
                    resetTextBoxFocus();
                }
           NumberTextBox = FormatNumber(NumberTextBox);
        }
        
        
        function resetTextBoxFocus()
            {
                if (document.getElementById("ctl00_cph_Main_lblValidPrice").innerHTML == "invalid price format")
                {
                    var txtBox = document.getElementById("ctl00_cph_Main_txtPrice");
                   
                     txtBox.focus();
                      txtBox.value = txtBox.value;
                }
                else
                    document.getElementById("ctl00_cph_Main_lblValidPrice").innerHTML = "";
            }
        
        function FormatNumber(fnum)
        {
            var orgfnum = fnum;
            var flagneg = false;
            
            if(fnum.charAt(0) == "-")
            {
                flagneg = true;
                fnum = fnum.substr(1, fnum.length-1);
            }
            
            psplit = fnum.split(".");

            var cnum = psplit[0],
	            parr = [],
	            j = cnum.length,
	            m = Math.floor(j / 3),
	            n = cnum.length % 3 || 3;

            // break the number into chunks of 3 digits; first chunk may be less than 3
            for (var i = 0; i < j; i += n) {
	            if (i != 0) {n = 3;}
	            parr[parr.length] = cnum.substr(i, n);
	            m -= 1;
            }

            // put chunks back together, separated by comma
            fnum = parr.join(",");

            // add the precision back in
            //if (psplit[1]) {fnum += "." + psplit[1];}
            if (orgfnum.indexOf(".") != -1)  
            {
                fnum += "." + psplit[1];
            }
            
            if(flagneg == true)
            {
                fnum = "-" + fnum;
            }
            
            return fnum;
        }
        
        
        function UnFormatNumber(obj)
        {
            if(obj == "") return;
            
            obj = obj.replace(/,/gi, "");
        }
        
        function ConfirmOnDelete()
        {
          if (confirm("Are you sure to delete selected property?")==true)
            return true;
          else
            return false;
        }	