//alert("hi suresh");

function fnFocusOnAWB()
{
  focusOnAWB = true;
}
function fnBlurOnAWB()
{
  focusOnAWB = false;
}

function updateUI(header, message)
{
	document.getElementById("errorDiv").innerHTML=
        "<p class=\"error\"><strong>" + header + "</strong></p><p class=\"error\">" + message + "</p>";

    document.getElementById("errorDiv").style.display="block";
    //fnClean();
}



function fnTrim(inputString, side)
{
	var tempString = "";
	var tempChar = "";
	var count = "";
	var SINGLE_BLANK = " ";
	var inputWidth = 0;
	if (null == inputString)
	{
	    tempString = "";
	}
	else
	{
		inputWidth = inputString.length;
		switch (side)
		{
		    case 0:
				//left trim
				for (count = 0; count < inputWidth; count++)
				{
				    tempChar = inputString.charAt (count);
				    if (SINGLE_BLANK != tempChar )
				    {
				        tempString = inputString.substring (count, inputWidth);
				        break;
				    }
				}
				break;

		    case 1:
	            //right trim
	            for (count = inputWidth - 1; count >= 0 ; count--)
	            {
	                tempChar = inputString.charAt (count);
	                if (SINGLE_BLANK != tempChar )
	                {
	                    tempString = inputString.substring (0, count+1);
	                    break;
	                }
	            }
	            break;
	        case 2:
	            //both trim
	            for (count = 0; count < inputWidth; count++)
	            {
	                tempChar = inputString.charAt (count);
	                if (SINGLE_BLANK != tempChar )
	                {
	                    tempString = inputString.substring (count, inputWidth);
	                    break;
	                }
	            }
	            inputWidth = tempString.length;
	            for (count = inputWidth - 1; count >= 0 ; count--)
	            {
	                tempChar = tempString.charAt (count);
	                if (SINGLE_BLANK != tempChar )
	                {
	                    tempString = tempString.substring (0, count+1);
	                    break;
	                }
	            }
	            break;
        }
    }
    return tempString;
} // end of fnTrim

function strip( instring )
{
    var outstring="";
    var bit="";
    var founddigit=false;
    for( j=0;j<instring.length;j++ )
    {
        c=instring.charAt(j);
        if( c != "," && c != " " && c !="\t" && c !="\n"  && c !="\r" )
        {
            if( founddigit == true )
            {
                outstring+=bit;
            }
            bit="";
            outstring+=c;
            founddigit=true;
        }
        else if( founddigit == true )
        {
            bit+=c;
        }
    }
    return outstring;
}

function isZeroValue()
{
	for( i=0 ; i < awbsLength ; i++ )
	{
		//changed on 200210
		var awbNumTrackLn = fnTrim(awbs[i], 2);
		for(j=0;j<awbNumTrackLn.length;j++){
			 
			myzeroArrayTrack[j] = awbNumTrackLn.charAt(j);
			 
		}
		
		if( awbNumTrackLn.length == 1 && parseInt( awbs[i] ) == 0 )
		{
			return true;
		}else if(awbNumTrackLn.length > 1){
			
			incTk = 0;
			
			for( k= 0;k<myzeroArrayTrack.length;k++){
							
				if(parseInt( myzeroArrayTrack[k] ) == 0){
					
					
					incTk = incTk+1;
					//alert("Inside Inc"+inc);
				}
				
			}
			if(incTk == myzeroArrayTrack.length){
				return true;
			}
		}
	}
}

function isDuplicate()
{
	for( i=0 ; i< awbsLength - 1 ; i++ )
	{ 
		awbs[i] = awbs[i].replace(/\s+/g,'');
		awbs[i] = fnTrim(awbs[i], 2);
		for( j=(i+1) ; j< awbsLength ; j++ )
		{
			awbs[j] = fnTrim(awbs[j], 2);
			if(awbs[i].length !=0 && awbs[j].length !=0 )
			{
				if (awbs[i] == awbs[j])
				{
					return true;
				}
			}
		}
	}
	
	return false;
}

function isDIValid(diValue)
{
    
    var validDIList = pieceIdDiField;

    if( validDIList.indexOf( "|" + diValue + "|" ) != -1
                || validDIList.indexOf( diValue + "|" ) != -1
                ||validDIList.indexOf( "|" + diValue) != -1 )
    {
        return true;
    }
    else
    {
        reasonForReject = "Invalid AI/DI";
        return false;
    }

}

function isIACValid( pieceId, startingIndex )
{

    //Check if the IAC starts with a character

    var iacAsNumber = new Number(pieceId.charAt(startingIndex));

    if( iacAsNumber.toString() != "NaN" )
    {
        reasonForReject = "First IAC char is a number";
        return false;
    }

    var validIACList = pieceIdIacField;

    //Check if the IAC is valid
    if( validIACList.indexOf( "|" + pieceId.substring( startingIndex, startingIndex+3) + "|" ) != -1 )
    {
        //3 digit IAC handled here
        return true;
    }
    else if( validIACList.indexOf( "|" + pieceId.substring( startingIndex, startingIndex + 2) + "|" ) != -1 )
    {
        //2 digit IAC handled here
        return true;
    }
    else if( validIACList.indexOf( "|" + pieceId.substring( startingIndex, startingIndex + 1) + "|" ) != -1 )
    {
        //1 digit IAC handled here
        return true;
                                                                
    }
    else
    {
        reasonForReject = "Invalid IAC";
        return false;
    }
}



function testPiece( pieceId)
{
    //check the max length of teh piece-id along with the special characters and ().
    var pieceIdTmp = pieceId.replace(/[^a-zA-Z0-9]+/g,'');

    //check the min max rule
    if( pieceIdTmp.length < 7 || pieceIdTmp.length > 37 )
    {
        reasonForReject = "Piece id length < 7 or > 37";

        return false;
    }

    //Replace special characters apart from ()
    //var pieceId = "this is a (te)!!!!st st>r23ing**%";
    pieceId =  pieceId.replace(/[^a-zA-Z0-9()]+/g,'');
    
    pieceId = fnTrim(pieceId, 2);

    //Check if piece id starts with "("
    if( pieceId.indexOf("(") == 0 )
    {

        var closingBracketIndex = pieceId.indexOf(")");
        
        //If there is no char between starting and closing bracket
        if( closingBracketIndex != 1 )
        {

            //get the value between brackets
            var valueBetweenBrackets = pieceId.substring(1, closingBracketIndex);
            
            //Check if the DI is present in the valid DI list
            if( isDIValid( valueBetweenBrackets ) )
            {

                //If the DI is 00
                if( valueBetweenBrackets == "00" )
                {

                    var tmpPid = pieceId.substring(closingBracketIndex + 1);
                    
                    var pidAsNumber = new Number(tmpPid);
                    
                    //if this is a valid number
                    if( pidAsNumber.toString() != "NaN" )
                    {
                        var pidlength = pieceId.length;

                        //length must be 22 including ( AI/DI )
                        if( pidlength == 22 )
                        {
                            reasonForSuccess = "Piece id meets all criteria";

                            //Piece Id is valid
                            return true;
                        }
                        else
                        {
                            reasonForReject = "Piece Id length is not 18";
                        }
                    }
                    else
                    {
                        reasonForReject = "Piece Id is not numeric";
                    }

                }
                else
                {
                    //Check if IAC is valid
                    if( isIACValid( pieceId, closingBracketIndex + 1 ) )
                    {
                        //Now check length
                        //get the length of the piece Id
                        pidlength = pieceId.length;

                        if( valueBetweenBrackets == "5J" || 
                        valueBetweenBrackets == "6J" )
                        {       
                            //length must be less than or equal to 24 including ( AI/DI )
                            if( pidlength <= 24 )
                            {
                                reasonForSuccess = "Piece id meets all criteria";

                                //Piece Id is valid
                                return true;
                            }
                            else
                            {
                                reasonForReject = "Piece Id length is  > 20";
                            }
                        }
                        else
                        {

                            if( valueBetweenBrackets == "J" )
                            {
                                //length must be less than or equal to 38 including ( AI/DI )   
                                if( pidlength <= 38 )
                                {
                                    reasonForSuccess = "Piece id meets all criteria";

                                    //Piece Id is valid
                                    return true;
                                }
                                else
                                {
                                    reasonForReject = "Piece Id length is > 35";
                                }
                            }
                            else
                            {
                                //length must be less than or equal to 39 including ( AI/DI )   
                                if( pidlength <= 39 )
                                {
                                    reasonForSuccess = "Piece id meets all criteria";

                                    //Piece Id is valid
                                    return true;
                                }
                                else
                                {
                                    reasonForReject = "Piece Id length is > 35";
                                }
                            }

                            
                        }
                    }
                }
            }
        }
        
    }//End of ( check
    else 
    {

        var diValue = pieceId.substring(0,1);

        if( diValue == "J" )
        {
            reasonForSuccess = "Since it starts with J. No Validation at NGW end.";

            return true;
        }
        else
        {
            diValue = pieceId.substring(0,2);
        }
        
        //Check if the DI is present in the valid DI list
        if( isDIValid( diValue ) )
        {
            //If the DI is 00
            if( diValue == "00" )
            {
                
                pidAsNumber = new Number(pieceId);
                
                //if this is a valid number
                if( pidAsNumber.toString() != "NaN" )
                {
                    pidlength = pieceId.length;

                    //length must be 20 including AI/DI
                    if( pidlength == 20 )
                    {
                        reasonForSuccess = "Piece id meets all criteria";

                        //Piece Id is valid
                        return true;
                    }
                    else
                    {
                        reasonForReject = "Piece Id length is not 18";
                    }
                }
                else
                {
                    reasonForReject = "Piece Id is not numeric";
                }
                

            }
            else
            {
                //Check if IAC is valid
                if( isIACValid( pieceId, 2 ) )
                {
                    //Now check length
                    //get the length of the piece Id
                    pidlength = pieceId.length;

                    if( diValue == "5J" || 
                    diValue == "6J" )
                    {           
                        //length must be less than or equal to 22 including AI/DI
                        if( pidlength <= 22 )
                        {
                            reasonForSuccess = "Piece id meets all criteria";

                            //Piece Id is valid
                            return true;
                        }
                        else
                        {
                            reasonForReject = "Piece Id length is not > 20";
                        }
                    }
                    else if( diValue != "J" )
                    {
                        //length must be less than or equal to 37 including AI/DI
                        if( pidlength <= 37 )
                        {
                            reasonForSuccess = "Piece id meets all criteria";

                            //Piece Id is valid
                            return true;
                        }
                        else
                        {
                            reasonForReject = "Piece Id length is > 35";
                        }
                    }
                }
            }
        }
        else
        {
            //alert(" pidlength  :"+pieceIdTmp.length );
            
            if(pieceIdTmp.length  <= 35)
            {
                reasonForSuccess = "Invalid AI/DI. No Validation at NGW end.";
                return true;
            }
            else
            {
                reasonForReject = " Even AI/DI not present,yet length is greter than 35 characters.";
                return false;
            }
        }
    }
}



function validatePieceid(pieceid)
{   
    var pid = " ";
    pid = pieceid.toUpperCase();

    if(!testPiece(pid))
    {
       //alert("Sorry!! Piece Id - "+pid +" would NOT be sent to ITS\nReason: " + reasonForReject);
        return false;
    }
    else
    {
        pid =  pid.replace(/[^a-zA-Z0-9]+/g,'');
        
       //alert("Bingo!! Piece Id - "+pid + " WOULD BE sent to ITS\nReason: " + reasonForSuccess);
        return true ;
    }

}

function isValidDHLAWB(awbNum)
{
	awbNum = fnTrim(awbNum, 2);
	//awbNum = awbNum.replace(/\s+/g,'');
	//awbNum = awbNum.replace(/[^a-zA-Z0-9]+/g,'');
	if(isNaN( awbNum ))
	{
	  //alert(" this is string !!! Invalid AWB..go for piece id validation");
        return false;
	}
	if (awbNum.length != 10 )
	{
	    return false;
	}
	check1=awbNum.substring(9,10);
	tocheck=awbNum.substring(0,9);
	check2=tocheck % 7;
	if( check1 != check2  && awbNum != "" )
	{
	    return false;
	}
	return true;
}

function fnDHL(form)
{
	//var finalPieceStr  = "";
	var trimmedPid     = "";
	var upperCasePid   = "";
	errors="";
	var isAwbFound = false;
	var isPieceFound = false;
	var invalidEntryFound = false;
	var errorMessage = "";
	var newline = "<br>";
	var space   = " ";

	if ( (awbsLength > 10) || ((flagSpaceEnter) && (awbsLength==10)) )
	{
		//+ brandText+"s."
		//alert("brandText::"+brandText);
		updateUI( toomanyNumber, lessthanTenNumber + " " );
	    return false;
	}
	//added by suresh
	finalPieceStr =" ";
	for (i=0;i<awbsLength;i++)
	{
    
		awbs[i] = awbs[i].replace(/\s+/g,'');
		//alert("AWB inside fndhl replace all the special char"+)
		if( awbs[i].length !=0)
		{

			if (!isValidDHLAWB(awbs[i]))
			{
				if(!validatePieceid(awbs[i]))
				{
					var pieceIdLen = awbs[i];
					if(pieceIdLen.length != 0)
					{
						var notAwb = notAwb1;
						var notPieceId = notPieceId1;
						
						invalidEntryFound = true;
						errorMessage = errorMessage + 
						entry + space + (i+1) + space + notAwb + 
						notPieceId +newline;
      
						if( errors == "" ) errors=""+(i+1);
						else errors+=(  ", " + (i+1) );
					}
				}
				else
				{
					
					errorMessage = errorMessage + 
					entry + space +(i+1) + space + isPieceId +newline;
					
					isPieceFound = true;
				}
     
			}
			else
			{
				
				errorMessage = errorMessage + 
				entry + space+ (i+1) + space+ isAwb +newline;
				
				isAwbFound = true;
			}
		}

		trimmedPid = awbs[i].replace(/[^a-zA-Z0-9]+/g,'');
		
		upperCasePid =  trimmedPid.toUpperCase();
		
		finalPieceStr = finalPieceStr + upperCasePid + "\n";
		finalPieceStr = fnTrim(finalPieceStr,2);
		//alert(" final piece string ="+finalPieceStr);
    

		if( i == awbsLength - 1 )
		{   
			
		   //document.getElementById("AWB").value = finalPieceStr;
		    
		} 
	}

    if( errorMessage != "" )
    {     
		if( isAwbFound && isPieceFound )
		{
			
		    updateUI(combinationNotAllowed, errorMessage + " " +"<br>"+ errMixed );
		    return false;
		}
	}

	if( errors != "" )
	{
    
		showRed = true;
		
		
		numbad=errors.split( ", " );
		if( numbad.length == 1 )
		  updateUI( invalidEntry, entry + " " + numbad[0] + " " + isNotValidAWBorPiece );
		else
		  updateUI( invalidEntry, entries + " " + errors + " " + areNotValidAWBorPiece +"<br>"+ correctAWB);
		  
		return false;
	}
	if (isZeroValue())
	{
		
		updateUI(invalidValues,errorZero+"<br>"+correctRemove);
		return false;
	}
	
	if (isDuplicate())
	{
		//alert("Duplicate Number::");
		
		updateUI(duplicatevalue,errorDuplicateNumber+"<br>"+correctRemove);
		return false;
	}

  return true;
}

function fnDPEE()
{
	if ( (awbsLength > 10) || ((flagSpaceEnter) && (awbsLength==10)) )
	{
		//alert("brandTextDPEE::"+brandText);
		updateUI( toomanyNumber, lessthanTenNumber + " ");
		return false;
	}
	if (isZeroValue())
	{
		
		updateUI(invalidValues, errorZero);
		return false;
	}
	if (isDuplicate())
	{
				
		updateUI(duplicatevalue, errorDuplicateNumber+"<br>"+correctRemove);
		return false;
	}
	return true;
}

function fnDanzas(brand)
{
	if ( (flagSpaceEnter) || (awbsLength>1) )
	{
		
		//+ brandText+"."
		updateUI( toomanyInput, pleaseEnter + " " + onlyOne + " " );
		return false;
	}
	
	
	if (isZeroValue())
	{
		
		updateUI(invalidValues, errorZero);
		return false;
	}
	
	return true;
}

function fnExel()
{
	if ( (awbsLength>1) || ((flagSpaceEnter) && (awbsLength==2)) )
	{
		
		// + brandText+"."
		updateUI( toomanyInput, pleaseEnter + " " + onlyOne + " ");
		return false;
	}
	if (isZeroValue())
	{
		
		updateUI(invalidValues, errorZero+"<br>"+correctRemove);
		return false;
	}
	return true;
}

function checkForm(form)
{
    if( typeof( form ) == "undefined" ) form = document.forms[0];
    var taval = document.getElementById("AWB").value ;
    //alert("awb before processing "+taval);
    awb=strip( taval );
    //alert("awb after processing "+awb);

    if(shipmentnumbersfield == awb){
    	awb = "";
	}
	
    if (awb=="")
    {
    	
    	updateUI( noValues, errorEmpty);
         
         return false;
    }

    var brand=document.getElementById("brand").options[document.getElementById("brand").selectedIndex].value;
    brandText = document.getElementById("brand").options[document.getElementById("brand").selectedIndex].text;
    
    awbs=new Array();
    tmp=""; iterator=0; i=0;
     
    while(iterator<awb.length)
    {
        c=awb.charAt(iterator);
        if( brand=="HBN" || brand=="CRN" ) 
        {
            if ( c !="\t" && c !="\n"  && c !="\r"  )
            {
              tmp=tmp+c;
            }
            else if (tmp!="")
            {
              awbs[i]=tmp;
              tmp="";
              i++;
            }
        }
        else
        {
            if ( c != "," && c !="\t" && c !="\n"  && c !="\r"  )
            {
              tmp=tmp+c;
            }
            else if (tmp!="")
            {
              awbs[i]=tmp;
              tmp="";
              i++;
            }
        }
        iterator++;
    }
    if (tmp!="")
    {
      awbs[i]=tmp;
    }
    
    
    awbsLength = awbs.length;
    
 
    if (brand=="")
    {
    	
    	updateUI( shipType,selectShipType );
        return false;
    }
    else if ( (brand=="DHL") && !fnDHL(form) )
    {
      return false;
    }
    else if ( (brand=="I" || brand=="R") && !fnDPEE() )
    {
      return false;
    }
    else if ( (brand=="HBN" || brand=="CRN") && !fnExel() )
    {
      return false;
    }
    else if ( (brand=="CN" || brand=="BOLN" || brand=="DOC") && !fnDanzas(brand) )
    {
      return false;
    }

    flagSpaceEnter = false;
    
    //Added By sawan on 11th May for cookie fix
    dd=new Date();
    ms=dd.getTime()+600*86400000;
    dd.setTime(ms);
    days=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    mons=new Array("Jan","Tue","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
    if( typeof( dd.getFullYear ) != "undefined" ) year=dd.getFullYear();
    else { year=dd.getYear(); if( year < 1900 ) year+=1900; }
    year+="";
    expire=days[dd.getDay()]+", "+zpad(dd.getDate())+"-"+mons[dd.getMonth()]+"-"+year.substring(2,year.length)+" 00:00:00 GMT";
    setCookie( "AWBS", awb, expire );
    setCookie( "BRAND", document.getElementById("brand").options[document.getElementById("brand").selectedIndex].text, expire );
  //End add By sawan on 11th May for cookie fix
    
    return true;
}

function zpad(num)
{
 return ((num<10)?"0"+num:num);
}

function getCookie(Name)
{
 var search = Name + "="
 if (0 < document.cookie.length)
 {
  offset = document.cookie.indexOf(search) 
  if (offset != -1)
  {
   offset += search.length 
   end = document.cookie.indexOf(";", offset) 
   if (end == -1) 
    end = document.cookie.length
    return unescape(document.cookie.substring(offset, end))
  } 
 }
 return "";
}
function setCookie(name, value, expire) {
 document.cookie = name + "=" + escape(value)
 + ((expire == null) ? "" : ("; expires=" + expire))
}


function trackSubmit(form)
{
  //form=document.forms['trackingIndex'];
  
	if (!checkForm(form) )
	{
	  return false;
	}
	return true;
}


function fnCheckEnter( event, form )
{
	//clear the error message  present on screen
	document.getElementById("errorDiv").innerHTML=" ";
    if( event.keyCode == "13" || event.keyCode == "44" )
    {
    	
        trackSubmit(form);
    }
}

//below written js is used in tracking result page
//function use to resolve true duplicate  shipment
function showDetailsResolveDuplicate(idis)
{
////alert("showDetailsResolveDuplicate and id is :"+idis);
var  aString = idis.split("*");
var valueReturned1 = aString[0];
var radioID = aString[1];
var maxSize = aString[2];
//alert("resolveDuplicate"+radioID);
document.getElementById("resolveDuplicate"+radioID).style.display = "block";
//alert("duplicate resolved :"+idis);

}

function hideDetailsResolveDuplicate(idis)
{ 
//alert(" inside hideDetailsResolveDuplicate with id is :"+idis);
//added by suresh for new 
var  aString = idis.split("*");
var valueReturned1 = aString[0];
var radioID = aString[1];
// alert(" inside hideDetailsResolveDuplicate with radioID  :"+radioID );
var maxSize = aString[2];
//alert("resolveDuplicate"+radioID);
document.getElementById("resolveDuplicate"+radioID).style.display = "block";
 
//document.getElementById("newRadioId").value = document.getElementById("newRadioId").value + "~" +idis;



}

//for enabling the resolve button

function enableButton(buttonId)
{

	//alert(" hi inside enable the resolve button: "+buttonId);
	 var noOfDuplicateCount = document.getElementById("noOfDuplicate").value ;
	 for( var i = 0; i < noOfDuplicateCount ;i++)
	 {
	     if(i!= buttonId)
	     {   
	    	 //alert(" ** enable the resolve button: "+buttonId);  
	      	document.getElementsByName(i)[0].disabled=true;
	     }
	     else
	     {
	        document.getElementsByName(buttonId)[0].disabled=false;
	     }
	 }
}

function clickRadio(group)
{ 

	 //alert(" inside click radio grup:"+group);
var valueReturned ;
var groupId = null ;
var length = document.getElementsByName("radio1").length;

for (i=0; i < length; i++) 
{     
     if (document.getElementById("resolveDulicate" + i).checked) 
 {
     valueReturned  = document.getElementById("resolveDulicate" + i).value;
     //alert(" valueReturn :"+valueReturned);
     var sString    = valueReturned.split("#");
     //alert(" sString[0] :"+sString[0]);
     //alert(" sString[1] :"+sString[1]);
     var tString    = sString[1];
     //alert(" tString :"+tString);
     var uString    = tString.split("`");
     //alert(" uString[0] :"+uString[0]);
     //alert(" uString[1] :"+uString[1]);
     
     groupId        = uString[1];
     document.getElementById("resolveDulicate" + i).checked = false ;
         break;
 }
 
   //  alert(" inside click radio grupid:"+groupId);

}

if(groupId == group)
{
	  //alert(" both are same ");
	  //alert(" value returned  to resolve Shipment fun: "+valueReturned);
   resolveShipment(valueReturned);
   
}

else
{       

   if(groupId == null)
   {
 	  //alert(" grup id is null ");
       return false;
   }
   if(groupId != group)
       {
 	 //alert(" both are not  same ");
          
           return false;
       }
   //alert(" both are not  same ");
       return false;
}

}

function resolveShipment(valueReturned) {  
	//alert("inside resolveShipment with value:"+valueReturned);
	var id             = null;
	var aString        = valueReturned.split("*");
	var valueReturned1 = aString[0];
	//alert("inside resolveShipment with idis:"+valueReturned1);
	var radioID        = aString[1];
	var bString        = aString[2];
	var idAll          = valueReturned1.split("|");
	var awbNo          = idAll[0];
	//alert("inside resolveShipment with awbNo:"+awbNo);
	var oString        = bString.split("#");
	var maxSize        = oString[0];
	//alert("inside resolveShipment with maxSize :"+maxSize );
	var groupandError  = oString[1];
	var sString        = groupandError.split("`");
	var groupId        = sString[1];
	var errorFlag      = sString[0];
	//alert("inside resolveShipment with groupId :"+groupId );
	
	if( errorFlag == "true")
{      
   
   
   //display error message for duplicate error
   document.getElementById("errorDiv").style.display="block";
}
if( errorFlag == "false")
{

	  
	document.getElementById("incrementForDuplicate").value = parseInt(document.getElementById("incrementForDuplicate").value) + 1;

	//alert("inside resolveShipment with incrementForDuplicate flag :"+document.getElementById("incrementForDuplicate").value );
	//for(var i=0; i<maxSize ;i++) {
		id = awbNo+"$"+ groupId ;
	//alert("radio button gruop id:"+id);
		document.getElementById(id).style.display = "none";
	//}
	var totalCount = document.getElementById("noOfDuplicate").value;
	//alert("noOfDuplicate in shipment:"+totalCount);
	var totalWithoutDupli = document.getElementById("totalCount").value;
	//alert("totalWithoutDupli in shipment:"+totalWithoutDupli);
	
	document.getElementById("incrimentDuplicate").value = parseInt(document.getElementById("incrimentDuplicate").value) + 1;

 //alert("no of dulicate present in shipment :"+document.getElementById("noOfDuplicate").value);
 //alert("no of dulicate resolved so for :"+document.getElementById("incrimentDuplicate").value);
 
	if(document.getElementById("noOfDuplicate").value == document.getElementById("incrimentDuplicate").value )
	{
	 //resolve duplicate header 
	 //ResolveDuplicateHeader
	 //alert("hi suresh");
	 document.getElementById("ResolveDuplicateHeader").style.display = "none";
	 document.getElementById("ShowAllWithDuplicate").style.display = "block";
	}
	if( totalWithoutDupli ==0&& totalCount>0 && document.getElementById("incrimentDuplicate").value >0)
	{
		//alert(" hi suresh show all link enabled ");
		document.getElementById("showalllinkforduplicate").style.display = "block";
	}
	if(groupId == 0)
	{
		//alert("hi suresh");
		//alert(document.getElementById("ResolveDuplicateHeader").style.position);
		document.getElementById("ResolveDuplicateHeader").style.position = "relative";
	}
	//remove error message header from single duplicate query
	if(document.getElementById("noOfDuplicate").value == 0)
	{
		//alert(" in side single duplicate header is removed if");
		document.getElementById("ResolveDuplicateHeader").style.display = "none";
	}
	
	if(document.getElementById("totalCount").value == 0 && document.getElementById("noOfDuplicate").value == 0 )
	{
	 //alert(" go to showDetailsResolveDuplicate valueReturned:"+valueReturned);
	 
	   showDetailsResolveDuplicate(valueReturned);
	   
	}
	
	else
	{

	//alert(" go to hideDetailsResolveDuplicate valueReturned:"+valueReturned);
	//document.getElementById("ResolveDuplicateHeader").style.display = "none";
	 hideDetailsResolveDuplicate(valueReturned);
	
	}
} 
}

//start changes by suresh

function ChengeTheAction( action )

{
    //alert(" hi inside the ChengeTheAction");
   //var brandid ="brand_"+uniqueid;
 // alert("brandid___>"+brandid);
	 var brand =document.getElementById("brand").options[document.getElementById("brand").selectedIndex].value;
	//alert("brand---->"+brand);

	 if(!(brand=="I" || brand=="R" ||brand=="DHL"))
	 {
		 var newaction = action+".html" 
		//var formname = "trackingIndex_fast_"+uniqueid;
		// alert("old action---->"+ document.trackingIndex.action );
		 document.trackingIndex.action = newaction;

		 //alert("modefied action ---->"+document.trackingIndex.action );
	 }
}
//end changes by suresh


function initForm(form)
{
  var awbVal = getCookie("AWBS");
  
  if( fnTrim(awbVal,2) != "" )
  {
	  form.AWB.value=awbVal;
	  if ( form.brand.options[0].text != "Please Select" )
	  {
	    BRAND = getCookie("BRAND");//form.brand.options[form.brand.selectedIndex].value ;
	    brandlength = form.brand.length;
	    for ( j=0 ; j < brandlength ; j++ )
	    {
	      if ( form.brand.options[j].text == BRAND )
	      {
	        form.brand.options[j].selected = true;
	        break;
	      }
	    }
	  }  
  }
  
}

