﻿// JScript File
function CheckUnCheckChild(objCheck,objFollow)
{
    try
    {
        for(var i=0;i<objCheck.getElementsByTagName("input").length;i++) 
        {
            if(objCheck.getElementsByTagName("input")[i].type == 'checkbox')
            {
                objCheck.getElementsByTagName("input")[i].checked  = objFollow.checked;
            }
        }
    }
    catch(err){}
}

function CheckUnCheckUsingParent(strControl,strCheckBox)
{
    try
    {
        CheckUnCheckChild(document.getElementById(strControl),document.getElementById(strCheckBox));
    }
    catch(err){}
}

function CheckUnCheckParent(objCheck,objFollow)
{
    try
    {
        var blnCheck = false;
        for(var i=0;i<objCheck.getElementsByTagName("input").length;i++) 
        {
            if(objCheck.getElementsByTagName("input")[i].type == 'checkbox')
            {
                if(!objCheck.getElementsByTagName("input")[i].checked)
                {
                    blnCheck = true;
                    break;
                }
            }
        }
        if(blnCheck)
            objFollow.checked = false;
        else
            objFollow.checked = true;
   }
   catch(err){}
}

function CheckUnCheckUsingChild(strControl,strCheckBox)
{
    try
    {
        CheckUnCheckParent(document.getElementById(strControl),document.getElementById(strCheckBox));
    }
    catch(err){}
}


function showHide(divtoshow,linkUsed)
{
      
        var objDiv =document.getElementById(divtoshow);
        var objLink = document.getElementById(linkUsed);
        if(objDiv != null && objLink != null)
        {
            if(objDiv.style.display == 'block')
                objDiv.style.display = 'none';
            else
                objDiv.style.display = 'block';
        }
}

function showDiv(divtoshow)
{
//debugger
    var objDiv = document.getElementById(divtoshow);
   
    if(objDiv != null)
    {
        if(objDiv.style.display == 'none')
        {  
           setPosition(divtoshow);//added by Dhara khachariya: to set the positon as per the resolution
           objDiv.style.display = 'block';
        }
        else
        {
        
            objDiv.style.display = 'none';
            var arrayOfDiv = document.getElementsByTagName("div");
            //alert(arrayOfDiv.length);
            for(i=0;i<arrayOfDiv.length;i++)
            {           
                if(arrayOfDiv[i].id != "")
                {
                    if(arrayOfDiv[i].id.indexOf('ucCompanyCard_divAdd') != -1)
                        arrayOfDiv[i].style.display = 'none';
                }
            }
        }
    }
}  

//dhara khachariya:19/4/07
//function to show hide the master div
function ShowHideMasterDiv()
{
//debugger

    //alert('ShowHideMasterDiv');
        var objDiv= document.getElementById(MasterDivGray);
        //alert(objDiv);
        if(objDiv != null)
        {
            
            if(objDiv.style.visibility=='visible')
            {
               
                 objDiv.style.visibility = 'hidden';
            }
           else
           {
               objDiv.style.visibility ='visible';
           }
             SetMasterDivPosition(objDiv);
        }
    // }
    
}

//dhara khachariya:19/4/07
//function to set the master div position
function SetMasterDivPosition(objDiv)
{

   if (window.innerHeight > 0 && window.scrollMaxY <= 0)
    { //firexox
       
         yWithScroll = window.innerHeight + "px"
         xWithScroll = window.innerWidth + "px";
        
    } 
    else if(window.scrollMaxY > 0)
    { //firexox
       
        yWithScroll = parseInt(window.innerHeight) + parseInt(window.scrollMaxY);
        yWithScroll = yWithScroll + "px";
        xWithScroll = window.innerWidth + "px";
    }
    else if (document.body.scrollHeight > document.documentElement.clientHeight)
    { // all but Explorer Mac  
       
        yWithScroll = document.body.offsetHeight;         
        xWithScroll = document.body.offsetWidth;   
        
    } 
    else 
    { // works in Explorer 6 Strict, Mozilla (not FF) and Safari     
        //alert(document.body.scrollHeight-document.documentElement.clientHeight);
          yWithScroll =  document.documentElement.clientHeight;
           xWithScroll = document.documentElement.clientWidth;     
         
    } 
        
    objDiv.style.position="absolute";
    objDiv.style.top="0px";
    objDiv.style.left="0px"; 
    objDiv.style.width=xWithScroll;
    objDiv.style.height=yWithScroll;
    objDiv.style.overflow="hidden";
}



//dhara khachariya:19/4/07
//function to set positon of the div
function setPosition(divName)
{ 
   
    var objYes = document.getElementById(divName);
    if(divName=="divBookmark")
    {
       
        if(screen.width==1024)
        {
        objYes.style.position="absolute";
        objYes.style.top="379px";
        objYes.style.left="170px";
        }
        if(screen.width==1280)
        {
        
        objYes.style.position="absolute";
        objYes.style.top="300px";
        objYes.style.left="300px";
     
        }
    }
   
 }
 
 
//dhara khachariya:19/4/07
//function to show master div
 function ShowMasterDiv()
{
   
    var objDiv= document.getElementById(MasterDivGray);
    
    if(objDiv != null)
    {
         objDiv.style.visibility ='visible';
      
         SetMasterDivPosition(objDiv);
    }

}

function CheckContactValidation(IdMemo,IdMessageToContact,IdWeight)
{
//    var flag = 1;
//    if(IdMemo.value == "")
//    {
//        alert("memo : " + IdMemo.value);
//        flag = 0;
//    }
//    if(IdMessageToContact.value == "")
//    {
//        alert("IdMessageToContact : " + IdMessageToContact.value);
//        flag = 0;
//    }
//    if(IdWeight.value == "")
//    {
//        alert("IdWeight : " + IdWeight.value);
//        flag = 0;
//    }
//    if(IdWeight.value < 0 || IdWeight.value > 100)
//    {
//         alert("IdWeight >: " + IdWeight.value);
//        flag = 0;
//    }
//    alert(flag);
//    if(flag == 1)
//        return true;
//        
//    return false;
}


//added on 26.10.2007 by krishna raval

//////this function check contact operation type.if is contacttoconfirm then return true else false.
//function CheckMessageToContact(sender,args)
//{ 

//    if(strOperation=='CONFIRM')
//    {
//             args.IsValid = true;
//    }
//    else
//    {   
//       // if(document.getElementById(txtMessageToContact).value=='')
//        if(document.getElementById(sender.controltovalidate).value=='')       
//        {              
//           // document.getElementById(lblMessageToContactError).style.display='block';                               
//            args.IsValid = false;
//        }
//        else
//        {
//           // document.getElementById(lblMessageToContactError).style.display='none';        
//            args.IsValid = true;        
//        }
//    }
//   
//}



//---function to check textbox's maxlength.

// Keep user from entering more than maxLength characters
function doKeypress(control) {
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
    if (maxLength && value.length > maxLength - 1) {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
    }
}
// Cancel default behavior
function doBeforePaste(control) {
    maxLength = control.attributes["maxLength"].value;
    if (maxLength) {
        event.returnValue = false;
    }
}
// Cancel default behavior and create a new paste routine
function doPaste(control) {
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
    if (maxLength) {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        var oTR = control.document.selection.createRange();
        var iInsertLength = maxLength - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}

