﻿// example that checks all validators on the page
var listBoxSelected = 0;

function ValidOrNot()
{
    var validator;
    var blnReturn = true;
    var drpcompanyedit;
    var drpcompanyadd;
    var listcompany;
   var checker;
    for (var i = 0; i < Page_Validators.length; i++)
    {
        validator = Page_Validators[i];
        ValidatorValidate(validator);

        // validation fails if at least one validator fails
        if (!validator.isvalid)
            blnReturn = false;
    }

        // create dialog box here
        //alert('well done!');

        // set it to true to post back page
   
  drpcompanyedit = document.getElementById("ctl00_CONTENT_actDetaId_ActivityOrgStructure1_drpSearchAdvCompany");
  drpcompanyadd = document.getElementById("ctl00_CONTENT_ctl00_ActivityOrgStructure1_drpSearchAdvCompany");
  

if(drpcompanyadd)
{
listcompany = drpcompanyadd;
}
else 
{
if(drpcompanyedit)
listcompany = drpcompanyedit;
}


if(listcompany)
{
   for (var i=0; i < listcompany.options.length; i++)
      {
      if (listcompany.options.item(i).selected == true )
         {
         checker = true;
          }       
       }
//       
    if (!checker)
     {
   
     blnReturn = false;    
     }
 }    

     return blnReturn;
}


//function ValidOrNot()
//{
//    var validator;
//    var blnReturn = true;
//    for (var i = 0; i < Page_Validators.length; i++)
//    {
//        validator = Page_Validators[i];
//        ValidatorValidate(validator);

//        // validation fails if at least one validator fails
//        if (!validator.isvalid)
//            blnReturn = false;
//    }

//        // create dialog box here
//        //alert('well done!');

//        // set it to true to post back page
//     return blnReturn;
//}

function ShowPopup()
{
    
    var testMe = ValidOrNot()
    if(testMe == true)    
    {document.getElementById("loadingDiv").style.display="block";}
    
    
}

function ProjectStatusCheck(objDrpLstStatus)
{
    var answer;
    objDropList = document.getElementById(objDrpLstStatus)      
    if (objDropList.selectedvalue="Finished")
    {
        answer =confirm("Do you really want to finish the project.\n This is set all productions to finish status") ;
    }
  return answer;
}


function UncheckBox(objCheckBox)
{

    objCheckBox = document.getElementById(objCheckBox)      
    objCheckBox.checked = false;  
}


function ChangeLabel(ObjName, stringText)
{
   
    divObj = document.getElementById(ObjName)    
    divObj.innerHTML = stringText
        
}

function ChangeBack(ObjNameTo, ObjNameFrom)
{   
    
    document.getElementById(ObjNameFrom).innerHTML = document.getElementById(ObjNameTo).value        
}

function SetNewName(ObjFrom,ObjTo)
{   
    
    //ctl00_CONTENT_ProjectDetailsTop_lblProjectNameTop
    document.getElementById(ObjFrom).innerHTML = document.getElementById(ObjTo).value        
}



function ChangeCheckBoxState(id, checkState)
{
      var cb = document.getElementById(id);
      if (cb != null)
         cb.checked = checkState;
}

function ChangeAllCheckBoxStates(checkState,checkBoxArray)
{
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
      if (checkBoxArray != null)
      {
         for (var i = 0; i < checkBoxArray.length; i++)
            ChangeCheckBoxState(checkBoxArray[i], checkState);
      }
}


function CheckIfAnySelectionInArray(checkBoxArray)
{
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
      var selNotSel
      if (checkBoxArray != null)
      {
         for (var i = 0; i < checkBoxArray.length; i++)
         {
              //ChangeCheckBoxState(checkBoxArray[i], checkState);
                var cb = document.getElementById(checkBoxArray[i]);
                if (cb != null)
                {
                if (cb.checked == true)
                {
                    selNotSel = true;
                    break;
                }
                else
                {
                    selNotSel = false;
                }
                }            
          }
      }
      
      if(selNotSel==false)
      {
        alert("Please make your selection.")
        return false;
      }     
      else
      {
        return true;
      }   
     
      
}

function CheckIfAnySelectionAndNumberInArray(checkBoxArray)
{
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
      var selNotSel=false
       var countSelected=0
       
      if (checkBoxArray != null)
      {
         for (var i = 0; i < checkBoxArray.length; i++)
         {
              //ChangeCheckBoxState(checkBoxArray[i], checkState);
                var cb = document.getElementById(checkBoxArray[i]);
                if (cb != null)
                {
                    if (cb.checked == true)
                    {
                        selNotSel = true;
                        countSelected++;
                    }
                }            
          }
      }
      
      if(selNotSel==false)
      {
        alert("Please make your selection.")
        return false;
      }     
      
      if(countSelected>1)
      {
       alert("Please select just one item.")
       return false;
      }  
     
      return true; 
}


function CheckNumberInSelectionInArray(checkBoxArray)
{
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
      var selNotSel
      var countSelected=0

      if (checkBoxArray != null)
      {
         for (var i = 0; i < checkBoxArray.length; i++)
         {
              //ChangeCheckBoxState(checkBoxArray[i], checkState);
                var cb = document.getElementById(checkBoxArray[i]);
                if (cb != null)
                {
                   if (cb.checked == true)
                    {
                       countSelected++;
                        
                    }              
                }            
          }
      }     
      
      if(countSelected>1)
      {
       alert("Please select just one item.")
       return false;
      }  
      else
      {
        return true;
      }   
}

function emailForm()
{ 

        var daReferrer = document.referrer; 
        var email = "yours@email.com"; 
        var errorMsg = "here here here is the error error error error"; 
        var subject = "Exception Error"; 
        var body_message = "%0D%0D%0D%0DThank you "+name+" for submitting this error to us. Please tell us in the space above, what you were doing when the error occurred.%0D%0DReferring Page: "+daReferrer+" %0D%0DException Error Message:%0D-------------------------------------------%0D"+errorMsg; 

        var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message; 

        win = window.open(mailto_link,'emailWindow'); 
        if (win && win.open &&!win.closed) win.close(); 
} 


function CheckDropBoxForAlert(source)
{
      var dropdown = document.getElementById(source.controltovalidate);
       if (dropdown.selectedindex == 0)
         {
             alert("Please choose Document Type");
             return false;
         }
       else
        {
            return true;
        }
}


function CheckIfAnySelectionInArrayAndDelete(checkBoxArray,msg)
{
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
      var selNotSel
      var ret
      if (checkBoxArray != null)
      {
         for (var i = 0; i < checkBoxArray.length; i++)
         {
              //ChangeCheckBoxState(checkBoxArray[i], checkState);
                var cb = document.getElementById(checkBoxArray[i]);
                if (cb != null)
                {
                if (cb.checked == true)
                {
                    selNotSel = true;
                    break;
                }
                else
                {
                    selNotSel = false;
                }
                }            
          }
      }
      
      if(selNotSel==false)
      {
        alert("Please make your selection.")
        return false;
      }     
      else
      {
//         ret = confirm('Are you sure you want to delete selected document/s?');
         ret = confirm(msg);
        return ret;
      }   
     
      
}


function CheckIfAnySelectionInArrayAndRemove(checkBoxArray,chkMemArrayNotDelete,msg)
{
      // Toggles through all of the checkboxes defined in the CheckBoxIDs array
      // and updates their value to the checkState input parameter
      var selNotSel
      var ret
      if (checkBoxArray != null)
      {
         for (var i = 0; i < checkBoxArray.length; i++)
         {
              //ChangeCheckBoxState(checkBoxArray[i], checkState);
                var cb = document.getElementById(checkBoxArray[i]);
                if (cb != null)
                {
                if (cb.checked == true)
                {
                    for (var j = 0; j < chkMemArrayNotDelete.length; j++)
                        {
                            if (chkMemArrayNotDelete[j]== checkBoxArray[i])
                            {
                                alert('Please replace the user before removing him/her');
                                return false;
                            }
                        }
                    selNotSel = true;
                    break;
                }
                else
                {
                    selNotSel = false;
                }
                }            
          }
      }
      
      if(selNotSel==false)
      {
        alert("Please make your selection.")
        return false;
      }     
      else
      {
//         ret = confirm('Are you sure you want to delete selected document/s?');
         ret = confirm(msg);
        return ret;
      }   
     
      
}


 function OpenMediaBank(strUrl)
 {
    var windowHandler;
    windowHandler=window.open(strUrl ,'win_mrm',"toolbar=no,scrollbars=yes,height=540,width=950,left=50,top=100,resizable=yes,status=no"); 
    windowHandler.focus();
  
 }
 function readCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) 
    {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function createCookie(name,value,days) 
{
    if (days)
    {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}
function eraseCookie(name) 
{
	createCookie(name,"",-1);
}


