var _n=null;var _t=true;var _f=false;
function s_e(ts) {if(ts!=_n && ts.style!=_n) ts.style.display="";}

function h_e(ts) {if(ts!=_n && ts.style!=_n) ts.style.display="none";}
function textValidation(id, errId){
    var field=g_e(id);
    if(field.value==_n || field.value=='')
    {
    	s_e(g_e(errId));
        return false;
    }
    return true;
}
function buildUrl( url ){
    var drpdwn=g_e("models");
    drpdwn.disabled=true;
    var brd = g_e("brd");
    url = url + brd.value;    
    sendReq(url)
}

function addbookmark(){      
   if (window.sidebar)
        window.sidebar.addPanel(document.title, location.href,"");
   else if( window.external )
        external.AddFavorite(window.location.href,document.title); 
}

function g_e(n){return document.getElementById(n);}
function showElement(ele, elem1){
  var ts=document.getElementById(ele);
  if(ts!=_n)s_e(ts);
  
  var ts2=document.getElementById(elem1);
  if(ts2!=_n)h_e(ts2);
}

function showElement(ele){
  var ts=document.getElementById(ele);
  if(ts!=_n)s_e(ts);
}
function hideElement(ele){
  var ts=document.getElementById(ele);
  if(ts!=_n)h_e(ts);
}

function validate(){    
    h_e(g_e("key"));
    h_e(g_e("cat"));
    h_e(g_e("exc"));
    h_e(g_e("prc"));
    h_e(g_e("prc1"));
    var check = true;
    var key=g_e("keyWords");
    if( key.value=="" )
        {            
            showElement("key");
            check = false;
        }
    key=g_e("CFD_PDT_primaryCats");    
    if( key.value==0)
        {
            showElement("cat");
            check = false;            
        }    
    key=g_e("minPrice"); 
    key1=g_e("maxPrice"); 
    if( key.value!="" || key1.value!="")
        {
            if( key.value==key1.value)
                {
                    showElement("prc");
                    check=false;
                }    
        }   
    if( ( key.value!="" && key1.value=="" ) || ( key.value=="" && key1.value!="" ) )
        {
            showElement("prc1");
            check = false;            
        } 
    return check;
}

function ve_al(msg){
  return confirm(msg);
}

var browser = '';
var version = '';
function browserInfo() {
	var entrance = '';
	var cond = '';
	alert(navigator.appName);
	if (browser == '') {
		if (navigator.appName.indexOf('Microsoft') != -1) {
			browser = 'IE';
	 	}
		else if (navigator.appName.indexOf('Netscape') != -1) {
			browser = 'Netscape';
		} 
		else if (navigator.appName.indexOf('Mozilla') != -1) {
	 		browser = 'Mozilla';
		}
		else {
			browser = 'IE';
		}
	}
	
	if (version == '') {
		version= navigator.appVersion;
		var paren = version.indexOf('(');
		var whole_version = navigator.appVersion.substring(0,paren-1);
		version = parseInt(whole_version);
	}
}

/**
 * Calculate the width for the main opening div block and
 * return the div html
 */
function adjustMainMargin() {
	// Set the div element width dynamically
	
	browserInfo();
	
	var margin = 100;
	if  (document.documentElement.clientWidth < 900 && browser == 'IE') {
 		margin = 100;
	} 
	
	/*var divElement = "<div style=\"width: " + divWidth + "px;\">";*/
	var divElement = g_e('main');
	alert("main: " + margin + "browser: " + browser + "width:" + screen.width + "width2:" + document.documentElement.clientWidth);
	divElement.style.marginLeft = margin;
}

/**
 * Calculate the width for the main opening div block and
 * return the div html
 */
function adjustMainBlock() {
	// Set the div element width dynamically
	
	browserInfo();
	
	var divWidth = 700;
	if  (screen.width > 1024 && screen.width <= 1150) {
 		divWidth = 950;
	} if  (screen.width > 1150) {
		divWidth = 700;
		if (browser == 'Mozilla') {
			divWidth = 1200;
		}
		else if (browser == 'Netscape') {
			divWidth = 700;
		}
	}
	
	/*var divElement = "<div style=\"width: " + divWidth + "px;\">";*/
	var divElement = g_e('main');
	alert("main: " + divWidth + "browser: " + browser );
	divElement.style.width = divWidth;
}

function f_sel(f)
{
    var v;var d=g_e(f);
    if(d!=_n){v=d.options[d.selectedIndex]; if(v!=_n) v=v.value;}
    return v;
}
function set_f_text(f,v)
{
    var d=g_e(f);if(d!=_n){d.value=v;}
}
function inv_f_sub(a,t)
{
    var s_m,s_y,e_m,e_y;
    s_m=f_sel('startMonth');s_y=f_sel('startYear');e_m=f_sel('endMonth');e_y=f_sel('endYear');
    var val=_t;if(e_y<s_y || (e_y==s_y && e_m<s_m))val=_f;
    if(val==_t){
        var f=document.forms['invoiceParamForm'];
        if(a!=_n)f.action=a;
        if(t!=_n)set_f_text('type',t);
        f.submit();
    }
    else showElement('date.range.invalid');
}

function checkData()
{
    clear_error();
    var userId = 'userName';
    var psdId = 'password';
    var element = document.getElementById(userId);
    if (element.value == '')
    {
        var elementErId = 'reqField_err';
        elementEr = document.getElementById(elementErId);
	elementEr.style.display='';
	return false;
    }
    element = document.getElementById(psdId);
    if (element.value == '')
    {
        var elementErId = 'reqField_err';
        elementEr = document.getElementById(elementErId);
	elementEr.style.display='';
	return false;
    }
}

function clear_error() {
    var fieldErId = 'reqField_err';
    var fieldErIdEl = document.getElementById(fieldErId);
    fieldErIdEl.style.display='none';
}

function isChecked( formname )
{
  var formElm = document.forms[formname];
  if ( formElm ){
    var count = formElm.elements.length;
    for (i=0; i < count; i++) {
        if ( formElm.elements[i].checked == 1 )
          return true;
    }
  }
  return false;
}

function CheckAll( formname )
{
  var formElm = document.forms[formname];
  if ( formElm ){
    var count = formElm.elements.length;
    for (i=0; i < count; i++) {
      formElm.elements[i].checked = 1;
    }
  }
  return false;
}

function UncheckAll( formname )
{
  var formElm = document.forms[formname];
  if ( formElm ){
    var count = formElm.elements.length;
      for (i=0; i < count; i++) 
      {
         formElm.elements[i].checked = 0;
      }
  }
return false;
}

function disableInputElement(ele){
  var ts=document.getElementById(ele);
  if(ts!=_n)ts.readOnly = true;
}

function enableInputElement(ele){
  var ts=document.getElementById(ele);
  if(ts!=_n)ts.readOnly = false;
}

function trimSpaces(data) {
    if(data==null || !(typeof data == 'string' ))
        return data;

    data=data.replace(/\s{2,}/g," ");
    data=data.replace(/^\s+/,"");
    data=data.replace(/\s+$/,"");

    //document.title="'"+data+"'";
    return data;
}