/*
common javascript functions included on all pages throughout site
*/

//change the url of a page
function changePage(url) {
	if (url != '') location.href = url;
}


function MM_findObj(n, d) 
{
        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); 
        return x;
}

/* Functions that swaps images. */
function MM_swapImage() 
{
        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 MM_swapImgRestore() 
{
        var i,x,a=document.MM_sr; 
        for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() 
{
        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 startTime(){
        var time= new Date();
        hours= time.getHours();
        mins= time.getMinutes();
        secs= time.getSeconds();
        closeTime=hours*3600+mins*60+secs;
        closeTime+=0.1;  
        Timer();
}

function Timer(){
        var time= new Date();
        hours= time.getHours();
        mins= time.getMinutes();
        secs= time.getSeconds();
        curTime=hours*3600+mins*60+secs
        if (curTime>=closeTime){
                self.close();}
        else{
                window.setTimeout("Timer()",1000)}
}

//display a div
function displayBlock(ID) {
	if (ID != '') {	
		document.getElementByID(ID).style.display = 'block';
	}
}

//generic wndow opener
function openWin(url, winName, specs) {	
	if (winName == '') winName = 'win';	
	var win = window.open(url, winName, specs);								
	win.focus();
}


//clear all form fields
//whichForm: name of form we're dealing with
//ignoreFields: comma-delimited list of field names we don't want to touch
function clearForm(whichForm, ignoreFields) {	
	for (var i=0; i<whichForm.elements.length; i++) {
		curElement = whichForm.elements[i];
		//alert(curElement.type)
		if (ignoreFields.indexOf(',' + curElement.name + ',') == -1) {
			if (curElement.type == 'text') {		
				curElement.value = '';
			}
			else if (curElement.type == 'select-one') {		
				curElement.selectedIndex = 0;
			}		
		}
	}
}

//count characters left in a form field
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...this trims it!
		field.value = field.value.substring(0, maxlimit);
	else // otherwise, update 'characters left' counter
		countfield.value = maxlimit - field.value.length;
}

//hide user emails on site so they can't be farmed by spiders
function hideEmail(domain, user, strDisplay) {
	document.write('<a href=\"mailto:' + user + '@' + domain + '\">');
	if (strDisplay == null || strDisplay == '') {
		document.write('Email</a>');
	}
	else {
		document.write(strDisplay + '</a>');
	}
}

function openAdminImagesWin(url) {
	var win1 = window.open(url,'','width=600,height=300,scrollbars=1,resizable=1,menubar=1');
	win1.focus();
}

//view photo lib img
function viewImg(photoID, imgName) {
	var win = window.open('closeup.cfm?photoID=' + photoID + '&imgName=' + imgName, 'win_photolib_closeup', 'width=300,height=300,resizable=1,scrollbars=0');
	win.focus();
}

var feedbackWin;
function openFeedback(site) {
	// function opens a new feedback window, or if it's already open, puts that window in focus.
	if (feedbackWin && !feedbackWin.closed) {
		feedbackWin.focus();
	} else {
		feedbackWin=window.open('http://www.pwcertified.com/feedback.cfm?referrer='+site,'feedback','height=500,width=400');
		if (window.focus) {feedbackWin.focus()}
	}
}

