// initiate the plugin after DOM has loaded
$(function(){
	// fixed tooltip
	$('a.fixedTip').aToolTip({
		fixed: true
	});

	// List of all paramaters and their default values:
	$('a').aToolTip({
		clickIt: false,						// set to true for click activated tooltip
		closeTipBtn: 'aToolTipCloseBtn',	// you can set custom class name for close button on tooltip
		fixed: true,						// Set true to activate fixed position
		inSpeed: 400,						// Speed tooltip fades in
		outSpeed: 100,						// Speed tooltip fades out
		tipContent: '',						// Pass in content or it will use objects 'title' attribute
		toolTipClass: 'aToolTip',			// Set custom class for tooltip
		xOffset: 5,							// x Position
		yOffset: -100							// y position
	});
});


function open_large_image(url) {
	var  new_url, name, features, new_window;
	new_url = "http://www.blindster.com/show_image.php?file=" + url;
	name = "Product_Image";
	features = "width=400,height=550,fullscreen=no,location=no,resizable=yes,status=no,scrollbars=yes,toolbar=no";
	new_window = window.open(new_url, name,features);
	new_window.focus();

}




function open_calc() {
	var  new_url, name, features, new_window;
	new_url = "http://www.blindster.com/multi-headrail-calculator.php";
	name = "Multi_headrail_calculator";
	features = "width=550,height=140,fullscreen=no,location=no,resizable=yes,status=no,scrollbars=auto,toolbar=no";
	new_window = window.open(new_url, name,features);
	new_window.focus();

}



function callAHAH(url, pageElement, callMessage, errorMessage)

{

	document.getElementById(pageElement).innerHTML=callMessage;

	try{ req=new XMLHttpRequest(); }

	catch(e){

		try { req = new ActiveXObject("Msxml2.XMLHTTP"); /* some versions IE */ }

		catch (f) {

			try{ req = new ActiveXObject("Microsoft.XMLHTTP");/* some versions IE */ }

			catch (E){ req = false;}

		}}

		req.onreadystatechange = function()

		{ responseAHAH(pageElement, errorMessage); }

		req.open("GET",url,true); 

		req.send(null); }



		function responseAHAH(pageElement, errorMessage) {

			if(req.readyState == 4) { if(req.status == 200) { 

				output = req.responseText;

				document.getElementById(pageElement).innerHTML = output; 

			} else { 

				document.getElementById(pageElement).innerHTML = errorMessage+"\n"+responseText; } 

			} }



function makeactive(page, tag)

{

	callAHAH(page, tag, '<br/><br/><span style="color:#FF0000"><strong>Loading Color Chart. Please wait...</strong></span><br/><br/>', 'Error');

}

function openColorSamplePopup(url) {
	var  new_url, name, features, new_window;
	new_url = "http://www.blindster.com/popup.php?file=" + url;
	name = "Option_Sample";
	features = "width=400,height=550,fullscreen=no,location=no,resizable=yes,status=no,scrollbars=auto,toolbar=no";
	new_window = window.open(new_url, name,features);
	new_window.focus();

}







// validate ZIP and ZIP+4 codes

function validateZipCode($zip_field) {

	var $valid_chars = "0123456789-";

	var $hyphen_count = 0;



	if ($zip_field.length != 5 && $zip_field.length != 10) {

		return false;

	}

	for (var i=0; i < $zip_field.length; i++) {

		$zc = "" + $zip_field.substring(i, i+1);

		if ($zc == "-") $hyphen_count++;

		if ($valid_chars.indexOf($zc) == "-1") {

			return false;

		}

		if (($hyphen_count > 1) || (($zip_field.length==10) && ""+$zip_field.charAt(5)!="-")) {

			return false;

		}

	}

	return true;

}



// Larger Sample Window

function popupWindow(url) {

	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')

}





var add_tax = false;

function calculate_total() {
	var state =  document.getElementById("state");
	var florida_tax =  document.getElementById("florida_tax");
	var total = document.getElementById("total");


	if (state.value == "FL") {
		florida_tax.style.display = "";
		//total.value = parseFloat(total.value) + parseFloat(florida_tax ?>);
		var num1 = new Number(total.value);
		total.value = num1.toFixed(2);
		add_tax = true;
	} else {
		florida_tax.style.display = "none";
		if (add_tax == true) {

			// alert(parseFloat(total.value)  - parseFloat());

			//total.value = parseFloat(total.value)  - parseFloat();
			var num2 = new Number(total.value);
			total.value = num2.toFixed(2);
			//	total.value  = total.value  + ".00";
			add_tax = false;
		}
	}

}

function copyFields()
{
	if ($('#copy_address').attr('checked'))
	{
		$('#ship_first_name').val($('#bill_first_name').val());
		$('#ship_last_name').val($('#bill_last_name').val());
		$('#ship_address1').val($('#bill_address1').val());
		$('#ship_address2').val($('#bill_address2').val());
		$('#ship_city').val($('#bill_city').val());
		$('#ship_zip').val($('#bill_zip').val());
		$('#ship_state').val($('#bill_state').val());
		$('#ship_phone1').val($('#bill_phone1').val());
		$('#ship_phone2').val($('#bill_phone2').val());
		$('#ship_email').val($('#bill_email').val());
	}
	else
	{
		$('#ship_first_name').val('');
		$('#ship_last_name').val('');
		$('#ship_address1').val('');
		$('#ship_address2').val('');
		$('#ship_city').val('');
		$('#ship_zip').val('');
		$('#ship_state').val('');
		$('#ship_phone1').val('');
		$('#ship_phone2').val('');
		$('#ship_email').val('');
	}
}

var form_submitted = false;

function validate_form()
{
	var error_msg = '';
	var bill_first_name = jQuery.trim($('#bill_first_name').val());
	var bill_last_name  = jQuery.trim($('#bill_last_name').val());
	var bill_address1   = jQuery.trim($('#bill_address1').val());
	var bill_city       = jQuery.trim($('#bill_city').val());
	var bill_zip        = jQuery.trim($('#bill_zip').val());
	var bill_state      = jQuery.trim($('#bill_state').val());
	var bill_phone1     = jQuery.trim($('#bill_phone1').val());
	var bill_phone2     = jQuery.trim($('#bill_phone2').val());
	var bill_email      = jQuery.trim($('#bill_email').val());
	var bill_email1     = jQuery.trim($('#bill_email1').val());
	var ship_first_name = jQuery.trim($('#ship_first_name').val());
	var ship_last_name  = jQuery.trim($('#ship_last_name').val());
	var ship_address1   = jQuery.trim($('#ship_address1').val());
	var ship_city       = jQuery.trim($('#ship_city').val());
	var ship_zip        = jQuery.trim($('#ship_zip').val());
	var ship_state      = jQuery.trim($('#ship_state').val());
	var ship_phone1     = jQuery.trim($('#ship_phone1').val());
	var ship_phone2     = jQuery.trim($('#ship_phone2').val());
	var cc_number       = jQuery.trim($('#cc_number').val());
	var cvv2            = jQuery.trim($('#cvv2').val());
	var ship_email      = $('#ship_email').val();

	if (bill_first_name == '') {
		error_msg += "Please enter the Billing First Name\r\n";
		$('#bill_first_name').css('backgroundColor','#ffe6e6');
	} else {
		$('#bill_first_name').css('backgroundColor','#fff');
	}

	if (bill_last_name == '') {
		error_msg += "Please enter the Billing Last Name\r\n";
		$('#bill_last_name').css('backgroundColor','#ffe6e6');
	} else {
		$('#bill_last_name').css('backgroundColor','#fff');
	}

	if (bill_address1 == '') {
		error_msg += "Please enter the Billing Address\r\n";
		$('#bill_address1').css('backgroundColor','#ffe6e6');
	} else {
		$('#bill_address1').css('backgroundColor','#fff');
	}

	if (bill_city == '') {
		error_msg += "Please enter the Billing City\r\n";
		$('#bill_city').css('backgroundColor','#ffe6e6');
	} else {
		$('#bill_city').css('backgroundColor','#fff');
	}

	if (bill_zip == '') {
		error_msg += "Please enter a Billing Zip Code\r\n";
		$('#bill_zip').css('backgroundColor','#ffe6e6');
	} else {
		$('#bill_zip').css('backgroundColor','#fff');
	}

	if (bill_state == '') {
		error_msg += "Please select a Billing State\r\n";
	}

	if (bill_phone1 == '') {
		error_msg += "Please enter a Billing Phone Number\r\n";
		$('#bill_phone1').css('backgroundColor','#ffe6e6');
	} else {
		$('#bill_phone1').css('backgroundColor','#fff');
	}

	if (bill_email == '') {
		error_msg += "Please enter a Billing Email Address\r\n";
		$('#bill_email').css('backgroundColor','#ffe6e6');
	} else {
		$('#bill_email').css('backgroundColor','#fff');
	}

	if (bill_email != bill_email1) {
		error_msg += "Your Email Addresses Do Not Match\r\n";
		$('#bill_email').css('backgroundColor','#ffe6e6');
		$('#bill_email1').css('backgroundColor','#ffe6e6');
	} else {
		$('#bill_email').css('backgroundColor','#fff');
		$('#bill_email1').css('backgroundColor','#fff');
	}

	if (ship_first_name == '') {
		error_msg += "Please enter the Shipping First Name\r\n";
		$('#ship_first_name').css('backgroundColor','#ffe6e6');
	} else {
		$('#ship_first_name').css('backgroundColor','#fff');
	}

	if (ship_last_name == '') {
		error_msg += "Please enter the Shipping Last Name\r\n";
		$('#ship_last_name').css('backgroundColor','#ffe6e6');
	} else {
		$('#ship_last_name').css('backgroundColor','#fff');
	}

	if (ship_address1 == '') {
		error_msg += "Please enter the Shipping Address\r\n";
		$('#ship_address1').css('backgroundColor','#ffe6e6');
	} else {
		$('#ship_address1').css('backgroundColor','#fff');
	}

	if (ship_city == '') {
		error_msg += "Please enter the Shipping City\r\n";
		$('#ship_city').css('backgroundColor','#ffe6e6');
	} else {
		$('#ship_city').css('backgroundColor','#fff');
	}

	if (ship_zip == '') {
		error_msg += "Please enter a Shipping Zip Code\r\n";
		$('#ship_zip').css('backgroundColor','#ffe6e6');
	} else {
		$('#ship_zip').css('backgroundColor','#fff');
	}

	if (ship_state == '') {
		error_msg += "Please select a Shipping State\r\n";
	}

	if (ship_phone1 == '') {
		error_msg += "Please enter a Shipping Phone Number\r\n";
		$('#ship_phone1').css('backgroundColor','#ffe6e6');
	} else {
		$('#ship_phone1').css('backgroundColor','#fff');
	}

	if (cc_number == '') {
		error_msg += "Please enter a valid Credit Card Number\r\n";
		$('#cc_number').css('backgroundColor','#ffe6e6');
	} else {
		$('#cc_number').css('backgroundColor','#fff');
	}

	if (cvv2 == '') {
		error_msg += "Please enter a valid CVV2 Number\r\n";
		$('#cvv2').css('backgroundColor','#ffe6e6');
	} else {
		$('#cvv2').css('backgroundColor','#fff');
	}

	if (error_msg != '') {
		alert("Please Correct The Following Errors:\r\n\r\n" + error_msg);
		return false;
	}

	return true;
}

function hide_Button()
{
	$('#submit_button').attr('src', '/images/processing_wait.gif');
	return true;
}
function hideButton()
{
	if (!validate_form())
	{
		return false;
	}
	$('#submit_button').attr('src', '/images/processing_wait.gif');
	return true;
}
if(typeof check_constraint == 'function') { 
	check_constraint(1);
}

