/****************************************************************
* file: 	vet.js
* author:	toy
* date:		21jul10
* re:		general sitewide js
*
* rev history
* [toy 21jul10]		orig version
*****************************************************************/
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; 
	
	if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
	
	for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  
	
	if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }

	if(!(x=d[n])&&d.all) x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){
			document.MM_sr[j++]=x; 
			if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
		}
}

function hidenav(nav) {
	//MM_changeProp('homenav','','visibility','visible','SPAN');
	var objname = nav + "nav";
	var obj = MM_findObj(objname);

	//alert(obj.style.visibility);

	obj.style.visibility = "hidden";
}

function blinkIt() {
	if (!document.all) return;
	else {
		for(i=0;i<document.all.tags('blink').length;i++){
			s=document.all.tags('blink')[i];
			s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
		}
	}
}

function checkLogin(theForm) {
    errmsg = "";
    fieldname = "";
    flag = false;
    sectionname = "";

    if ((document.getElementById("username").value == "") || (document.getElementById("username").value == "username")) {
        errmsg += "- Username is required.\n";
    }

    if ((document.getElementById("password").value == "") || (document.getElementById("password").value == "password")) {
        errmsg += "- Password is required.\n";
    }

    if (errmsg != "") {
        intro = "There were some issues with your submission: \n";
        alert(intro + errmsg);
        return false;
    }

    return true;
}

function redirectHome() {window.location='/index.php';}


// DO NOT ERASE OR DELETE!!!!
function displayPopupDivORIG(e) {

    var posx = 0;
    var posy = 0;
    if (!e) { var e = window.event };

    // determine target DIV
    var targ = e.target ? e.target : e.srcElement;

    // calculate mouse coordinates
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX;
        posy = e.clientY;
        // check for scroll offsets in IE 6
        if (document.documentElement.scrollLeft || document.documentElement.scrollTop) {
            posx += document.documentElement.scrollLeft;
            posy += document.documentElement.scrollTop;
        }
    }

    // assign attributes to pop-up DIV element and append it to web document tree
    var div = document.getElementById('popup');
    if (!div) {
        var div = document.createElement('div');
        div.setAttribute('id', 'popup');
        div.className = 'popupdiv';
        div.appendChild(document.createTextNode('This is a sample content for pop-up DIV element.'));
        document.getElementsByTagName('body')[0].appendChild(div);
    }
    // move pop-up DIV element
    div.style.top = posy + 5 + 'px';
    div.style.left = posx + 5 + 'px';
}

function displayPopupDiv(e) {

    var posx = 0;
    var posy = 0;
    if (!e) { var e = window.event };

    // determine target DIV
    var targ = e.target ? e.target : e.srcElement;

    // calculate mouse coordinates
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX;
        posy = e.clientY;
        // check for scroll offsets in IE 6
        if (document.documentElement.scrollLeft || document.documentElement.scrollTop) {
            posx += document.documentElement.scrollLeft;
            posy += document.documentElement.scrollTop;
        }
    }

    // assign attributes to pop-up DIV element and append it to web document tree
    var div = document.getElementById('popup');
    if (!div) {
        var div = document.createElement('div');
        div.setAttribute('id', 'popup');
        div.className = 'popupdiv';
        div.appendChild(document.createTextNode('This is a sample content for pop-up DIV element.'));
        document.getElementsByTagName('body')[0].appendChild(div);
    }
    // move pop-up DIV element
    div.style.top = posy + 5 + 'px';
    div.style.left = posx + 5 + 'px';
}

// remove pop-up DIV element
function hidePopupDiv() {
    var div = document.getElementById('popup');
    if (!div) { return };
    div.parentNode.removeChild(div);
}

// activate pop-up DIV elements
function activatePopupDivs() {
    var divs = document.getElementsByTagName('div');
    if (!divs) { return };
    for (var i = 0; i < divs.length; i++) {
        if (divs[i].className == 'thumbnailI') {
            // display pop-up DIV element
            divs[i].onclick = displayPopupDiv;
            
            // hide pop-up DIV element
            divs[i].onmouseout = hidePopupDiv;
        }
    }
}

// activate pop-up DIV elements when web page has been loaded
/*
window.onload = function() {
    if (document.getElementById && document.createElement && document.createTextNode) {
        activatePopupDivs();
    }
}
*/


function findPos(obj) {
    var curleft = curtop = 0;

    // check if browser supports offsetParent
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}


function hideSWF() {
	var x = MM_findObj("theswf");
	if (x != null) {	
	    x.innerHTML = "&nbsp;";
	    x.style.display="none";
	    var x = MM_findObj("thetop5");
	    x.style.display="block";
	}
}
function hideSWF2() {
    var x = MM_findObj("player");
    if (x != null) {
        x.innerHTML = "&nbsp;";
        x.style.display = "none";
        var x = MM_findObj("instructions");
        x.style.display = "block";
    }
}

function redirectHome() {
    window.location='http://veteransnetwork.net/';
}
