var aOpen = new Array();

function _CinegagevPIP_addEvent(obj, evType, fn){
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

//Run CinegagevPIPInit on body load
// Legacy function
//_CinegagevPIP_addEvent(window, 'load', CinegagevPIPInit);



//$(document).ready(function(){//when the document is loaded
// Legacy function
/*function CinegagevPIPInit() {
   $("#divBloggerInstall").hide();
   $("#divWordpressInstall").hide();
   $("#divGeneralInstall").hide();
   $("#divUsingvPIP").hide();

   for (var i=0; i<10; i++) {
      aOpen[i] = true;
   }
}*/
//});

var request;
var queryString;   //will hold the POSTed data

/*
function joinMailList(  ){
   var sEmail = document.frmContactInfo.email.value;
    if (sEmail.length > 0 && isValidEmail(sEmail)) {
       setQueryString(  );
       var url="http://vpip.org/scripts/ajaxHandle.php";
       httpRequest("POST",url,true);
   }
   else {
      if (sEmail.length == 0) 
	 alert("Missing email.");
      else if (! isValidEmail(sEmail))
	 alert("Email isn't formatted correctly.");
      else
	 alert("Unknown error sending contant information.");

   }
}

function setQueryString(  ){
    queryString="";
    var frm = document.frmContactInfo;
    var numberElements =  frm.elements.length;
    for(var i = 0; i < numberElements; i++) {
        if(i < numberElements-1) {
            queryString += frm.elements[i].name+"="+
                           encodeURIComponent(frm.elements[i].value)+"&";
        } else {
            queryString += frm.elements[i].name+"="+
                           encodeURIComponent(frm.elements[i].value);
        }

    }
}
*/

/* Wrapper function for constructing a request object.
 Parameters:
  reqType: The HTTP request type, such as GET or POST.
  url: The URL of the server program.
  asynch: Whether to send the request asynchronously or not. */
  
function httpRequest(reqType,url,asynch){
    //Mozilla-based browsers
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest(  );
    } else if (window.ActiveXObject){
        request=new ActiveXObject("Msxml2.XMLHTTP");
        if (! request){
            request=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    //the request could still be null if neither ActiveXObject
    //initialization succeeded
    if(request){
        initReq(reqType,url,asynch);
    } else {
        alert("Your browser does not permit the use of all "+
              "of this application's features!");
    }
}

/* Initialize a request object that is already constructed.
 Parameters:
   reqType: The HTTP request type, such as GET or POST.
   url: The URL of the server program.
   isAsynch: Whether to send the request asynchronously or not. */
function initReq(reqType,url,isAsynch){
    /* Specify the function that will handle the HTTP response */
    request.onreadystatechange=handleResponse;
    request.open(reqType,url,isAsynch);
    /* Set the Content-Type header for a POST request */
    request.setRequestHeader("Content-Type",
            "application/x-www-form-urlencoded; charset=UTF-8");
    request.send(queryString);
}

function isValidEmail(sEmail){
   
   var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
   return (filter.test(sEmail))
}

//event handler for XMLHttpRequest
function handleResponse(  ){
    if(request.readyState == 4){
        if(request.status == 200){
            alert(request.responseText);
        } else {
            alert("A problem occurred with communicating between "+
                  "the XMLHttpRequest object and the server program.");
        }
    }//end outer if
}

function openBrWindow(theURL,winName,features) { 
   return window.open(theURL,winName,features);
}

function openCloseAnchor(sDiv, sImgName, iOpenPos) {
   
   var oImg = document.getElementById(sImgName);
   if (aOpen[iOpenPos]) {
      $(sDiv).slideDown();
      oImg.src = "http://vpip.org/images/contract.gif";
      aOpen[iOpenPos] = false;
   }
   else {
      $(sDiv).slideUp();
      oImg.src = "http://vpip.org/images/expand.gif";
      aOpen[iOpenPos] = true;
   }

}

function openAnchor(sDiv, sImgName, sLocation, iOpenPos) {
   var oImg = document.getElementById(sImgName);
   $(sDiv).slideDown();
   oImg.src = "http://vpip.org/images/contract.gif";
   window.location.hash = sLocation;
   aOpen[iOpenPos] = false;
}

