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 ""
}

function setCookie(c_name,value,expiremilliseconds) {
var exdate=new Date()
exdate.setTime(exdate.getTime()+expiremilliseconds)
document.cookie=c_name+ "=" +escape(value)+
((expiremilliseconds==null) ? "" : ";expires="+exdate.toGMTString())
}

function checkCookie() {
  username=getCookie('username')
  if (username!=null && username!="")
    {alert('Welcome again '+username+'!')}
  else 
    {
    username=prompt('Please enter your name:',"")
    if (username!=null && username!="")
      {
      setCookie('username',username,365)
      }
    }
}
function closeMyPopup() {
 document.getElementById("mypopup").style.display = "none";
}

function myPopupRelocate() {
 var scrolledX, scrolledY;
 if( self.pageYOffset ) {
   scrolledX = self.pageXOffset;
   scrolledY = self.pageYOffset;
 } else if( document.documentElement && document.documentElement.scrollTop ) {
   scrolledX = document.documentElement.scrollLeft;
   scrolledY = document.documentElement.scrollTop;
 } else if( document.body ) {
   scrolledX = document.body.scrollLeft;
   scrolledY = document.body.scrollTop;
 }

 var centerX, centerY;
 if( self.innerHeight ) {
   centerX = self.innerWidth;
   centerY = self.innerHeight;
 } else if( document.documentElement && document.documentElement.clientHeight ) {
   centerX = document.documentElement.clientWidth;
   centerY = document.documentElement.clientHeight;
 } else if( document.body ) {
   centerX = document.body.clientWidth;
   centerY = document.body.clientHeight;
 }

 var leftOffset = scrolledX + 100;//(centerX - 400) / 2;
 var topOffset = scrolledY + 20;//(centerY - 400) / 2;

 document.getElementById("mypopup").style.top = topOffset + "px";
 document.getElementById("mypopup").style.left = leftOffset + "px";
}
function fireMyPopup() {
 myPopupRelocate();
 document.getElementById("mypopup").style.display = "block";
 document.body.onscroll = myPopupRelocate;
 window.onscroll = myPopupRelocate;
// window.setTimeout("closeMyPopup()", 10000);
}
function closepopup() {
  document.getElementById("mypopup").style.display = "none";
  setCookie("askromeonewsletter", "closed", 3600000);
}
function loadpopup() {
  popupcookie=getCookie('askromeonewsletter')
  if (popupcookie!=null && popupcookie!="") {
  } else {
    document.body.onload = window.setTimeout("fireMyPopup()", 60000);
  }
}
function DoSubmit(form){
    var winName = form.name + "_win";
    window.open("", "_main", "scrollbars=yes,width=620,height=260,resizable=0");    
    form.target = winName;
    form.submit();
}
