var ajaxdestination="";

function getdata(what,where) { // get data from source (what)
 try {
   xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
 }
 catch (e) { /* do nothing */ }

 document.getElementById(where).innerHTML ="<center><img src='/images/loading.gif'></center>";
// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
 ajaxdestination=where;
 xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
 xmlhttp.open("GET", what);
 xmlhttp.send(null);
//  return false;
}

function triggered() { // put data returned by requested URL to selected DIV
  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
}


function hideans(pass) {
var boxes = document.getElementsByTagName("div");

for(var i=0;i<boxes.length;i++) {
var boxClass = boxes[i].className;

if(boxClass.match("detailsedit")) {
if(boxes[i].id.match(pass)){//if they are 'see' divs
if (document.getElementById) // DOM3 = IE5, NS6
{
boxes[i].style.visibility="visible";// show/hide
boxes[i].style.display="block";// show/hide
}
else
if (document.layers) // Netscape 4
{
document.layers[boxes[i]].display = 'visible';
}
else // IE 4
{
document.all.boxes[i].visibility = 'visible';
document.all.boxes[i].display='block';
}
} else  {
	
	
	
if (document.getElementById)
{
//boxes[i].innerHTML='';
boxes[i].style.visibility="hidden";
boxes[i].style.display="none";// show/hide


}
else
if (document.layers) // Netscape 4
{
document.boxes[i].visibility = 'hidden';
document.boxes[i].display='none';
}
else // IE 4
{
document.all.boxes[i].visibility = 'hidden';
document.all.boxes[i].display = 'none';

}
	

}


}
}
}





function hideDiv(elemShow,  newhtml, editlinkname) {
if (document.getElementById) { // DOM3 = IE5, NS6

document.getElementById(editlinkname).href='javascript:showDiv(\''+elemShow+'\',\''+newhtml+'\',\''+editlinkname+'\')';
document.getElementById(elemShow).style.visibility = 'hidden';
getdata('',elemShow);



}
else {
if (document.layers) { // Netscape 4
document.elemShow.visibility = 'hidden';
}
else { // IE 4
document.all.elemShow.style.visibility = 'hidden';
}
}
}

function showDiv(elemShow, newhtml, editlinkname) {
if (document.getElementById) { // DOM3 = IE5, NS6
hideans(elemShow);
document.getElementById(elemShow).style.visibility = 'visible';
getdata(newhtml,elemShow);
document.getElementById(editlinkname).href='javascript:hideDiv(\''+elemShow+'\',\''+newhtml+'\',\''+editlinkname+'\')';

}
else {
if (document.layers) { // Netscape 4
document.elemShow.visibility = 'visible';
}
else { // IE 4
document.all.elemShow.style.visibility = 'visible';
}
}
}

function VisibleDiv(elemShow, isvisible) {
if (document.getElementById) { // DOM3 = IE5, NS6
	if (isvisible==1)
	{
	document.getElementById(elemShow).style.visibility = 'visible';
	}
	else {
	document.getElementById(elemShow).style.visibility = 'hidden';
	}
}
else {
if (document.layers) { // Netscape 4
	if (isvisible==1)
	{
	document.elemShow.visibility = 'visible';
	}
	else {
	document.elemShow.visibility = 'hidden';		
	}
}
else { // IE 4
	if (isvisible==1)
	{

	document.all.elemShow.style.visibility = 'visible';
	}
	else {
	document.all.elemShow.style.visibility = 'hidden';
	}
}
}
}


function check(elemshow)
  {
	if   (document.getElementById(elemshow).checked) 
	{
	document.getElementById(elemshow).value='yes';
	}
	else {
		document.getElementById(elemshow).value='non';
	}
  
  }


function addtitle(elemsget,elemsshow)
  {
	document.getElementById(elemsshow).value=document.getElementById(elemsget).value;
  }
  
  
function changedivcontent(elemShow, newhtml, editlinkname) {
if (document.getElementById) { // DOM3 = IE5, NS6
//document.getElementById(elemShow).style.visibility = 'visible';
getdata(newhtml,elemShow);
//document.getElementById(editlinkname).href='javascript:changedivcontent(\''+elemShow+'\',\''+newhtml+'\',\''+editlinkname+'\')';

}
else {
if (document.layers) { // Netscape 4
document.elemShow.visibility = 'visible';
}
else { // IE 4
document.all.elemShow.style.visibility = 'visible';
}
}

}

//LOAD PLAN

var ajaxdestinationvalue="";


function setvalue(what,where) { // get data from source (what)
 try {
   xmlhttp1 = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
 }
 catch (e) { /* do nothing */ }


// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
 ajaxdestinationvalue=where;
 xmlhttp1.onreadystatechange = triggeredvalue; // when request finished, call the function to put result to destination DIV
 xmlhttp1.open("GET", what);
 xmlhttp1.send(null);
  return false;
}

function triggeredvalue() { // put data returned by requested URL to selected DIV
  if (xmlhttp1.readyState == 4) if (xmlhttp1.status == 200) 
    document.getElementById(ajaxdestinationvalue).value =xmlhttp1.responseText;
}

var ajaxdestinationvalue2="";
function setvalue2(what,where) { // get data from source (what)
 try {
   xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
 }
 catch (e) { /* do nothing */ }


// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
 ajaxdestinationvalue2=where;
 xmlhttp2.onreadystatechange = triggeredvalue2; // when request finished, call the function to put result to destination DIV
 xmlhttp2.open("GET", what);
 xmlhttp2.send(null);
  return false;
}

function triggeredvalue2() { // put data returned by requested URL to selected DIV
  if (xmlhttp2.readyState == 4) if (xmlhttp2.status == 200) 
    document.getElementById(ajaxdestinationvalue2).value =xmlhttp2.responseText;
}


function loadplanparameter(elemParent, elemShow, newhtml,params) {
	
		
if (document.getElementById) { // DOM3 = IE5, NS6

 newhtml=newhtml+'?parentvalue='+document.getElementById(elemParent).value+'&field=0&singup='+document.getElementById('var_signupdate').value; 
 setvalue(newhtml,'var_numberoffers');
 
 
  newhtml=newhtml+'?parentvalue='+document.getElementById(elemParent).value+'&field=1&singup='+document.getElementById('var_signupdate').value; 
 setvalue2(newhtml,'var_expirationdate');

}
else {
if (document.layers) { // Netscape 4
document.elemShow.visibility = 'visible';
}
else { // IE 4
document.all.elemShow.style.visibility = 'visible';
}
}
}


// JavaScript Document

var ajaxdestinationimage="";

function getdataimage(what,where, status) { // get data from source (what)
 try {
   xmlhttp4 = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
 }
 catch (e) { /* do nothing */ }

 document.getElementById(where).src ="/images/loading.gif";
// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
 ajaxdestinationimage=where;
 xmlhttp4.onreadystatechange = triggered4; // when request finished, call the function to put result to destination DIV
 xmlhttp4.open("GET", what);
 xmlhttp4.send(null);
  //return false;
}

function triggered4() { // put data returned by requested URL to selected DIV
  if (xmlhttp4.readyState == 4) if (xmlhttp4.status == 200) 
  {
    document.getElementById(ajaxdestinationimage).src =xmlhttp4.responseText;
	

  }
}


function changestatus(what,where, status, wherelink, whatlink) { 
var whatlinkwithparam;
whatlinkwithparam=whatlink+'status='+status+'&id='+what;
  
  if (status==0)
  {
  document.getElementById(wherelink).href='javascript:changestatus(\''+what+'\',\''+where+'\','+1+',\''+wherelink+'\',\''+whatlink+'\')';
  }
  else {
  document.getElementById(wherelink).href='javascript:changestatus(\''+what+'\',\''+where+'\','+0+',\''+wherelink+'\',\''+whatlink+'\')';
  }

  getdataimage(whatlinkwithparam,where, status);
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate_form(thisform, ename)
{
with (thisform)
  {
  if (validate_email(ename,"Not a valid e-mail address!")==false)
    {ename.focus();return false;}
  }
}

