﻿// JScript File

function validatefld(ids,Message)
    {
        var obj;
        obj=document.getElementById(ids);
        if(obj.value=="" || obj.value==false)
        {
            alert(Message);
            document.getElementById(ids).value="";
            document.getElementById(ids).focus();
            return false;
        }
        return true;
    }
 function validatetext_alert(id,message)
 {
    var obj;
    obj=document.getElementById(id);
    if(obj.value="")
    {
            alert(Message);
            document.getElementById(ids).value="";
            return false;
    }
 }
 function validatefld_combo(ids,Message)
    {
        var obj;
        obj=document.getElementById(ids);
        if(obj.value==0)
        {
            alert(Message);
            document.getElementById(ids).value=0;
            return false;
        }
        return true;
    }
function CompareValues(ids1,ids2,Message)
    {
        var obj1;
        obj1=document.getElementById(ids1);

        var obj2;
        obj2=document.getElementById(ids2);
        
        if(obj1.value!=obj2.value)
        {
            alert(Message);
            return false;
        }
        return true;
    }    
    
    
    // JScript File

function checkEmail(str)
    {
      
        var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
         
            
 		 return true;	
    }
    
    
    
    function round_decimals(original_number, decimals) 
     {

        var result1 = original_number * Math.pow(10, decimals)
        var result2 = Math.round(result1)
        var result3 = result2 / Math.pow(10, decimals)
        return pad_with_zeros(result3, decimals)
    }

    function pad_with_zeros(rounded_value, decimal_places) 
    {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}


function pop_calendar(frmname,txtname)
{
    var browser=navigator.appName;
    var b_version=navigator.appVersion;
    var version=parseFloat(b_version);
    
    if(browser!='Netscape')
    var w = window.open(frmname+'?textbox='+txtname,'Calendar','width=200,height=180');  
    else
    var w = window.open(frmname+'?textbox='+txtname,'Calendar','width=210,height=270');  
   
    
}

function popWind(file,window,height,width)
{
    var w = window.open('ShowproductImage.aspx?ID=1','test','scrollbars=0,width=250,height=200');
}

function newWindow(file,window,height,width)
{
   
    msgWindow=open(file,window,'height='+height+',width='+width+',resizable=yes');
	if (msgWindow.opener == null) msgWindow.opener = self;
	
}

function get_numeric_check(element_id,msgtext)
{
    
    if(isNaN(document.getElementById(element_id).value))
    {
        alert(msgtext +' Must Be Numeric.');
        document.getElementById(element_id).value=0;
        document.getElementById(element_id).focus();
        return false;
        
    }
    return true;

}

function get_NonNegCheck(element_id,msgtext)
{
    
    if(isNaN(document.getElementById(element_id).value))
    {
        alert(msgtext +' Must Be Numeric.');
        document.getElementById(element_id).value=0;
        document.getElementById(element_id).focus();
        return false;
        
    }
    if(document.getElementById(element_id).value!=false)
    {
       if(document.getElementById(element_id).value<0)
       {
            alert(msgtext +' Must Be Greater Zero.');
            document.getElementById(element_id).value='';
            document.getElementById(element_id).focus();
            return false;
        }
        
    }
    return true;

}

function get_NonNegCheck_withString(element_id,msgtext)
{
   
    if(isNaN(document.getElementById(element_id).value)==false)
    {    
        if(document.getElementById(element_id).value!=false)
        {
           if(document.getElementById(element_id).value<0)
           {
                alert(msgtext +' Must Be Greater Zero.');
                document.getElementById(element_id).value='';
                document.getElementById(element_id).focus();
                return false;
            }
        }
        
    }
    return true;

}