﻿// JScript File

function ShowRssDialog(TrackingURL,rssName,Url)
{
    document.getElementById("rssLink").innerHTML = Url;
    //$('rssLink').innerHTML = Url;
    document.getElementById("rssLink").href=Url;
    document.getElementById('lblRSSNAME').innerHTML = rssName;
    if($find('ctl00_ModalPopupExtender1')==null)
        $find('ctl00_ctl00_ModalPopupExtender1').show();
    else
        $find('ctl00_ModalPopupExtender1').show();
    gPageTracker(TrackingURL);
}

function gPageTracker(url)
{
    try {
        var pageTracker2 = _gat._getTracker("UA-1118822-2");
        pageTracker2._trackPageview(url);
    } catch(err) {}
}
function HideRssDialog()
{
    if($find('ctl00_ModalPopupExtender1')==null)
        $find('ctl00_ctl00_ModalPopupExtender1').hide();
    else
        $find('ctl00_ModalPopupExtender1').hide();
}
<!-- Random Image Selector
//
// Usage:
//  RandomImage(images)
//  RandomImageLong(images,iparams)
//  RandomImageLink(images,urls)
//  RandomImageLinkLongTarget(images,urls,iparams,hparams)
//     images		is space or comma separated file list
//     urls		is space or comma separated list of url's
//     iparams		params to add to <img>
//     hparams		params to add to <a href..>

function RandomImageLong(images,iparams)
{
/* si: start index 
** i: current index
** ei: end index
** cc: current count
*/

 si = 0; 
 ci=0;
 cc=0;
 imageSet = new Array();
 ei = images.length;
  for (i=1;i<ei;i++) {
    if (images.charAt(i) == ' ' || images.charAt(i) == ',') {
      imageSet[cc] = images.substring(si,i);
      cc++;
      si=i+1;
      }
    }
  ind = Math.floor(Math.random() *cc);
  document.write("<img "+iparams+" src="+imageSet[ind]+" alt=\""+imageSet[ind]+"\">");
}

function RandomImage(images)
{
  RandomImageLong(images," ");
}

function RandomImageLinkLongTarget(images,urls,iparams,hparams)
{
/* si: start index 
** i: current index
** ei: end index
** cc: current count
*/
 imageSet = new Array();
 urlSet = new Array();
 si = 0; 
 ci=0;
 cc=0;
 ei = images.length;
  for (i=1;i<ei;i++) {
    if (images.charAt(i) == ' ' || images.charAt(i) == ',') {
      imageSet[cc] = images.substring(si,i);
      cc++;
      si=i+1;
      }
    }
  ind = Math.floor(Math.random() *cc);
 si = 0; 
 ci=0;
 cc=0;
 ei = urls.length;
  for (i=1;i<ei && cc <=ind ;i++) {
    if (urls.charAt(i) == ' ' || urls.charAt(i) == ',') {
      urlSet[cc] = urls.substring(si,i);
      cc++;
      si=i+1;
      }
    }

  //document.write("<img "+iparams+" src="+imageSet[ind]+" alt=\""+imageSet[ind]+"\">");
  document.write("<a "+hparams+" href=\""+urlSet[ind]+"\"><img "+iparams+" src="+imageSet[ind]+" alt=\""+imageSet[ind]+"\"></a>");
}

function RandomImageLinkLong(images,urls,iparams)
{
  RandomImageLinkLongTarget(images,urls,iparams,"");
}

function RandomImageLink(images,urls)
{
  RandomImageLinkLongTarget(images,urls,"border=0","");
}


function RedirectToProductPage(ProdId,ProdName)
{
    if(ProdId!="")
        location.href = "index.aspx?ProdID=" + ProdId + "&ProdNM=" + ProdName;
}


function ShowCropProductDialog(CropGroupId)
{
    if(CropGroupId!="")
    {
        imgFooter= getCropImage(CropGroupId)
        document.getElementById("imgCropProductPage").src = "/imagesV2/" + imgFooter;
        CloneCropProductTable(CropGroupId);
        $find('ctl00_ctl00_ModalPopupExtender2').show();
    }
}

function CloneCropProductTable(CropGroupId)
{
    var old_table = document.getElementById("tblpopupprodcontent");
    document.getElementById("popupprodcontent").removeChild(old_table);
    var the_table 
    if(CropGroupId=="V")
        the_table = document.getElementById("tblVegetables");
    else if(CropGroupId=="T")
        //the_table = document.getElementById("tblCrop" + CropGroupId);
        the_table = document.getElementById("tblTreeNuttables");
    else
        the_table = document.getElementById("tblCrop" + CropGroupId);
        
    var newTable = the_table.cloneNode(true);
    newTable.id = 'tblpopupprodcontent';
    newTable.style.display ="block";
    document.getElementById("popupprodcontent").appendChild(newTable);
    gPageTracker("/ProdRender/ProductListByCropGroup.aspx?CropGroupId=" + CropGroupId);
}
function HideCropProductDialog()
{
    $find('ctl00_ctl00_ModalPopupExtender2').hide();
    document.getElementById("imgCropProductPage").src="/imagesV2/clear.gif";
    window.scrollTo(0,0);
    
}
function getCropImage(CropGroupId)
{
    var ImageName = "";
    switch(CropGroupId)
    {
        case "27":
            ImageName = "prod_pop_up_berries.jpg";
            break;
        case "17":
            ImageName = "prod_pop_up_citrus.jpg";
            break;
        case "2":
            ImageName = "prod_pop_up_corn.jpg";
            break;
        case "5":
            ImageName = "prod_pop_up_cotton.jpg";
            break;
        case "41":
            ImageName = "prod_pop_up_peanuts.jpg";
            break;
        case "29":
            ImageName = "prod_pop_up_pome.jpg";
            break;
        case "11":
            ImageName = "prod_pop_up_potatoes.jpg";
            break;
        case "6":
            ImageName = "prod_pop_up_rice.jpg";
            break;
        case "66":
            ImageName = "prod_pop_up_sorghum.jpg";
            break;
        case "3":
            ImageName = "prod_pop_up_soybeans.jpg";
            break;
        case "30":
            ImageName = "prod_pop_up_stone.jpg";
            break;
        case "67":
            ImageName = "prod_pop_up_sunflowers.jpg";
            break;
        case "38":
            ImageName = "prod_pop_up_tobacco.jpg";
            break;
        case "T":
            ImageName = "prod_pop_up_nuts.jpg";
            break;
        case "V":
            ImageName = "prod_pop_up_veg.jpg";
            break;
        case "4":
            ImageName = "prod_pop_up_wheat.jpg";
            break;        
        case "37":
            ImageName = "prod_pop_up_veg.jpg";
            break;               
        case "15":
            ImageName = "prod_pop_up_veg.jpg";
            break;               
        case "33":
            ImageName = "prod_pop_up_veg.jpg";
            break;               
        case "23":
            ImageName = "prod_pop_up_veg.jpg";
            break;               
        case "34":
            ImageName = "prod_pop_up_veg.jpg";
            break;   
         case "57945":
            ImageName = "sugarbeets_popup_image.jpg";
            break;               
    }
    return ImageName;
}

function ShowProductTypeDialog(ProdTypeId)
{
    if(ProdTypeId!="")
    {
        imgFooter= "prod_pop_up_prod_type.jpg";
        document.getElementById("imgCropProductPage").src = "/imagesV2/" + imgFooter;
        CloneProductTypeTable(ProdTypeId);
        $find('ctl00_ctl00_ModalPopupExtender2').show();
    }
}

function CloneProductTypeTable(ProdTypeId)
{
    
    var old_table = document.getElementById("tblpopupprodcontent");
    document.getElementById("popupprodcontent").removeChild(old_table);
    var the_table 
    the_table = document.getElementById("tblProdType" + ProdTypeId);
        
    var newTable = the_table.cloneNode(true);
    newTable.id = 'tblpopupprodcontent';
    newTable.style.display ="block";
    document.getElementById("popupprodcontent").appendChild(newTable);
    gPageTracker("/ProdRender/ProductListByProductType.aspx?ProdTypeId=" + ProdTypeId);
}

     function ShowDialog(DialogId)
    {
        if($find('ctl00_ctl00_' + DialogId)!=null)
            $find('ctl00_ctl00_' + DialogId).show(); 
        else if($find('ctl00_' + DialogId)!=null)
            $find('ctl00_' + DialogId).show(); 
        else if($find(DialogId)!=null)
            $find(DialogId).show(); 
    }
    function HideDialog(DialogId)
    {
        if($find('ctl00_ctl00_' + DialogId)!=null)
            $find('ctl00_ctl00_' + DialogId).hide(); 
        else if($find('ctl00_' + DialogId)!=null)
            $find('ctl00_' + DialogId).hide(); 
        else if($find(DialogId)!=null)
            $find(DialogId).hide(); 
    }
    
    
    function SetWeather()
    {
        __doPostBack('ctl00$pnlblank$btnWeather','');        
    }
    
    function SetCashBids()
    {
        __doPostBack('ctl00$pnlblank$EditCashBids','');        
    }
    
    function SetCommodities()
    {
        //alert(document.getElementById("ctl00_txtCommodity1").value)
        __doPostBack('ctl00$pnlblank$EditCommodities','');        
    }
    function openWindow( newUrl ) {
      
		opener =	newUrl
		shownewwindow = window.open(opener, 'displaywindow', 'toolbar=no,location=no,scrollbars=1,resizable=1,width=700,height=750');
		}
 function SetProducts()
    {
        __doPostBack('ctl00$pnlblank$EditMyProduct','');        
    }

function printPartOfPage(elementId)
{
 var printContent = document.getElementById(elementId);
 var windowUrl = 'about:blank';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
 printWindow.document.write("<link href='/Css/styles.css' rel='stylesheet' type='text/css' />"+
    "<link href='~/Css/Famassist.css' rel='stylesheet' type='text/css' />");
 printWindow.document.write("<img src='http://208.251.220.54/imagesV2/logo.gif'/>");
 printWindow.document.write(printContent.innerHTML);
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
}

function UpdateMyProduct(productId)
{
    LinkControl = document.getElementById("lnkProduct" + productId);
    if(LinkControl.disabled!="1")
    {
        LinkControl.disabled=1;
        //alert(LinkControl.id.replace("lnkProduct","imgProduct"));
        document.getElementById("imgProduct" + productId ).src="/imagesV2/delete_button_gray.gif";
        if(document.getElementById("ctl00_hidDeleteProduct").value=="")
            document.getElementById("ctl00_hidDeleteProduct").value = productId;
        else
            document.getElementById("ctl00_hidDeleteProduct").value += "," + productId;
    }
    
}

function CancelDeleteProducts()
{
    if(document.getElementById("ctl00_hidDeleteProduct").value!="")
    {
        var productIds = document.getElementById("ctl00_hidDeleteProduct").value.split(",");
         //alert(document.getElementById("ctl00_hidDeleteProduct").value);
        for(i=0;i<productIds.length;i++)
        {
            document.getElementById("lnkProduct" +productIds[i]).disabled=0;
            document.getElementById("imgProduct" + productIds[i] ).src="/imagesV2/delete_button.gif";
        }
        document.getElementById("ctl00_hidDeleteProduct").value="";
    }
}

function removeRow(rows){ var _row = rows.parentElement.parentElement;  document.getElementById('table1').deleteRow(_row.rowIndex);}
function LoadMyproduct()
{
    //alert(document.getElementById("ctl00_pnlblank_hidProductIds").value);
    //alert(document.getElementById("ctl00_pnlblank_hidProductNames").value);
    var arrProductIds = document.getElementById("ctl00_pnlblank_hidProductIds").value.split(",");
    var arrProductNames = document.getElementById("ctl00_pnlblank_hidProductNames").value.split(",");
    var tblProduct = document.getElementById("ctl00_tblMyProduct");
    var lastRow = tblProduct.rows.length;
    for(i=0;i<lastRow;i++)
        tblProduct.deleteRow(0);
    if( document.getElementById("ctl00_pnlblank_hidProductIds").value=="")
        return;
    var intRowNum = arrProductIds.length / 2;
    if (arrProductIds.length % 2 > 0)
       intRowNum = (arrProductIds.length +1) / 2;
    var row;
    for(i=0;i<arrProductIds.length;i++)
    {
         if (i < intRowNum)
             row = tblProduct.insertRow(tblProduct.rows.length);
         else
             row = tblProduct.rows[i-intRowNum];
             
         var cell = row.insertCell(row.cells.length);
         cell.width = "62";
         cell.align="left";
         cell.valign="middle";
         cell.innerHTML = "<a id=\"lnkProduct" + arrProductIds[i] + "\" href=\"javascript:UpdateMyProduct('" + arrProductIds[i] 
            + "');\" ><img id=\"imgProduct" + arrProductIds[i]+ "\" src=\"/imagesV2/delete_button.gif\" alt=\"Delete\" width=\"62\" height=\"19\" border=\"0\" /></a>";
            
         cell = row.insertCell(row.cells.length);
         cell.width = "48%";
         cell.align="left";
         cell.valign="middle";
         cell.innerHTML = arrProductNames[i]
         
    }
        
    if (row.cells.length == 2)
    {
        var cell = row.insertCell(row.cells.length);
        cell.width = "62";
        cell.align="left";
        cell.valign="middle";
        cell.innerHTML = "&nbsp;";
        
        cell = row.insertCell(row.cells.length);
        cell.width = "48%";
        cell.align= "left";
        cell.valign= "middle";
        cell.innerHTML = "&nbsp;";
    }
}


function isIE()
{
	var i = navigator.userAgent.toLowerCase().indexOf("msie");
	return i>=0;
}

function isFireFox()
{	
	var i = navigator.userAgent.toLowerCase().indexOf("firefox");	
	var j = navigator.userAgent.toLowerCase().indexOf("safari");
	
	if(i>=0)	
	return i>=0;
	else if( j>=0)
	return j>=0;
}


function fnResults()
{
		
	var cx = '005307373233178623494:logqtcm4dtc';
	var cof = 'FORID:11;NB:1';
	
	var srch=document.getElementById('searchTxt').value;
	
	var q=srch;	
	
	if(q!=null)
	{
		if(q!= '')
		{		//alert(		window.location.host);			
			var baseURL ;
			
		//	if(window.location.host=='syngentaus.')
		//	{
			baseURL='http://' +window.location.host +'/search.aspx?cx=' + cx + '&' +  'cof=' + cof   + '&' +  'q=' + q ;// + '&client=google-cbse';
			
		//	}
		//	else
		//	{
		//	cx = '005307373233178623494:darry2okkjo';
		//	baseURL='http://' +window.location.host +'/search.aspx?cx=' + cx + '&' +  'cof=' + cof   + '&' +  'q=' + q + ' site:'+'www.syngentacropprotection.com';// + '&client=google-cbse';
			
		//	}
			if(isFireFox())
			{  //alert(baseURL);
				//window.location(baseURL);
				  window.location.href=baseURL;
			}
			else 
				window.navigate(baseURL);
		}
	}
	return false;
}