function popup(url,windowname,width,height,features) {
  if (window.name == windowname) {
    window.location.href = url;
    window.resizeTo(width, height);
  } else {
    var ix = 0;
    var iy = 0;
    if (screen.width)  // Object guarding - is it supported?
      ix = screen.width/2 - width/2;
    if (screen.height)  // Object guarding - is it supported?
      if (features == "all") {
      	iy = 10  //to account for all the vertical space added by address bar, etc.
      } else {
        iy = screen.height/2 - height/2;
      }
    var strFeatures = "";
    if (typeof(features) == "undefined"){
      strFeatures = ",resizable=1,scrollbars=1,left=" + ix + ",top=" + iy;
    } else if (features == "all"){
      strFeatures = ",resizable=1,scrollbars=1,toolbar=1,menubar=1,location=1,status=1,left=" + ix + ",top=" + iy;
    } else if (features == "none"){
      strFeatures = ",left=" + ix + ",top=" + iy;
    } else {
      strFeatures = "," + features;
    }
    var handle = window.open(url, windowname, 'width=' + width + ',height=' + height + strFeatures);
    if (!handle.opener) handle.opener = self;
    handle.focus();
  }
}
function register_popup(next_url) {
  var url    = '/account/register/?popup=1&next_url=' + escape(next_url);
  var width  = 500;
  var height = 600;
  popup(url, 'LoginRegisterProfile', width, height);
}
function login_popup(next_url) {
  var url    = '/account/login/?popup=1&next_url=' + escape(next_url);
  var width  = 500;
  var height = 370;
  popup(url, 'LoginRegisterProfile', width, height);
}
function profile_popup(next_url) {
  var url    = '/account/profile/?popup=1&next_url=' + escape(next_url);
  var width  = 510;
  var height = 510;
  popup(url, 'LoginRegisterProfile', width, height);
}
function thankyou_popup(next_url) {
  var url    = '/account/register/thankyou/?popup=1&next_url=' + escape(next_url);
  var width  = 500;
  var height = 370;
  popup(url, 'ThankYou', width, height);  
}
function closeFrameAndGo(URL){
	if (parent.window.opener){
		parent.window.opener.location=URL;
		parent.window.close();
	} else {
		parent.window.location=URL;
	}
}
function targetparent_and_close(url) {
  self.opener.location.href=url;
  window.close();
}
function help_popup() {
  popup('/service/help/','Help',496,450);
}
function searchreq_popup(form) {
 var width  = 500;
 var height = 600;
 var ix = 0;
 var iy = 0;

 if (screen.width)  ix = screen.width/2 - width/2;
 if (screen.height) iy = screen.height/2 - height/2;

 _target = form.target + ',left=' + ix + ',top=' + iy;
 _colon = _target.indexOf(":");
 
 if(_colon != -1) {
   form.target = _target.substring(0,_colon);
   form.args = _target.substring(_colon+1);
 } else if(typeof(form.args)=="undefined") {
   form.args = "";
 }
 
 if(form.args.indexOf("{")!=-1) {
   _args = form.args.split("{");
   form.args = _args[0];
   for(var i = 1; i < _args.length;i++) {
     _args[i] = _args[i].split("}");
     form.args += eval(_args[i][0]) + _args[i][1];
   }
 }
 
 form.args = form.args.replace(/ /g,"");
 
 _win = window.open('',form.target,form.args);
 
 _win.focus();
 
 return true;
}
function doFocus(){
  window.focus();
}


