var downKey=true;             
   function fnTrapKD(btn,event)
     {     
     var el = document.getElementById(btn);      
     if (el!=null){       
         var key = window.event ? event.keyCode : event.which;
         if(key==40 && downKey){ downKey=false;}
         if(key==13 && downKey==false)
         {
            downKey=true;
         }
         else
         if (key == 13 && downKey)             
                if (document.all)
                {
                    window.event.returnValue = null;     
                    event.cancel = true;
                    el.click();
                }
                else                
                el.focus();                              
            }
        
    }
    function getURLParameters(paramName) 
{
	var sURL = window.document.URL.toString();	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");			
		var arrURLParams = arrParams[1].split("&");		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != paramName)
				return  unescape(sParam[1]);
		}
		
		
	}
	return "";
}

     function resize(ContentFrameName) {
             var iframe = document.getElementById(ContentFrameName);
             if (document.frames)
             iframe.height=document.frames(ContentFrameName).document.body.scrollHeight;
             else
             iframe.height=window.frames[ContentFrameName].document.body.scrollHeight;            
             var srcUrl=getURLParameters('ContentFrame');             
             if(! srcUrl== '')             
                {                            
                }
        } 
function showHide(blockId, SFexpandCollapseLink){
	var hmtlBlock = document.getElementById(blockId);
	var expandCollapseLink = document.getElementById(SFexpandCollapseLink);
	
	    var skipNode=2;
	    var i=0;
	    while ( i<hmtlBlock.childNodes.length)
	    {
	        if(hmtlBlock.childNodes[i].tagName=='LI')
	        {
	            if(skipNode==0)
	            {
	            if (hmtlBlock.childNodes[i].style.display=='none')	    
	                {
	                    hmtlBlock.childNodes[i].style.display= 'block';
	                    expandCollapseLink.innerHTML = '-';
	                }
	                else
	                {
	                    hmtlBlock.childNodes[i].style.display='none';
	                    expandCollapseLink.innerHTML = '+';
	                }
	            }
	            else
	            skipNode--;	            
	            i++;
	        }
	        else
	        i++;	        
	    }
	return;
}
function PopupPic(sPicURL) { 
     displayWindow(sPicURL, "", 800, 600, "resizable=0,scrollbars=0"); 
}
function Popup(sPicURL,winName) { 
   
     displayWindow(sPicURL+'?'+ winName,'', 600, 600, "resizable=0"); 
}
function displayWindow(theURL,winName,width,height,features) {
   
    var baseAddr = null;

        if( document.getElementsByTagName ) {
        var elems = document.getElementsByTagName( 'base' );

        if( elems.length ) {
        baseAddr = elems[ 0 ].href;
        }
        }
    if(baseAddr!=null && baseAddr.charAt(baseAddr.length-1)=='/') theURL=baseAddr+theURL;
    if(baseAddr!=null && baseAddr.charAt(baseAddr.length-1)!='/') theURL=baseAddr+'/'+theURL;
    var window_width = width;
    var window_height = height;
    var newfeatures = features;
    var window_top = (screen.height-window_height)/2;
    var window_left = (screen.width-window_width)/2;     
    var newWindow=window.open(theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',' + newfeatures + '');
}    
function QuantityValid(source, arguments)
{
    var id= source.id;
    var i =id.lastIndexOf("_");
    
    var mincant=id.substring(0,i+1)+"minQunatity";
    var packcant=id.substring(0,i+1)+"packetSize";
    
    var packet= document.getElementById(packcant).value;
    var mincant= document.getElementById(mincant).value;
    if ((Number(arguments.Value) % Number(mincant)==0) && (Number(arguments.Value) % Number(packet) ==0 ))
    {
        arguments.IsValid=true;                
    }
    else 
    {        
        arguments.IsValid=false;
    }

}

function CheckAll(elemid)
{
    var me = document.getElementById(elemid);

    var prefix = me.id; 
    var form = document.forms[0];    
    for(i=0; i<form.length; i++) 
    { 
        var o = form[i];         
        if (o.type == 'checkbox') 
        {             
            if (me.id != o.id) 
            {
                if (o.id.substring(0, prefix.length) == prefix) 
                {                   
                    o.checked = true;                     
                }
            }
        } 
    } 
}
function ClearAll(elemid)
{
    
    var me = document.getElementById(elemid);

    var index = me.id;  
    var prefix = me.id; 
    var form = document.forms[0];    
    for(i=0; i<form.length; i++) 
    { 
        var o = form[i];         
        if (o.type == 'checkbox') 
        {                
            if (me.id != o.id) 
            {            
                if (o.id.substring(0, prefix.length) == prefix) 
                {                   
                    o.checked = false;                     
                }
            }
        } 
    } 
}

function ToggleAll(elemid,head)
{
		var me = document.getElementById(elemid);

        var prefix = me.id; 
        var form = document.forms[0];
		
        var j = 0;
		if(form == null)
			return;
       
        for(i=0; i<form.length; i++) 
        { 
            var o = form[i];         
            if (o.type == 'checkbox') 
            {     
                if (me.id != o.id) 
                {  
                    if ((o.id.substring(0, prefix.length) == prefix) &&
                    (o.name.indexOf(head) == -1)) 
                    {
                        if(o.checked == true)
                        {
                            
                            j++;
                        }   
                    }
                }
            }
        }	      
		if(j == 0)
		{
			CheckAll(elemid);
		}
        else
        {
            ClearAll(elemid);
        }
}

function CheckThis(me,head)
{
    var index = me.name.indexOf('$');  
    var prefix = me.name.substr(0,index);     
    var form = me.form;
    
    for(i=0; i<form.length; i++) 
    { 
        var o = form[i]; 
        if (o.type == 'checkbox') 
        {             
            if (o.name.substring(0, prefix.length) == prefix &&
                o.name.indexOf(head) >= 0) 
            {
                o.checked = o.checked & me.checked;
                break;
            }
        } 
    } 
}

function showControl(countryDDL,countyDDL,countyText)
{
    
    var country=document.getElementById(countryDDL);
    
    if (country.options[country.selectedIndex].value=='ro' || country.options[country.selectedIndex].value=='RO' )
    {
        var county=document.getElementById(countyDDL);
        var countyText=document.getElementById(countyText);
        county.className='show';
        countyText.className='hide';        
    }
    else
    {
        var county=document.getElementById(countyDDL);
        var countyText=document.getElementById(countyText);
        county.className='hide'; 
        countyText.className= 'show';      
    }
}

//Cookie util
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+";expires=Fri, 02-Jan-1970 00:00:00 GMT";
document.cookie=c_name+ "=" +escape(value)+";expires="+exdate.toDateString();
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}