function check_field(obj,msg){
obj=eval(obj);
if(obj.value=="" || obj.value=="enter name"){
	alert(msg);
	obj.focus();
	return false;
}
return true;
}




/**
 * counter for textarea
 *
 * @author Ritchie
 * @param  string  sForm      form name
 * @param  string  sTextArea  textarea name
 * @param  string  sTextInput counter name
 * @param  integer iMaxLimit  max number for counter
 *
 * @usage  <textarea onKeyUp="calcCharLeft('frmregister', 'company_description', 'counter', 150)">
*/
function calcCharLeft(sForm, sTextArea, sTextInput, iMaxLimit)
{
	var _oDF        = document.forms[sForm];
	var _oTxtA      = _oDF.elements[sTextArea];
	var _iMaxLength = (!iMaxLimit) ? 100 : iMaxLimit;
	var _iCharLeft  = _oTxtA.value.length;

	_oDF.elements[sTextInput].value = _iCharLeft;

	if(_iCharLeft > _iMaxLength)
	{
		_oTxtA.value = _oTxtA.value.substring(0, _iMaxLength);
		_oDF.elements[sTextInput].value = _iMaxLength;
		alert('You can enter only '+_iMaxLength+' characters.');
	}
}


// create the prototype on the String object
String.prototype.trim = function()
{
	// skip leading and trailing whitespace
	// and return everything in between
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
}


/**
 * to populate the listbox on the fly
 *
 * @author Ritchie
 * @param  object oCurElement form element to be filled
 * @param  string sArrayName  data will be filled from this array
 * @param  string sKey        which key to be taken from the array
 * @param  string sDefSel     for default selection
 *
 * @usage  fill_options(this.form.city, "aIndianStates", this.form.state.options[this.form.state.selectedIndex].value);
*/
function fill_options(oCurElement, sArrayName, sKey, sDefSel)
{
	var _oElement = eval(oCurElement);
	var _iTotal   = _oElement.options.length;
	var _aData    = eval(sArrayName);

	//Empty _oElement dropdwn
	for(i=0; i < _iTotal; i++)
	{
		_oElement.options[i].value = null;
		_oElement.options[i].text  = null;
	}

	if(_aData[sKey].length > 0)
	{
		_oElement.options.length = _aData[sKey].length;

		//Fill _oElement with relevant data
		for(i=0; i<_aData[sKey].length; i++)
		{
			_oElement.options[i].value = _aData[sKey][i];
			_oElement.options[i].text  = _aData[sKey][i];

			//select def val
			if(sDefSel != '' && sDefSel == _aData[sKey][i]) _oElement.options[i].selected = true;
		}

	} // end of if(_aData[sKey].length > 0)

} // end of fill_options()


/**
 * to validate the vendor co search form
 *
 * @author Ritchie
 * @usage  onClick="return sbt_co_search();"
*/
function sbt_co_search()
{
	var _oDF     = document.frm_co_search;
	var _sCoName = _oDF.co_name.value;
	_sCoName     = _sCoName.trim();

	if(_sCoName == '' || _sCoName == 'enter name')
	{
		alert('Please enter company name');
		_oDF.co_name.select();
		_oDF.co_name.focus();
		return false;
	}
	else if(_sCoName.length < 3)
	{
		alert('Company Name should be atleast of 3 characters in length');
		_oDF.co_name.select();
		_oDF.co_name.focus();
		return false;
	}
	else _oDF.submit();

 } // end of sbt_co_search()



/**
 * to validate the vendor search form
 *
 * @author Ritchie
 * @usage  onClick="return sbt_vendor_search();"
*/
function sbt_search(sForm)
{
	var _oDF  = document.forms[sForm];

	if(_oDF.category_id.value == '')
	{
		alert('Please select Category');
		_oDF.category_id.focus();
		return false;
	}
	/*if(_oDF.subcategory.value == '')
	{
		alert('Please select Sub-Category');
		_oDF.subcategory.focus();
		return false;
	}
	if(_oDF.country.value == '')
	{
		alert('Please select Country');
		_oDF.country.focus();
		return false;
	}
	if((_oDF.country.value == 'India' || _oDF.country.value == 'USA') && _oDF.state.value == '')
	{
		alert('Please select State');
		_oDF.state.focus();
		return false;
	}
	if(_oDF.city.value == '')
	{
		alert('Please select City');
		_oDF.city.focus();
		return false;
	}*/
	_oDF.submit();

} // end of sbt_vendor_search()




/**
 * to populate the state listbox on the fly for catalog
 *
 * @author Ritchie
 * @param  string sForm       name of the form
 * @param  string sCountry    name of the current country selected
 * @param  string [sDefState] name of the state to be selected by default
 *
 * @usage  getState('frm_vendor_search', this.options[this.selectedIndex].value)
*/
function getState(sForm, sCountry, sDefState)
{
	if(sCountry == '') return false;

	var _oState       = eval(document.forms[sForm].state);
	var _iTotalStates = _oState.options.length;

	// empty _oState listbox
	for(i=0; i<_iTotalStates; i++)
	{
		_oState.options[i].value = null;
		_oState.options[i].text  = null;
	}

	var iCountryLen = 0;
	if(sCountry != 'Any') iCountryLen = aCountry[sCountry].length;

	_oState.options.length      = iCountryLen+1;
	_oState.options[0].value    = '';
	_oState.options[0].text     = 'Select State';
	_oState.options[0].selected = true;

	if(iCountryLen > 0)
	{
		if(sCountry != 'India' && sCountry != 'USA')
		{
			_oState.disabled = true;
			getCity(sForm, sCountry, sCountry);
		}
		else
		{
			_oState.disabled = false;

			// fill _oState with relevant data
			for(i=0; i<iCountryLen; i++)
			{
				_oState.options[i+1].value = aCountry[sCountry][i];
				_oState.options[i+1].text  = aCountry[sCountry][i];

				// select default val if available
				if(sDefState != '' && sDefState == aCountry[sCountry][i]) _oState.options[i+1].selected = true;
			}
			getCity(sForm, sCountry, 'Any');

		} // end of else of if(sCountry != 'India' && sCountry != 'USA')

	} // end of if(iCountryLen > 0)

} // end of function getState(sForm, sCountry, sDefState)



/**
 * to populate the city listbox on the fly for catalog
 *
 * @author Ritchie
 * @param  string sForm      name of the form
 * @param  string sState     name of the current state selected
 * @param  string [sDefCity] name of the city to be selected by default
 *
 * @usage  getCity('frm_vendor_search', this.options[this.selectedIndex].value, this.form.state.options[this.form.state.selectedIndex].value);
*/
function getCity(sForm, sCountry, sState, sDefCity)
{
	if(sCountry == '' || sState == '') return false;

	var _oCity        = eval(document.forms[sForm].city);
	var _iTotalCities = _oCity.options.length;

	var _aStates      = eval('aStatesOf'+sCountry.replace(/\s/g,'_')); // refering global array eg. aStatesOfIndia

	// empty _oCity listbox
	for(i=0; i<_iTotalCities; i++)
	{
		_oCity.options[i].value = null;
		_oCity.options[i].text  = null;
	}

	var _iStatesLen = 0;
	if(sState != 'Any') _iStatesLen = _aStates[sState].length;

	_oCity.options.length      = _iStatesLen+1;
	_oCity.options[0].value    = '';
	_oCity.options[0].text     = 'Select City';
	_oCity.options[0].selected = true;

	if(sCountry != 'India' && sCountry != 'USA') sState = sCountry;

	if(_iStatesLen > 0)
	{
		// fill _oCity with relevant data
		for(i=0; i<_iStatesLen; i++)
		{
			_oCity.options[i+1].value = _aStates[sState][i];
			_oCity.options[i+1].text  = _aStates[sState][i];

			// select default val if available
			if(sDefCity != '' && sDefCity == _aStates[sState][i]) _oCity.options[i+1].selected = true;
		}

	} // end of if(_iStatesLen > 0)

} // end of function getCity(sForm, sCountry, sState, sDefCity)


// catalog function
function ifcountry_india_usa(oCountry, sForm)
{
	var _oDF = document.frmregister;

	if(sForm) _oDF = document.forms[sForm];

	if(oCountry.options[oCountry.selectedIndex].text == 'India')
	{
		_oDF.indianstates.disabled = false;
		_oDF.usstates[0].selected  = true;
		_oDF.usstates.disabled     = true;
		_oDF.otherstate.value      = "";
		_oDF.otherstate.disabled   = true;
		return true;
	}
	else
	{
		if(oCountry.options[oCountry.selectedIndex].text == 'USA')
		{
			_oDF.indianstates[0].selected = true;
			_oDF.indianstates.disabled    = true;
			_oDF.usstates.disabled        = false;
			_oDF.otherstate.value         = "";
			_oDF.otherstate.disabled      = true;
			return true;
		}
		else
		{
			_oDF.otherstate.disabled      = false;
			_oDF.otherstate.focus();
			_oDF.usstates[0].selected     = true;
			_oDF.usstates.disabled        = true;
			_oDF.indianstates[0].selected = true;
			_oDF.indianstates.disabled    = true;
			return true;
		}
	}
}



// catalog sub category function
function get_subcategory(sForm, category_id, subcategory) {
count_sub=0;
  if(category_id == '') return false;

  var subcat_obj  = document.forms[sForm].elements["subcategory"];
  var have_subcat_obj  = document.forms[sForm].elements["have_subcategory"];
  while(subcat_obj.options.length) subcat_obj.options[0] = null;

  subcat_obj.options[0]=new Option('Select Sub-Category','');
  
if(arr_category[category_id]!=null)
  for(j=0; j<arr_category[category_id].length; j++) {
	
    //dont include option with null value
    if(arr_category[category_id][j] != "") {
	count_sub++;
      selected_str = (subcategory == arr_category[category_id][j])?true:false;
      subcat_obj.options[j+1]=new Option(arr_category[category_id][j],arr_category[category_id][j],true,selected_str);
	}
  }
	if(count_sub==0){
		have_subcat_obj.value="N";
		getobject("subcat_comp").innerHTML=""
		subcat_obj.disabled = true
	}else{
		have_subcat_obj.value="Y";
		getobject("subcat_comp").innerHTML="*"
		subcat_obj.disabled = false
	}
	
}//end get_subcategory(category_id,subcategory)


function getobject(div){
	if(document.all){
		return document.all[div];
	}else if(document.layers){
		return document.layers[div];
	}else{
		return document.getElementById(div);
	}
}

// #### allowing frames for roltanet ####
if (self != top) {
	if (document.images)
		top.location.replace(window.location.href);
	else
		top.location.href = window.location.href;
}

var opened=false;
var win;
function openWin(str,nm,width,height,noCtrWin){
	if(opened == false){
		win = open(str,nm,"status=0,scrollbars=1,menubar=0,toolbar=0,location=0,resizeable=0,width="+width+",height="+height);
	}
	else if(opened == true){
		if(win.closed == false)
		win.close();
		win = window.open(str,nm,"status=0,scrollbars=1,menubar=0,toolbar=0,location=0,resizeable=0,width="+width+",height="+height);
	}
	opened = true;
	win.focus();

  // center win
  if(!noCtrWin) {
    var w = (screen.availWidth/2) - (width/2);
    var h = (screen.availHeight/2) - (height/2);
    win.moveTo(w,h);
  }
}

function ctrWin(w,h) {

  var w = (screen.availWidth/2) - (w/2);
  var h = (screen.availHeight/2) - (h/2);
  top.moveTo(w,h);
  return;
}

// #### clear form ###
function cls(str){
	str.value = "";
	return;
}

function goUrl(obj) {
  for (i = 1; i < obj.length; i++)
    if (obj[i].selected == true)
      eval(obj[i].value);
}


function veriPopUp(url)
{
	sealWin = window.open(url, 'win', 'toolbar=0, location=0, directories=0, status=1, menubar=1, scrollbars=1, resizable=1, width=720, height=450');
	self.name = "mainWin";
}