// ClearOnFocus JQuery plugin:
// Unobtrusive solution to have default texts on textboxes that will go away
// when clicked. (When the user doesn't have JavaScript enabled, the textbox
// will be blank.)

;(function($) {
    $.clearOnFocus = function()
    {
        // For each input box with the default in the rel field (mostly search boxes),
        // and has the value attribute:
        $('input[rel*=default]').each(function()
        {
            // See if it's in the right format. Don't continue if it's not
            var match = (/\[default=([^\]]*)\]/).exec($(this).attr('rel'));
            if (!match) { return; }
        
            // Get the default text
            this.originalText = match[1];
        
            // When it's clicked...
            $(this).focus(function()
            {
                // And the text is the same as the default text...
                if (this.originalText == $(this).val()) {
                    // Clear it, and remove the .default-text class.
                    $(this).val('');
                    $(this).removeClass('default-text');
                }
                // But if there's something in it...
                else {
                    // Select the whole thing
                    this.selectionStart = 0;
                    this.selectionEnd = this.value.length;
                }
            });
        
            // And when leaving the field...
            $(this).blur(function()
            {
                // And there's nothing in it...
                if (('' == $(this).val()) || (this.originalText == $(this).val())) {
                    // Switch it back to the default text.
                    $(this).val(this.originalText);
                    $(this).addClass('default-text');
                }
            });
        
            // Run the blur code (bad and lazy)
            $(this).blur();
        });
        return $;
    };
})(jQuery);

// On load:
// Initialize the clear-on-focus behavior.
$(function() {
    $.clearOnFocus();
});





var swidth = (screen.width);
var sheight = (screen.height);

function feedbackpop(cur_url) {
	var str = navigator.userAgent;
	var plat = navigator.platform;
	if(b=str.indexOf("Safari") != -1){
		browser_name = "Safari";
		swidth = 620;
		sheight = 510;
	}else if(b=str.indexOf("Firefox") != -1 && plat == "Win32"){
		browser_name = "Firefox";
		swidth = 535;
		sheight = 488;
	}else if(b=str.indexOf("Firefox") != -1 && plat != "Win32"){
		browser_name = "Firefox";
		swidth = 620;
		sheight = 510;
	}else if(b=str.indexOf("MSIE") != -1){
		browser_name = "MSIE";
		swidth = 535;
		sheight = 488;
	}else{
		browser_name = "unknown";
		swidth = 535;
		sheight = 488;
	}
	//alert(browser_name);
	var feedback_url = 'http://www.partstrain.com/feedback/index.php';
	//535,488
	window.open(feedback_url+'?w='+swidth+'&h='+sheight+'&u='+cur_url, 'feedbk', 'width='+swidth+', height='+sheight+', screenX='+((swidth-'+swidth+')/2)+',screenY='+((sheight-'+sheight+')/2)+',top='+((sheight-'+sheight+')/2)+',left='+((swidth-'+swidth+')/2)+',resizable=yes,copyhistory=yes,scrollbars=no');
}

function fcheck_required_overall() {
	var OverallValue = "";

	if(typeof document.feedback.overall!='undefined') {
		if(typeof document.feedback.overall.value!='undefined'){
			OverallValue = document.feedback.overall.value;
		} else {
			for (i=0; i<5; i++) {
			  if(typeof document.feedback.overall[i]!='undefined'){
				  if(document.feedback.overall[i].checked=="1"){
					OverallValue=document.feedback.overall[i].value;
				  }
			  }else{OverallValue="0"}
			}
		}

	} else { OverallValue="0" }

	if (OverallValue == "" ) {
		alert("Please choose an overall rating before submitting.");
		return false;
	}

}


function fcheck_required_comments() {
	var CommentsValue = "";

	if(typeof document.feedback.comments!='undefined') {
		if(typeof document.feedback.comments.value!='undefined'){
			if (document.feedback.comments.value != 'Please enter your comments about this webpage here.') {
				CommentsValue = document.feedback.comments.value;
			}
		}
	} else { CommentsValue="0" }

	if (CommentsValue == "" ) {
		alert("Please enter your comments before submitting.");
		return false;
	}

}


function fcheck_required() {
	var CommentsValue = "";
	var EmailValue = document.feedback.answer_6.value;

	if(typeof document.feedback.comments!='undefined') {
                if(typeof document.feedback.comments.value!='undefined'){
                        if (document.feedback.comments.value != 'Please enter your comments about this webpage here.') {
                                CommentsValue = document.feedback.comments.value;
                        }
                }
        } else { CommentsValue="0" }

	if (CommentsValue == "" ) {
                alert("Please enter your comments before submitting.");
                return false;
        } else if (EmailValue == "") {
		alert("Please enter your email address.");
		return false;
	}
}


function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}

function clearTextArea() {
        if (document.feedback.cleared.value == '') {
                document.feedback.cleared.value = 1;
                document.feedback.comments.value = '';
        }
}



