function popup_window(URLname,width,height,left,top,scrollbar)
{
	var popup;
	popup=window.open(URLname, "winid", 'width='+width+', height='+height+', left='+left+', top='+top+', scrollbars='+scrollbar+',screenX=0,screenY=0,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=yes');
	popup.focus(); 
}
function popup_window_max(URLname)
{
	var popup1;
	popup1=window.open(URLname, "winid1",'554,730,scrollbars=yes');
	popup1.focus();
}

function isNotNumeric(s)
{ 
	if(isNaN(s))
	{
		return(true);
	}
	return(false);
}
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
function strtrim(str) //function to trim a string
{
	var temp = str;
	var obj =/^(\s*)(\w*)(\s*)$/;
	if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
	return  temp;
}
function isnotvalid(str) //funtion to check spaces in string
{
	var temp = str;
	var obj =/\w*\s+\w*/;
	return obj.test(temp); 
}
All_phonechars = " 1234567890+-.()-\/";
function isValid_Phone(s)
{
	var i;
	for(i=0;i < s.length;i++)
	{
		var currchar = s.charAt(i);
		//window.alert(All_phonechars.indexOf(currchar));
		if(All_phonechars.indexOf(currchar) == -1)
		{
			return true;
		}
	}
	return false;
}
function isvalidmail(str) //function to validate Email Address
{
	/*var temp = str;
	var obj =/^(\w|-|\.)+@(\w|-)+\.\w{1,4}(\.\w{1,4})?$/;
	return obj.test(temp); */
	if (str.indexOf ('@',0) == -1 || str.indexOf ('.',0) == -1)
	    return 1;
    else
        return 0;
}
whitespace = "\t \n\r";
function isEmptyString(s)
{
    var i;
	if((s == null) || (s.length == 0)) return true;
	for(i=0;i < s.length;i++)
	{
		var currchar = s.charAt(i);
		if(whitespace.indexOf(currchar) == -1) return false;
	}
	return true;
}
function moveOptions(theSelFrom, theSelTo)
{

  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;

  var i;

  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      if(theSelTo.name == "city")
	{
		deleteOption(theSelFrom, i);
		var selLength = theSelFrom.length;
		if(selLength=='0')
		{
			addOption(theSelFrom, "-- All Cities --", "0");
		}
	}
      selectedCount++;
    }
  }



  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }

  if(NS4) history.go(0);
}
function change_city_option(value)
{
	var city_op = document.frm_ad.city.options.length;
	if(value == '0')
	{
		for(var i=1; i<city_op; i++)
		{
			document.frm_ad.city.options[i].selected = false;
		}
	}
	else
	{
		document.frm_ad.city.options[0].selected = false;
	}
}

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  var found = false;
  for(var i=0; i<selLength; i++)
	{
		if(theSel.options[i].value == theValue)
		{
			found = true;
		}
	}
	//alert(selLength)
	if(theValue == 0 && found == false && theSel.name == "city2[]")
	{
		for(var i=0; i<selLength; i++)
		{
			//alert(i)
			deleteOption(theSel, 0);
		}
		theSel.options[0] = newOpt;
		found = true;
	}
	else if(theValue != 0 && theSel.name == "city2[]")
	{
		if(theSel.options[0].value == "0")
		{
			deleteOption(theSel, 0);
			selLength = selLength - 1;
		}
	}
	if(found == false)
	{
	  theSel.options[selLength] = newOpt;
    }

}

function deleteOption(theSel, theIndex)
{
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

