﻿// JScript File
function SelectAll(row_count,grid_client_id) // for Grid View items
{
   //alert("" + row_count + ", " + grid_client_id);
    chk_header_id=grid_client_id + "_ctl01" + "_chk_Select_All";
    chk_header = document.getElementById(chk_header_id);
     //alert("" + chk_header.id);
    for(var i=2;i<=row_count+1;i++)
    {
        var item_no=""
        if(i<10)
          item_no="0"+i;
        else
          item_no="" + i;
        chk_id=grid_client_id + "_ctl" + item_no + "_chk_Select_item";
        chk = document.getElementById(chk_id);
        //alert("" + chk.id);
         if (chk!=null)
        {
            //alert("" + chk.InnerText);
            chk.checked=chk_header.checked;
            //alert("" + chk.value +", "+ chk_header.value);
          }
    }
}

function Check_SelectedAny(row_count,grid_client_id,command_name) // for Grid View items
{
 
       for(var i=2;i<=row_count+1;i++)
        {
            var item_no=""
            if(i<10)
              item_no="0"+i;
            else
              item_no="" + i;
            chk_id=grid_client_id + "_ctl" + item_no + "_chk_Select_item";
            chk = document.getElementById(chk_id);
            //alert("" + chk.id);
            if (chk!=null)
            {
               // alert("" + chk.checked);
                if (chk.checked==true)
                {
                   if(command_name!="")
                      return confirm('Sure to '+ command_name +' selected products?');
                   else
                      return true;
                }
                //alert("" + chk.value +", "+ chk_header.value);
            }
        }
        alert("No record(s) selected");
        return false;

}


function SelectAll_Images(row_count,dtl_client_id,chk_selectall_id) // for image Datalist
{
   //alert("" + row_count + ", " + dtl_client_id);
   chk_selectall = document.getElementById(chk_selectall_id);
   //alert("" + chk_selectall.id);
    for(var i=0;i<row_count;i++)
    {
        var item_no=""
        if(i<10)
          item_no="0"+i;
        else
          item_no="" + i;
        chk_id=dtl_client_id + "_ctl" + item_no + "_chk_Select_item";
        chk = document.getElementById(chk_id);
        //alert("" + chk.id);
         if (chk!=null)
        {
            //alert("" + chk.InnerText);
            chk.checked=chk_selectall.checked;
           //alert("" + chk.value +", "+ chk_selectall.value);
          }
    }
}

function SelectAll_Items(row_count,dtl_client_id,chk_selectall_id,chk_tem_id) // for image Datalist
{
   //alert("" + row_count + ", " + dtl_client_id);
   chk_selectall = document.getElementById(chk_selectall_id);
   //alert("" + chk_selectall.id);
    for(var i=0;i<row_count;i++)
    {
        var item_no=""
        if(i<10)
          item_no="0"+i;
        else
          item_no="" + i;
        chk_id=dtl_client_id + "_ctl" + item_no + "_" + chk_tem_id;
        chk = document.getElementById(chk_id);
        //alert("" + chk.id);
         if (chk!=null)
        {
            //alert("" + chk.InnerText);
            chk.checked=chk_selectall.checked;
            //alert("" + chk.value +", "+ chk_selectall.value);
          }
    }
}

function SelectAnyOne_Item(row_count,dtl_client_id,chk_common_id,chk_client_id) // for image Datalist
{
   //alert("" + row_count + ", " + dtl_client_id);
   for(var i=0;i<row_count;i++)
   {
        var item_no=""
        if(i<10)
          item_no="0"+i;
        else
          item_no="" + i;
        chk_id=dtl_client_id + "_ctl" + item_no + "_" + chk_common_id;
        chk = document.getElementById(chk_id);
        //alert("" + chk.id);
        if (chk!=null)
        {
            //alert("" + chk.InnerText);
            chk.checked=0;
            //alert("" + chk.value +", "+ chk_selectall.value);
        }
    }
    chk_selected = document.getElementById(chk_client_id);
    //alert("" + chk_selected);
    chk_selected.checked=1;
}

function OpenPdf(PdfPath)
{
    window.open(PdfPath,"_blank");
}

function ZoomImage(ImgPath,WD,HT)
{
    
    if(WD>500){if (WD>=800) WD=820; else WD=500; }
    if(HT>500){if (HT>=600) HT=500; else HT=500; }
    
    dhtmlmodal.open("zoombox", "iframe", "Zoom_Picture.aspx?Image_Path=" + ImgPath,"Image","center=1,width=" + (WD+20) + ",height=" + (HT+10) + ",resize=0,scrolling=0","");
  
}

function ZoomImage_OL(ImgPath,WD,HT)
{
    
    if(WD>500){if (WD>=800) WD=820; else WD=500; }
    if(HT>500){if (HT>=600) HT=500; else HT=500; }
    
    dhtmlmodal.open("zoombox", "iframe", "Zoom_Picture.aspx?Image_Path=" + ImgPath,"OutLine Drawing","center=1,width=" + (WD+20) + ",height=" + (HT+10) + ",resize=0,scrolling=0","");
  
}

function ZoomImage_CO(ImgPath,WD,HT)
{
    
    if(WD>500){if (WD>=800) WD=820; else WD=500; }
    if(HT>500){if (HT>=600) HT=500; else HT=500; }
    
    dhtmlmodal.open("zoombox", "iframe", "Zoom_Picture.aspx?Image_Path=" + ImgPath,"CutOut Drawing","center=1,width=" + (WD+20) + ",height=" + (HT+10) + ",resize=0,scrolling=0","");
  
}

function ZoomPhoto(ImgPath,Title,WD,HT)
{            
    if (WD>=800) WD=820;
    if (HT>=600) HT=500;
    
    dhtmlmodal.open("Zoombox", "iframe", "Zoom_Photo.aspx?Image_Path=" + ImgPath + "&Type=" + Title,Title,"center=1,width=" + (WD+20) + ",height=" + (HT+40) + ",resize=0,scrolling=0","");          
}

function SetImage(ctrlId, Imagepath, Height, Width)
{   
    document.getElementById(ctrlId ).src=Imagepath;
    document.getElementById(ctrlId ).style.height=Height+"px";
    document.getElementById(ctrlId ).style.width=Width+"px";
} 

function CheckSave()
{
    var save_flag_val = !(RequiredTxt("txt_ModelNo","Model No cannot be empty."));
    if (save_flag_val==true)
    {
        save_flag_val = confirm("System is saving the product data and \nis advancing to Product Performance Page. \n\nDo you want to proceed?");   
        document.getElementById("hdn_SaveFlag").value=save_flag_val;
    }
    return save_flag_val;
}

function AddNewRow(Item_id,Plus_Button)
{
    //alert(Item_id);
    document.getElementById(Item_id).style.display="";
    //Plus_Button.style.display="none";
    return false;
}

function RemoveRow(Item_id,Minus_button,Plus_button_prev,Plus_buton_this,last_row)
{
    //alert(Item_id);
    document.getElementById(Item_id).value="";
    document.getElementById(Item_id).style.display="none";
    //if(document.getElementById(Plus_buton_this).style.display=="")
       // document.getElementById(Plus_button_prev).style.display="";
    return false;
}

function CheckFileTypes(file_uploader)
{
   if(file_uploader.value!="")
   {
    var file_path=file_uploader.value;
    var arr_file_exten_allowed=new Array(".bmp",".jpg",".png",".gif",".tif",".tiff",".dwg",".pdf");
    //alert(file_path + "\n" + file_path.toLowerCase());
    var valid_entry=false;
    file_path=file_path.toLowerCase();
    for(var i=0;i<file_path.length;i++)
    {
        if(file_path.lastIndexOf(arr_file_exten_allowed[i])>0)
        {
           valid_entry =true;
           break;
        }
    }
    if(!valid_entry)
    {
        alert("Inavlid File Type.");
        if(navigator.appName.toLowerCase()=='microsoft internet explorer')
        {
            file_uploader.select();
            n=file_uploader.createTextRange();
            n.execCommand('delete');                     
        }
        else
            file_uploader.value = "";
    }
   }
}

var DoAnimation=true;


function onUpdated() 
{
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv'); 
    // make it invisible
    updateProgressDiv.style.display = 'none';
}
function onUpdating()
{
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv'); 
    // make it visible
    updateProgressDiv.style.display = '';
    
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
    
    var ie=document.all && !window.opera;
    var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000; //Preliminary doc width in non IE browsers
	
    var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body; //create reference to common "body" across doctypes
	
    var scroll_top=(ie)? standardbody.scrollTop : window.pageYOffset;
    var scroll_left=(ie)? standardbody.scrollLeft : window.pageXOffset;
    var docwidth=(ie)? standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16);
    var docheight=(ie)? standardbody.clientHeight: window.innerHeight;
     
     
    var mx= Math.round(scroll_left+(docwidth-updateProgressDiv.offsetWidth)/2); 
    var my= Math.round(scroll_top+(docheight-updateProgressDiv.offsetHeight)/2);
    
    //	set the progress element to this position
    Sys.UI.DomElement.setLocation (updateProgressDiv, mx,my);    
        
}

////////////////User section ///////////////////////////////////

function ReplaceText_TextBox(obj_textbox,old_text,new_text,AlphaCheck)
{
    obj_textbox.value=str_trim(obj_textbox.value)
    if(AlphaCheck==true)
    {
        if(isNaN(obj_textbox.value)==true)
            obj_textbox.value = new_text;
    }
    if(obj_textbox.value == old_text)
        obj_textbox.value = new_text;
        
}


function SetScreenResolution(obj_id)
{
    obj=document.getElementById(obj_id);
    var screenwidth = screen.width;
    var screenwidth=parseInt(screenwidth) - 215 - 40;
    //alert(''+screenwidth);
    obj.style.width= screenwidth + "px";
    //alert(''+obj.style.width);
}

function str_trim(str_val)
{
    var start_non_space_char_pos=0;
    var last_non_space_char_pos=str_val.length;
    for(i=0;i<str_val.length && str_val.charAt(i)==' ';i++);
    start_non_space_char_pos=i;
    for(i=str_val.length-1;i>=0 && str_val.charAt(i)==' ';i--);
    last_non_space_char_pos = i - start_non_space_char_pos  + 1;
    return str_val.substr(start_non_space_char_pos,last_non_space_char_pos);
}

function ValueExists(obj_id,arr_value_to_avoid,msg)
{
    obj=document.getElementById(obj_id);
    
    for(j=0;j<arr_value_to_avoid.length;j++)
    {
        if(obj.value==arr_value_to_avoid[j])
        {
            if(msg!="")
                alert(msg);
            return false;
        }
    }
    return true;
}

function MultiControl_AnyValueExists(arr_obj_id,arr_value_to_avoid,msg)
{
    //alert("ok");
    var anyexists=false;
    for(i=0;i<arr_obj_id.length;i++)
    {
       //alert(arr_obj_id[i]);
       if(ValueExists(arr_obj_id[i],arr_value_to_avoid,"")==true)
         anyexists=true;
    }
    if (anyexists==false)
    {   if(msg!="")
            alert(msg);
    }
    return anyexists;
}

function Set_Url(obj, val_to_check)
{
   /* if(obj.value==val_to_check)
    {
        for(i=0;i<arr_obj_hlnks.length;i++)
        {
             var obj_link=document.getElementById(arr_obj_hlnks[i]);
             obj_link.href=arr_obj_hlnks_url[i];
        }
    }
    else
    {
        if(obj.value!="")
        {
            for(i=0;i<arr_obj_hlnks.length;i++)
            {
                 var obj_link=document.getElementById(arr_obj_hlnks[i]);
                 obj_link.href=arr_obj_hlnks_url[i] + "&Model_No=" + obj.value;
            }
        }
    }*/
}

function OpenExternalSites(site_url)
{
    window.open(site_url);
}

function ShowShaftnfo(ddl_shaft_id,ddl_measureunit_id)
{
    var shaft_no=document.getElementById(ddl_shaft_id).value;
    var measure_unit=document.getElementById(ddl_measureunit_id).value;
    dhtmlmodal.open('zoombox', 'iframe', 'Prod_Shaft_AddEdit.aspx?PageAction=2&Shaft_No=' + shaft_no + '&MeasureUnit=' + measure_unit, 'Shaft', 'center=1,width=600,height=220,resize=0,scrolling=0','');
}

function RemoveAllSelected(row_count,grid_client_id)
{
   
       for(var i=2;i<=row_count+1;i++)
        {
            var item_no=""
            if(i<10)
              item_no="0"+i;
            else
              item_no="" + i;
            chk_id=grid_client_id + "_ctl" + item_no + "_chk_Select_item";
            chk = document.getElementById(chk_id);
            //alert("" + chk.id);
            if (chk!=null)
            {
                //alert("" + chk.checked);
                if (chk.checked==true)
                {
                    hdn_id= grid_client_id + "_ctl" + item_no + "_hdn_Visible";
                    document.getElementById(hdn_id).value="0";
                    
                    selected_row_id=grid_client_id + "_ctl" + item_no ;
                    document.getElementById(selected_row_id).style.display="none";
                }
           }
        }
        return false;
}
