var checkValue = 0;
var checkValueName = 0;
var brwType = navigator.appName;

function AddScript(pathtoMember,strExtendBannerName,mainPath,rand)
{
   var script   = document.createElement( 'script' );
   script.src   = pathtoMember + strExtendBannerName+'/config.js?rand='+rand;
   document.getElementsByTagName( 'head' )[0].appendChild( script );
   
   var script   = document.createElement( 'script' );
   script.src   = mainPath + '/includes/Creative Banners/flash_detect_min.js';
   document.getElementsByTagName( 'head' )[0].appendChild( script );
   
   var script   = document.createElement( 'script' );
   script.src   = mainPath + '/includes/Creative Banners/xtdBannerLayout.js';
   document.getElementsByTagName( 'head' )[0].appendChild( script );
}     


function CheckAllById(chk, currentForm, chkId)
{

    for (var i=0;i < currentForm.elements.length;i++)
    {
	    var e = currentForm.elements[i];
	    if (e.type == "checkbox")
	    {
	    var count=e.id.indexOf(chkId);
	   
	       
                if(count!=-1)
                {
	                e.checked = chk.checked;
                }
	        }
	    }
    }
        
function CheckHead(chkAll, currentForm)
{
    
    var boolValue = true;
    var headCheck;
    for (var i=0;i < currentForm.elements.length;i++)
    {
        var e = currentForm.elements[i];
        if (e.type == "checkbox" && e.name == chkAll)
        {
            headCheck = e;
        }
        if (e.type == "checkbox" && e.name != chkAll)
        {
            if (!e.checked)
            {
                boolValue = false;
                headCheck.checked = false;
                break;
            }
        }
    }
 }
 
 function CheckHeadV2(chkAll,chkAllPro,currentForm)
{
    
    var boolValue = true;
    var headCheck;
    var headCheckPro;
    for (var i=0;i < currentForm.elements.length;i++)
    {
        var e = currentForm.elements[i];
        if (e.type == "checkbox" && e.id == chkAll)
        {
            headCheck = e;
        }
        
        if (e.type == "checkbox" && e.id == chkAllPro)
        {
            if(boolValue == false)
             {
               e.checked = false;
             }
        }  
        
        if (e.type == "checkbox" && e.id != chkAll)
        {
            if (!e.checked)
            {
                boolValue = false;
                headCheck.checked = false;
                //break;
            }
        }
    }
 }
 
function CheckAll(chk, currentForm)
{
    for (var i=0;i < currentForm.elements.length;i++)
    {
	    var e = currentForm.elements[i];
	    if (e.type == "checkbox")
	    {
		    e.checked = chk.checked;
	    }
    }
}

function CheckHeadByName(chkAll, currentForm)
{
    var boolValue = true;
    var headCheck;
    for (var i=0;i < currentForm.elements.length;i++)
    {
        var e = currentForm.elements[i];
        if (e.type == "checkbox"  && e.name == chkAll)
        {
            headCheck = e;
        }
        if (e.type == "checkbox" && e.name != chkAll)
        {
            if (!e.checked)
            {
                boolValue = false;
                document.getElementById(chkAll).checked = false;
                break;
            }
        }
    }
 }
function CheckAllByName(chk, currentForm, chkName, chkId)
{
    for (var i=0;i < currentForm.elements.length;i++)
    {
	    var e = currentForm.elements[i];
	    if (e.type == "checkbox")
	    {
	        if (e.id != "")
	        {
	            var count=e.id.indexOf(chkName); 
                if(count!=-1)
                {
	                e.checked = chk.checked;
                }
	        }
	    }
    }
//    for (var i=0;i < currentForm.elements.length;i++)
//    {
//	    var e = currentForm.elements[i];
//	    if (e.type == "checkbox")
//	    {
//	        var y = e.parentNode.childNodes;
//	        alert(e.parent.frames[1].name);
//	        if (y[0].id != null)
//            {
//                var count=y[0].id.indexOf(chkName); 
//                if(count!=-1)
//                {
//	                e.checked = chk.checked;
//                }
//            }
//	    }
//    }
}

function chkDeleteByName(chkAll, currentForm, varFor, chkName, chkId)
{
    checkValueName = 0;	
    CheckCountByName(chkAll, currentForm, chkName, chkId);
    if (checkValueName == 0)
    {
        alert('Please select any ' + varFor + '(s) to delete');
        return false;
    }	        
    else
    {	
        if (confirm('Do you want to delete selected ' + varFor + '(s)?'))
	        return true;
        else
	        return false;
	}
}

function CheckCountByName(chkAll, currentForm, chkName, chkId)
{
    for (var i=0;i < currentForm.elements.length;i++)
    {
	    var e = currentForm.elements[i];
	    if (e.type == "checkbox")
	    {
	        if (e.id != "")
	        {
	            var count=e.id.indexOf(chkName); 
                if(count!=-1)
                {
                    if (e.checked)
	                    checkValueName++;
                }
	        }
//	        var y = e.parentNode.childNodes;
//	        if (y[0].id != null)
//            {
//                var count=y[0].id.indexOf(chkName); 
//                if(count!=-1)
//                {
//	                if (e.checked)
//		            {
//		                checkValueName++;
//		            }
//                }
//            }
	    }
//	    if (e.type == "checkbox" && e.name != chkAll)
//	    {
//		    if (e.checked)
//		    {
//		        checkValue++;
//		    }
//	    }
    }	 
}

function chkDelete(chkAll, currentForm, varFor)
{
    checkValue = 0;	
    CheckCount(chkAll, currentForm);
    if (checkValue == 0)
    {
        alert('Please select any ' + varFor + '(s) to delete');
        return false;
    }	        
    else
    {	
        if (confirm('Do you want to delete selected ' + varFor + '(s)?'))
	        return true;
        else
	        return false;
	}
}

function CheckCount(chkAll, currentForm)
{
    for (var i=0;i < currentForm.elements.length;i++)
    {
	    var e = currentForm.elements[i];
	    if (e.type == "checkbox" && e.name != chkAll)
	    {
		    if (e.checked)
		    {
		        checkValue++;
		    }
	    }
    }	 
}

function chkSend(chkAll, currentForm, varFor)
{	
    checkValue = 0;
    CheckCount(chkAll, currentForm);
    if (checkValue == 0)
    {
        alert('Please select any ' + varFor + '(s) to send mail');
        return false;
    }
    return true;	        
}

function chkAdd(chkAll, currentForm, varFor)
{	
    checkValue = 0;
    CheckCount(chkAll, currentForm);
    if (checkValue == 0)
    {
        alert('Please select any ' + varFor + '(s) to add');
        return false;
    }
    return true;	        
}

function chkCommonFunction(chkAll, currentForm, varFor)
{
    checkValue = 0;	
    CheckCount(chkAll, currentForm);
    if (checkValue == 0)
    {
        alert('Please select any ' + varFor);
        return false;
    }	        
    else
    {						
        return true;
	}
}

function chkDeleteAlert(varFor)
{	
 if (confirm('Do you want to delete selected ' + varFor + ' ?'))
    return true;
 else
    return false;
}	

function chkDeleteUser()
{	
 if (confirm('You will be deleted permanently from the group'))
    return true;
 else
    return false;
}


function textCounter(field, countfield, maxlimit)
{
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit); // otherwise, update 'characters left' counter
    else 
        countfield.value = maxlimit - field.value.length;
   
 }
 
function DisplaytextCounter(field, countfield, maxlimit)
{
    if (document.getElementById(field) != null)
    {   
        var fieldDescription = document.getElementById(field);
        var countfieldDescription;
        if (document.getElementById(countfield) != null)
            countfieldDescription = document.getElementById(countfield);
        else
            countfieldDescription = document.getElementsByName(countfield);  
        if (fieldDescription.value.length > maxlimit) // if too long...trim it!
            fieldDescription.value = fieldDescription.value.substring(0, maxlimit); // otherwise, update 'characters left' counter
        else 
            countfieldDescription.value = maxlimit - fieldDescription.value.length;
    }
}

function openClosStatus(divId,Path, imgOpen, imgClose, imgName) 
{
    if (document.getElementById(divId).style.display == "block") 
    {
        document.getElementById(divId).style.display = "none";
        imgName.src = Path + imgOpen;
    } 
    else 
    {
        document.getElementById(divId).style.display = "block";
        imgName.src = Path + imgClose;
    }
}

function openClosStatusOnLoad(divId,Path, imgOpen, imgClose, imgName, boolCheck) 
{
    if (boolCheck)
    {
        document.getElementById(divId).style.display = "none";
        imgName.src = Path + imgOpen;
    } 
    else 
    {
        document.getElementById(divId).style.display = "block";
        imgName.src = Path + imgClose;
    }
 }
 
function CheckAvailableProduct(idTL, idAuction, chkTL, chkAuction, trTL, trAuction)
{
       SetValue();
       var strMessage = '';
       var intTlValue = 0;
       var intAuctionValue = 0;
       if (document.getElementById(idTL) != null)
           intTlValue = document.getElementById(idTL).value;
           
       if (document.getElementById(idAuction) != null)
           intAuctionValue = document.getElementById(idAuction).value;
           
       if (document.getElementById(chkTL) != null)
       {
           if (!document.getElementById(chkTL).checked)
           {
               if (intTlValue > 0)
               {
                    strMessage += "Trade lead ";
               }
           }
       }
       if (document.getElementById(chkAuction) != null)
       {
           if (!document.getElementById(chkAuction).checked)
           {
               if (intAuctionValue > 0)
               {
                    if (strMessage != '')
                        strMessage += "and Auction ";
                    else
                       strMessage += "Auction ";
               }
           }
       }
       
       if (strMessage != '')
       {
           if (confirm('The action will delete this product from ' + strMessage))
           {
                return true;
           }
           else
           {
                if (document.getElementById(idTL).value != '')
                    document.getElementById(chkTL).checked = true;
                else
                    document.getElementById(chkTL).checked = false;
                if (document.getElementById(idAuction).value != '')
                    document.getElementById(chkAuction).checked = true;
                else
                    document.getElementById(chkAuction).checked = false;
                ShowHide(chkTL, trTL, chkAuction, trAuction)
                SetValue();
                return false;
           }
       }
  }
  
 function MoveFocus(txtArea)
 {
    document.getElementById(txtArea).value += '\n';
    document.getElementById(txtArea).focus();
    return false;
 }


//var nextID = null; 

//function DisableEnterAndTab(evt, cNextID) 
//{
//    nextID = cNextID;
//    return kH(evt);
//}

//function kH(e) {
//     var code;
//     
//     if (!e) var e = window.event
//       if (e.keyCode) code = e.keyCode;
//       else if (e.which) code = e.which;
//     alert(e.which);
//     if((code==13))
//     {
//            document.getElementById(nextID).focus();
//            //e.cancelBubble = true;
//            alert(e.stopPropagation);
//            //if (e.stopPropagation) e.stopPropagation();
//            return false;
//       }else{
//         return true;
//       }
//}



