﻿// JScript File

//------------------for fetching port , subport and service of respective port in parameter search---------------
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  

//var XmlHttp;

//function CreateXmlHttp(){
//	//Creating object of XMLHTTP in IE
//	try{
//		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
//	   }
//	catch(e){
//		try{
//			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
//		   } 
//		catch(oc){
//			XmlHttp = null;
//		   }
//	   }	   
//	//Creating object of XMLHTTP in Mozilla and Safari 
//	if(!XmlHttp && typeof XMLHttpRequest != "undefined"){
//		XmlHttp = new XMLHttpRequest();
//	  }
//	  alert(XmlHttp);
//  }
  
function ajax4SCookies()
{
var TotalNo=document.getElementById("txtNoOfCheckBox").value;
var tmpSelectedId="";

    if(TotalNo != 0)
    { 

            for(var i=0,k=0;i<TotalNo;i++)
            {
                var cname="chkBox"+i;
                if((document.getElementById(cname) != null) && document.getElementById(cname).checked == true)
                {   k++;
                    if((k>1 ))
                    {
                        tmpSelectedId+=",";
                    }
                        tmpSelectedId+=document.getElementById(cname).value;
                }
             }
            
            CreateXmlHttp();
            
            if(XmlHttp){
            XmlHttp.onreadystatechange=AddSCookey;
            XmlHttp.open("GET", "Cookeypage.aspx?CT=O&CE=" + encodeURIComponent(tmpSelectedId) , false);
            XmlHttp.send(null);
                    }
    }
}

function AddSCookey()
{
if(XmlHttp.readyState==4)
   {
        if(XmlHttp.status==200)
        {
             //alert(XmlHttp.responseText);
             
            if(XmlHttp.responseText=='Success'){
            alert('Port added in MyExxonMobilPorts');
            } else if(XmlHttp.responseText=='Error'){
                alert('Error in retrieving data');
            } else if(XmlHttp.responseText=='Exist'){
               alert('Port already present in MyMobilPortList');
            }
        }
        else
        {
        alert('Error in retrieving data');
        }
    }
}

function FetchPSport(tmpId)
{
// for storing selected Id in hidden field
 document.getElementById('tmpStId').value=tmpId; 
 var tmpObj=document.getElementById('tmpStId').value;
 var tmpDivNm="myDiv"+tmpObj;
 var tmpDivObj=document.getElementById(tmpDivNm);
    if(tmpDivObj.visible == true)
    {
    tmpDivObj.visible=false;
    }else
    {
    tmpDivObj.visible=true;
    }

if(tmpDivObj.visible == true)
{
	// URL to get data from server
	var requestUrl = "dispMSPortDetail.aspx?strId=" + encodeURIComponent(tmpId) ;
	CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp){ 
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = LoadPSport;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("Get", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	 }
 }else
 { tmpDivObj.innerHTML=""; }
 
 }

function LoadPSport(){
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4){
	var a = XmlHttp.responseText;
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200){		
		//Save successfully
		if(a.length>0)
		{
		    addPSport(a);
		    return true;
		}
		else{
			alert("There was a problem retrieving data from the server. Please try again!" )
			return false;
		 }
		 }
		else{
			alert("There was a problem retrieving data from the server. Please try again!" )
			return false;
		 }
	  }
  }

function addPSport(str)
{
   var strRowValue = str.split(',');
   var tmpGetSubPort = strRowValue[0];
   var tmpGetSubService = strRowValue[1];
   
   var tmpObj=document.getElementById('tmpStId').value;
   var tmpDivNm="myDiv"+tmpObj;
   var tmpDivObj=document.getElementById(tmpDivNm);
   tmpDivObj.innerHTML="";
   var ll=0,lll=0;
   tmpStringHTML="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
   tmpStringHTML +="<tr><td height=\"1\" colspan=\"3\" bgcolor=\"CDCDCD\"><img src=\"images/blank.gif\" width=\"1\" height=\"1\" alt=\"\" /></td></tr>";
   tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"font-weight: bold\" class=\"innersubhead1\"> Sub Port Name </td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"></td></tr>";
    var tmpGetSubPortF=tmpGetSubPort.split('~');
    for(var i=0;i< tmpGetSubPortF.length;i++)
    {
    if(tmpGetSubPortF[i]=="-")
    { ll=5; }
    tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpGetSubPortF[i]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"></td></tr>";
    }
    tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"font-weight: bold\" class=\"innersubhead1\"> Port Services </td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"></td></tr>";
    var tmpGetSubServiceF=tmpGetSubService.split('~');
    for(var j=0;j< tmpGetSubServiceF.length; j++)
    {
        var tmpSplitSubService=tmpGetSubServiceF[j].split('=');
        if(tmpSplitSubService[0]=="-" || tmpSplitSubService[0]== "")
        {
            tmpSplitSubService[1]="";
        }    
        if(tmpSplitSubService[0]=='Lead Time')
        {
            if(tmpSplitSubService[1] != 0)
            {
                tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">"+tmpSplitSubService[1]+" Days"+"</td></tr>";
            }
        }
        else if(tmpSplitSubService[0]=='Hours Of Operation')
        {
            tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"&nbsp;&nbsp;<img src=\"images/watch.gif\" width=\"10\" height=\"10\" alt=\"\"/></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">"+tmpSplitSubService[1]+"</td></tr>";
        }
        else if(tmpSplitSubService[0]=='Star Rating')
        {
            if(tmpSplitSubService[1]==1)
            {
                tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"3%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/></td></tr>";
            }
            if(tmpSplitSubService[1]==2)
            {
                tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/></td></tr>";
            }
            if(tmpSplitSubService[1]==3)
            {
                tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/></td></tr>";
            }
            if(tmpSplitSubService[1]==4)
            {
                tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"3%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/></td></tr>";
            }
            if(tmpSplitSubService[1]==5)
            {
                tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/></td></tr>";
            }
            if(tmpSplitSubService[1]==6)
            {
                tmpStringHTML +="<tr><td width=\"30%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\"><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/><img src=\"images/b_star.gif\" width=\"8\" height=\"8\" alt=\"\"/></td></tr>";
            }
        }
        else
        {
            if(tmpGetSubServiceF[j]=="-")
            { ll=5; }
            if(tmpGetSubServiceF[j]!= "")
            { 
            tmpStringHTML +="<tr><td width=\"10%\" align=\"left\" class=\"innersubhead1\"></td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">&nbsp;&nbsp;&nbsp;&nbsp;"+tmpSplitSubService[0]+"</td><td width=\"35%\" align=\"left\" style=\"color:#0066C0\"  class=\"innersubhead1\">"+tmpSplitSubService[1]+"</td></tr>";
            }
        }
    }
   tmpStringHTML +="</table>"; 
   tmpDivObj.innerHTML=tmpStringHTML;
}
//------------------------------------------------ End of the Section -------------------------------------------

//-------------------------------------------for the page search_Result.aspx----------------------------------------

function doCheckCheckBox()
{
    var TotalNo=document.getElementById("txtNoOfCheckBox").value;
    var tmpSelectedId="";
    if(TotalNo != 0)
    {
        for(var i=0,k=0;i<TotalNo;i++)
        {
        var cname="chkBox"+i;
            if((document.getElementById(cname) != null) && document.getElementById(cname).checked == true)
            {k++;
                if((k>1 ))
                {
                    tmpSelectedId+=",";
                }
                    tmpSelectedId+=document.getElementById(cname).value;
            }
        }
        if(tmpSelectedId !="" && k>1 ){
            //document.getElementById("frmSearchResult").action="ComparePorts.aspx?pstring=" + tmpSelectedId ;
            //document.getElementById("frmSearchResult").method="Post";
            //document.getElementById("frmSearchResult").submit();
            document.location.href="ComparePorts.aspx?Splatform=result&pstring=" + tmpSelectedId;
            }
        else
        {alert("Select atleast two port for Compare");
        }
        
     }
}

//------------------------------------------------ End of the Section -------------------------------------------

//-------------------------------------------for the page search_parameter.aspx----------------------------------------

function checkExistingString(inpString)
{
  var num = (document.getElementById('inSt').value-1)+2;
  for(var i=1,j=0;i<num;i++)
  {
  var txtNm="tmpMyDiv"+ i
  var txtObj=document.getElementById(txtNm);
      if(document.getElementById(txtNm) != null && txtObj.value==inpString)
      {
        j=5;
      }
  }
  if(j==5)
  {
    return true;
  }else
  {
    return false;
  }
}

function doAdd_Element()
{
var cmbdD1=document.getElementById('dDl');
var tmpPstring=cmbdD1.options[cmbdD1.selectedIndex].text;
var tmpPId=cmbdD1.value;
var cmbCondition=document.getElementById('cmbCondition');
var tmpcmbCondition=cmbCondition.options[cmbCondition.selectedIndex].text;
var tV1=document.getElementById("txtValue");
var tmpValue=(tV1.value).replace(/^\s+/,'').replace(/\s+$/,'');
var isValid=true;

if(tV1.type=="text"){tV1.value =tmpValue;}
if(cmbdD1.value=="Select"){
    alert("Please select a value for Parameter");
    cmbdD1.focus();   
}
else if(cmbCondition.value=="Select"){
    alert("Please Select a value for Condition");
    cmbCondition.focus();   
}
else if(tV1.type=="text" && tV1.value =="") {
    alert("Please enter a value in Input box");
    tV1.focus();   
 }
else if(tV1.type !="text" && tV1.value =="Select") {
 alert("Please Select a value in Input box");
 tV1.value="Select";
 tV1.focus(); 
 } 
 else if(tV1.value ==''){
    alert("User Inputs Field is essential for search !!! Don\'t leave it Blank");
    tV1.focus();   
  }
 
 else{ 
 if(cmbCondition.value ==" like ") {var tmpPPstring=tmpPId+' '+cmbCondition.value+" \'%"+tmpValue+"%\'"; } 
 else if(cmbCondition.value ==" likeB "){var tmpPPstring=tmpPId+" like \'"+tmpValue+"\%'";} 
 else if(cmbCondition.value ==" likeE "){var tmpPPstring=tmpPId+" like \'%"+tmpValue+"\'";} 
 else if(IsNumeric(tV1.value))
 {
  if (tmpPstring == "Minimum Bulk Requrement Truck Per Grade(Lt)")
                   {
                        StrExc = "(e.portproductsignal=1 and e.bulkmintruckgrade" +" "+cmbCondition.value+" "+tmpValue+" ))";
                         var tmpPPstring = "(" + tmpPId+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                   else if (tmpPstring == "Minimum Bulk Requrement Barge Per Grade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.bulkminbargegrade" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        var tmpPPstring = "(" + tmpPId+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                    else if (tmpPstring == "Minimum Bulk Requrement Truck Aggregade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.bulkmintruckaggr" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        var tmpPPstring = "(" + tmpPId+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                    else if (tmpPstring == "Minimum Bulk Requrement Barge Aggregade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.bulkminbargeaggr" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        var tmpPPstring = "(" + tmpPId+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                    else if (tmpPstring == "Minimum Pack Volume Aggregade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.minpackedvol" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        var tmpPPstring = "(" + tmpPId+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                    else if (tmpPstring == "Minimum Combined Volume Aggregade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.combinedminvol" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        var tmpPPstring = "(" + tmpPId+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                   else
                   {                  
                    //tmpSelectedStringVar += tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" ";
                     var tmpPPstring=tmpPId+" "+cmbCondition.value+" "+tmpValue+" ";}
                    }
 
 
 
 
 
 //var tmpPPstring=tmpPId+" "+cmbCondition.value+" "+tmpValue+" ";}
 else if(cmbCondition.value==" = "){var tmpPPstring=tmpPId+" "+cmbCondition.value+" \'"+tmpValue+"\'";}
 else if(cmbCondition.value ==" < "){
       alert('Please enter a numeric value');
       if(tV1.type=="text"){tV1.value ="";}
       isValid=false;
       tV1.focus();    
   }  
 
 if (isValid){ 
   if(checkExistingString(tmpPId) == false && tmpPId != "Select" && cmbCondition.value != "Select")
    {
     var numi = document.getElementById('inSt');
     var num = (document.getElementById('inSt').value -1)+ 2;
     numi.value = num;
     var ni = document.getElementById('frmDiv1');
     var newdiv = document.createElement('div');
     var divIdName = 'MyDiv' + num;
     newdiv.setAttribute('id',divIdName);

     var strString="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
     strString=strString+"<td width=\"30%\" class=\"tdflx\" style=\"height:35px;\">"+tmpPstring+"</td>";
     strString=strString+"<td width=\"20%\" class=\"tdflx\">"+tmpcmbCondition+"</td>";
     strString=strString+"<td width=\"28%\" class=\"tdflx\">"+tV1.value+"</td>"
     strString=strString+"<td width=\"22%\" class=\"tdflxR\" align=\"center\"><a class=\"b-removeprod\" href=\"javascript:remove_Element("+divIdName+ ");\"> Remove criteria </a></td>";
     strString=strString+"</tr></table>";
     strString=strString+"<input id=\"txt"+ divIdName + "\" type=\"hidden\" value=\""+tmpPPstring+"\" />";
     strString=strString+"<input id=\"tmp"+ divIdName + "\" type=\"hidden\" value=\""+tmpPId+"\" />";
     newdiv.innerHTML =newdiv.innerHTML +strString;
     ni.appendChild(newdiv);
     cmbdD1.value="Select";
     cmbCondition.value="Select";
     if(tV1.type=="text"){tV1.value ="";}
     else{tV1.value="Select";}
     
     FetchCountVal();
  }else{
     alert("Existing Condition already available \nso Please remove it First and then Add");
     tV1.focus();
    }
  }  
  }  
}


function IsNumeric(expression)
{
    var nums = "0123456789";
    if (expression.length==0)return(false);
        for (var n=0; n < expression.length; n++)
        {
            if(nums.indexOf(expression.charAt(n))==-1)
            {return(false);}
        }
            return(true);
}


function B8() 
{ 
this.ver=navigator.appVersion;this.agent=navigator.userAgent; 
this.dom=Y7.getElementById?1:0; 
this.opera5=this.agent.indexOf("Opera 5")>-1; 
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0; 
this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0; 
this.ie4=(Y7.all && !this.dom && !this.opera5)?1:0; 
this.ie=this.ie4||this.ie5||this.ie6||this.ie7; 
this.mac=this.agent.indexOf("Mac")>-1; 
this.ns6=(this.dom && parseInt(this.ver)>=5)?1:0; 
this.ns4=(Y7.layers && !this.dom)?1:0; 
this.bw=(this.ie7||this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5); 
return this; 
} 



function remove_Element_NewSearch() 
{
var rname;
var d;
var olddiv ;
rname="";
this.ver=navigator.appVersion;this.agent=navigator.userAgent; 
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
   // var arr = (ie5 ? document.all.tags('div') : document.getElementByTag('div'));
   //var arr=document.getElementByTag('DIV');
   var arr=document.all.tags('div');
   for (i = 0; i < arr.length; i++) 
    {
        var sname=arr[i].id;
       // alert(sname);
    if (sname.substring(0,5) == 'MyDiv') 
    {
        if(rname=="")
        {
          rname+=  sname;
          }
          else {
           rname+= "," + sname;
          }
     }
    }
    if(rname !="")
    {
    d = document.getElementById("frmDiv1");
    arr=rname.split(",");
        for (i = 0; i < arr.length; i++) 
        {
              olddiv = document.getElementById(arr[i]);
              d.removeChild(olddiv);
        }
     }  
   document.getElementById("inSt").value="0";
   var tmpCountDiv=document.getElementById("spanCountArea");
   tmpCountDiv.innerHTML="";
}

//function remove_Element() 
//{
//var numVar = document.getElementById('inSt');
//var num = numVar.value;
// for(i=1;i<=num && num >0;i++)
//  {
//  var cname="checkbox"+i;
//    if((document.getElementById(cname) != null) && document.getElementById(cname).checked == true)
//    { 
//    var divIdName = "MyDiv" +i;
//      var d = document.getElementById("frmDiv1");
//      var olddiv = document.getElementById(divIdName);
//      d.removeChild(olddiv);
//      if(document.getElementById("inSt").value >0)
//      {
//        document.getElementById("inSt").value=document.getElementById("inSt").value -1;
//      }
//    }
//   }
//}
function remove_Element(divIdName) 
{
//var numVar = document.getElementById('inSt');
//var num = numVar.value;
// for(i=1;i<=num && num >0;i++)
//  {
  //var cname="button"+i;
  //alert(divIdName);
    //if((document.getElementById(divIdName) != null))
    //{ alert(divIdName);
//    var divIdName = "MyDiv" +i;
      var d = document.getElementById("frmDiv1");
      var olddiv = document.getElementById(divIdName);
      //d.removeChild(olddiv);
      d.removeChild(divIdName);
      divIdName.innerhtml="";
      FetchCountVal();
    //  if(document.getElementById("inSt").value >0)
     // {
    //    document.getElementById("inSt").value=document.getElementById("inSt").value -1;
    //  }
    //}
   //}
}
function doSearch()
{
var numVar = document.getElementById("inSt");
var num = numVar.value;
var tmpSelectedStringVar="";
var StrExc='';
var tmpIdObj=document.getElementById("dDl");
var tmpIdVar=document.getElementById("dDl").value;
var tmpIdVar1=tmpIdObj.options[tmpIdObj.selectedIndex].text;
var cmbCondition=document.getElementById("cmbCondition");
var tmpcmbCondition=cmbCondition.options[cmbCondition.selectedIndex].text;
var tV1=document.getElementById("txtValue");
var tmpValue=(tV1.value).replace(/^\s+/,'').replace(/\s+$/,'');
if(cmbCondition.value==" < " && (IsNumeric(tmpValue)==false))
{
    alert('Enter a numeric value');
    tV1.value="";
    return ;
}
//tV1.value=tmpValue;
 var sname;
    var divIdName;
    this.ver=navigator.appVersion;this.agent=navigator.userAgent; 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
  /*  var arr=document.all;
    
   for (i = 0; i < arr.length; i++) 
    {
        sname=arr[i].id;
        if (sname.substring(0,8) == 'txtMyDiv') 
        {
             if(tmpSelectedStringVar.length>0)
                {
                    tmpSelectedStringVar+=" and ";
                }
                divIdName = sname;
//alert(sname);
                if(document.getElementById(divIdName) != null)
                {
                var tmpSelectedString=document.getElementById(divIdName).value;
                }
                tmpSelectedStringVar += tmpSelectedString;
          }
      }*/


 for(i=1;i<=num && num >0;i++)
  {
      if(i>1)
        {
            tmpSelectedStringVar+=" and ";
        }
        var divIdName = "txtMyDiv" +i;
        var tmpSelectedString=document.getElementById(divIdName).value;
        tmpSelectedStringVar += tmpSelectedString;
  }
  
 // alert(tmpSelectedStringVar);
   if(tmpSelectedStringVar !="" && tmpValue != "" && tmpValue != "Select" && tmpValue != "Select" && num>0)
  {
     tmpSelectedStringVar+=" and ";
  }
  if(tmpIdVar != "Select" && cmbCondition.value==" like " && tmpValue !='' && tmpValue !="Select")
  {
    tmpSelectedStringVar += tmpIdVar+" "+cmbCondition.value+" \'%"+tmpValue+"%\'";
  }else if(tmpIdVar != "Select" && cmbCondition.value==" likeB " && tmpValue !='' && tmpValue !="Select") 
  {
    tmpSelectedStringVar += tmpIdVar+" like \'"+tmpValue+"%\'";
  }else if(tmpIdVar != "Select" && cmbCondition.value==" likeE " && tmpValue !='' && tmpValue !="Select") 
  {
    tmpSelectedStringVar += tmpIdVar+" like \'%"+tmpValue+"\'";
  }else{
        //alert(tmpIdVar1);
      if(tmpIdVar1 != "Select" && cmbCondition.value !="Select"  && IsNumeric(tmpValue))
      {
      
                   if (tmpIdVar1 == "Minimum Bulk Requrement Truck Per Grade(Lt)")
                   {
                        StrExc = "(e.portproductsignal=1 and e.bulkmintruckgrade" +" "+cmbCondition.value+" "+tmpValue+" ))";
                         tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                   else if (tmpIdVar1 == "Minimum Bulk Requrement Barge Per Grade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.bulkminbargegrade" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                    else if (tmpIdVar1 == "Minimum Bulk Requrement Truck Aggregade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.bulkmintruckaggr" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                    else if (tmpIdVar1 == "Minimum Bulk Requrement Barge Aggregade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.bulkminbargeaggr" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                    else if (tmpIdVar1 == "Minimum Pack Volume Aggregade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.minpackedvol" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                    else if (tmpIdVar1 == "Minimum Combined Volume Aggregade(Lt)")
                   {
                        StrExc="(e.portproductsignal=1 and e.combinedminvol" +" "+cmbCondition.value+" "+tmpValue+" ))";
                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
                   }
                   else
                   {tmpSelectedStringVar += tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" ";}
      }
      else if(tmpIdVar != "Select" && cmbCondition.value !="Select"  && tmpValue !="Select" && tmpValue !="")
      {
       tmpSelectedStringVar += tmpIdVar+" "+cmbCondition.value+" \'"+tmpValue+"\'";
      }
  }
  if(tmpSelectedStringVar != "" && (checkExistingString(tmpIdVar)==false ||tmpValue =="" ||tmpValue == "Select"))
  {
  var encodedInputString=escape(tmpSelectedStringVar);
  encodedInputString=encodedInputString.replace("+", "%20");
  encodedInputString=encodedInputString.replace("/", "%2F"); 
  document.getElementById("frmSearchParameter").action="search_Result.aspx?Splatform=Flex&PortString="+encodedInputString;
  document.getElementById("frmSearchParameter").method="Post";
  document.getElementById("frmSearchParameter").submit();
//  alert((tmpSelectedStringVar));

  }else if(checkExistingString(tmpIdVar)==true)
  {  
  alert("Existing Condition already available \nso Please remove it First then Search");
  }else if(tmpSelectedStringVar == "")
  {
    alert("No any condition for Search. \n So create condition First then Search");
    document.getElementById('dDl').focus();
    document.getElementById('dDl').value="Select";
    cmbCondition.value="Select";
    if(tV1.type=="text")
    {
    tV1.value="";
    }else
    {
    tV1.value="Select";
    }
  }
}
//------------------------------------------------ End of the Section -------------------------------------------

//-----------------------------Function for displaying combo and Text box alternatively-----------------------

function doShowOrNot()
{
    var tmpObj=document.getElementById("dDl");
    var tmpCountDiv=document.getElementById("spanCountArea");
       tmpCountDiv.innerHTML="";
    var tmpCmbObj="<select id=\"cmbCondition\" class=\"normalgrey\" style=\"width:150px;\">";
    tmpCmbObj +="<option id=\"Option1\" value=\"Select\"> - Select - </option>"
    var tmpStrId=tmpObj.options[tmpObj.selectedIndex].id ;
    var tmpObj2=document.getElementById("CmbCondDiv");
    tmpObj2.innerHTML=="";
    
    if(tmpStrId =='2' || tmpStrId =='3' ||tmpStrId =='5' ||tmpStrId =='1')
    {
            tmpCmbObj += "<option value=\" likeB \"> Begins with  </option>";
            tmpCmbObj += "<option value=\" likeE \">  Ends with   </option>";
            tmpCmbObj += "<option value=\" like \"> Contains  </option>";
    }else if((tmpStrId >12 && tmpStrId  < 19)||tmpStrId =='9')
    {
            tmpCmbObj += "<option value=\" &lt; \"> Less than </option>";
            tmpCmbObj += "<option value=\" = \"> Equal to  </option>";
    }else
    {
        tmpCmbObj += "<option value=\" = \"> Equal to  </option>";
    }
    tmpCmbObj +="</select>";
    tmpObj2.innerHTML=tmpCmbObj;
    document.getElementById("tmpTxtCmbDiv").innerHTML="";
    
    if(tmpStrId =='7'|| tmpStrId =='8' || tmpStrId =='10' ||tmpStrId =='11' ||tmpStrId =='12'||tmpStrId =='19'||tmpStrId =='20'||tmpStrId =='21'||tmpStrId =='22' )
    {
            FetchMultiOpt();
    }else
    {
        document.getElementById("tmpTxtCmbDiv").innerHTML="<input id=\"txtValue\" name='txtValue' type=\"text\" class=\"normalgrey\" size=\"40\" value='' onblur='javascript:doCheckMinmVol()' />";
    }
}
function doCheckMinmVol()
{
var tmpObj=document.getElementById("dDl");
var tV1=document.getElementById("txtValue");
var tmpStrId=tmpObj.options[tmpObj.selectedIndex].id ;
   if((parseInt(tV1.value) < 2000) && (tmpStrId =='13' || tmpStrId =='14'))
    {
        alert("Number Should be Not Less than 2000");
        tV1.value="";
        tV1.focus();
    }
     if((parseInt(tV1.value) < 4000)  && (tmpStrId =='15' || tmpStrId =='16'))
    {
        alert("Number Should be Not Less than 4000");
        tV1.value="";
        tV1.focus();
    }
        if((parseInt(tV1.value) < 2)  && (tmpStrId =='9'))
    {
        alert("Number Should be Not Less than 2");
        tV1.value="";
        tV1.focus();
    }
}

function FetchMultiOpt()
{
// for storing selected Id in hidden field
    var tmpObj=document.getElementById("dDl");
    var tmpStrId=tmpObj.options[tmpObj.selectedIndex].id ;
	// URL to get data from server
	var requestUrl = "dispMultiOption.aspx?strId=" + encodeURIComponent(tmpStrId);
	CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	 { 
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = LoadMultiOpt;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("Get", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	 }
}
function LoadMultiOpt()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
    	var a = XmlHttp.responseText;
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{		
		//Save successfully
		    if(a.length>0)
		    {
		        addMultiOpt(a);
		        return true;
		    }
		    else{
			    alert("There was a problem retrieving data from the server. Please try again!" );
			    return false;
		     }
	    }
	    else
	    {
		    alert("There was a problem retrieving data from the server. Please try again!" );
		    return false;
	    }
  }
}
function addMultiOpt(str)
{
    var tmpObj=document.getElementById("tmpTxtCmbDiv");
    tmpObj.innerHTML="";
    var tmpStrArr=str.split(',');
    var tmpString="";
    tmpString="<select id=\"txtValue\" class=\"normalgrey\" >";
    tmpString +="<option value=\"Select\"> - Select - </option>"
    for(i=1;i< tmpStrArr.length ;i++)
    {
    tmpString +="<option value=\""+tmpStrArr[i]+"\">"+tmpStrArr[i]+"</option>";
    }
    tmpString += "</select>";
    tmpObj.innerHTML=tmpString;
    //alert(tmpString);
}
//----------------------------------------------- End of the Section ------------------------------------------
//---------------------------------------------------- New Section --------------------------------------------
function doCreateQueryStringParameter()
{
//    var tmpObj=document.getElementById('dDl');
//    var tmpStrId=tmpObj.options[tmpObj.selectedIndex].id ;
    //alert(tmpStrId);
    var numVar = document.getElementById('inSt');
    var num = numVar.value;
    var tmpSelectedStringVar="";
    var tmpIdVar=document.getElementById('dDl').value;
    //alert(tmpStrId);
    var cmbCondition=document.getElementById('cmbCondition');
    var tmpcmbCondition=cmbCondition.options[cmbCondition.selectedIndex].text;
    var tV1=document.getElementById("txtValue");
    var tmpValue=(tV1.value).replace(/^\s+/,'').replace(/\s+$/,'');
    var StrExc="";
    if(tV1.type=="text")
    {
        tV1.value=tmpValue;
    }
    
    var sname;
    var divIdName;
    this.ver=navigator.appVersion;this.agent=navigator.userAgent; 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
    //var arr=document.all;
    var tmpSelectedString="";
    for(i=1;i<=num && num >0;i++)
  {
      if(i>1)
        {
            tmpSelectedStringVar+=" and ";
        }
        var divIdName = "txtMyDiv" +i;
        var tmpSelectedString=document.getElementById(divIdName).value;
        tmpSelectedStringVar += tmpSelectedString;
  }/*
   for (i = 0; i < arr.length; i++) 
    {
        sname=arr[i].id;
        if (sname.substring(0,8) == 'txtMyDiv') 
        {
             if(tmpSelectedStringVar.length>0)
                {
                    tmpSelectedStringVar+=" and ";
                }
                divIdName = sname;
                if(document.getElementById(divIdName) != null)
                {
                tmpSelectedString=document.getElementById(divIdName).value;
                }
                tmpSelectedStringVar += tmpSelectedString;
          }
      }*/
    //  alert(tmpIdVar);
      if(tmpSelectedStringVar !="" && tmpValue != "" && tmpValue != "Select" && tmpValue != "Select" && num>0)
      {
         tmpSelectedStringVar+=" and ";
      }
      
      if(tmpIdVar != "Select" && cmbCondition.value==" like " && tmpValue !="" && tmpValue !="Select")
      {
        tmpSelectedStringVar += tmpIdVar+" "+cmbCondition.value+" \'%"+tmpValue+"%\'";
      } else if(tmpIdVar != "Select" && cmbCondition.value==" likeB " && tmpValue !="" && tmpValue !="Select")
      {
        tmpSelectedStringVar += tmpIdVar+" like \'"+tmpValue+"%\'";
      }else if(tmpIdVar != "Select" && cmbCondition.value==" likeE " && tmpValue !="" && tmpValue !="Select")
      {
        tmpSelectedStringVar += tmpIdVar+" like \'%"+tmpValue+"\'";
      }else   
        {
        if(tmpIdVar != "Select" && cmbCondition.value !="Select"  && IsNumeric(tmpValue))
          {
          //alert(tmpIdVar);
//                    if (tmpIdVar == "Minimum Bulk Requrement Truck Per Grade(Lt)")
//                   {
//                        StrExc = "(e.portproductsignal=1 and e.bulkmintruckgrade" +" "+cmbCondition.value+" "+tmpValue+" ))";
//                         tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
//                   }
//                   else if (tmpIdVar == "Minimum Bulk Requrement Barge Per Grade(Lt)")
//                   {
//                        StrExc="(e.portproductsignal=1 and e.bulkminbargegrade" +" "+cmbCondition.value+" "+tmpValue+" )";
//                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
//                   }
//                    else if (tmpIdVar == "Minimum Bulk Requrement Truck Aggregade(Lt)")
//                   {
//                        StrExc="(e.portproductsignal=1 and e.bulkmintruckaggr" +" "+cmbCondition.value+" "+tmpValue+" )";
//                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
//                   }
//                    else if (tmpIdVar == "Minimum Bulk Requrement Barge Aggregade(Lt)")
//                   {
//                        StrExc="(e.portproductsignal=1 and e.bulkminbargeaggr" +" "+cmbCondition.value+" "+tmpValue+" )";
//                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
//                   }
//                    else if (tmpIdVar == "Minimum Pack Volume Aggregade(Lt)")
//                   {
//                        StrExc="(e.portproductsignal=1 and e.minpackedvol" +" "+cmbCondition.value+" "+tmpValue+" )";
//                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
//                   }
//                    else if (tmpIdVar == "Minimum Combined Volume Aggregade(Lt)")
//                   {
//                        StrExc="(e.portproductsignal=1 and e.combinedminvol" +" "+cmbCondition.value+" "+tmpValue+" )";
//                        tmpSelectedStringVar += "(" + tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" or "+ StrExc;
//                   }
//                   else
//                   {                  
                  tmpSelectedStringVar += tmpIdVar+" "+cmbCondition.value+" "+tmpValue+" ";
                    //}

            
          }
          else if(tmpIdVar != "Select" && cmbCondition.value !="Select"  && tmpValue !="Select" && tmpValue !="")
          {
           tmpSelectedStringVar += tmpIdVar+" "+cmbCondition.value+" \'"+tmpValue+"\'";
          }
      }
      
return tmpSelectedStringVar;
}

function FetchCountVal()
{
// for clearing messege division tag 
var inpString=document.getElementById('dDl').value;
if(checkExistingString(inpString)==false)
{
var tmpCountDiv=document.getElementById("spanCountArea");
 tmpCountDiv.innerHTML="";

// for storing selected Id in hidden field
    var tmpStrId=doCreateQueryStringParameter();
	// URL to get data from server
	if(tmpStrId != "")
	{
	var requestUrl = "dispCountPort.aspx?strValue=" + encodeURIComponent(tmpStrId);
	CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	 { 
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = LoadCountVal;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("Get", requestUrl,  true);		
		//Sends the request to server
		XmlHttp.send(null);		
	
	 }
  }else
  {   var tmpCountDiv=document.getElementById("spanCountArea");
       tmpCountDiv.innerHTML="No Condition is Created";
       return false;
  }
}
}
function LoadCountVal()
{
	// To make sure receiving response data from server is completed
	 
  var tmpCountDiv=document.getElementById("spanCountArea");	
 
	if(XmlHttp.readyState == 4)
	{
    	var a = XmlHttp.responseText;
    	
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{		
		//Save successfully
		    if(a !="")
		    {
		    tmpCountDiv.innerHTML=a +" Port found for this Search ";
		        //alert(a);
		        return true;
		    }
		    else if(a==""){
			    tmpCountDiv.innerHTML="No Port Selected. Please try again!" ;
			    return false;
		     }
	    }
	    else
	    {
		    alert("There was a problem retrieving data from the server. Please try again!" );
		    tmpCountDiv.innerHTML="";
		    return false;
	    }
  }
}
//----------------------------------------------- End of the Section -----------------------------------------
