
function IncrementItemCount() {
    var count = parseInt($('#cart-item-count').html());
    $('#cart-item-count').html(++count);
}

function DecrementItemCount() {
    var count = parseInt($('#cart-item-count').html());
    $('#cart-item-count').html(--count);
}

var contact_method = '';

function ajaxSetMethod(method) {
    contact_method = method;
    
    /*
    if (method == '1') {
        document.getElementById('contact_comments_call_me').style.background = "url(images/call_select.png) no-repeat";
        document.getElementById('contact_comments_email_me').style.background = "url(images/email.png) no-repeat";
        document.getElementById('contact_comments_both').style.background = "url(images/both.png) no-repeat";
    } else if (method == '2') {
        document.getElementById('contact_comments_email_me').style.background = "url(images/email_select.png) no-repeat";
        document.getElementById('contact_comments_call_me').style.background = "url(images/call.png) no-repeat";
        document.getElementById('contact_comments_both').style.background = "url(images/both.png) no-repeat";
    } else {
        document.getElementById('contact_comments_both').style.background = "url(images/both_select.png) no-repeat";
        document.getElementById('contact_comments_email_me').style.background = "url(images/email.png) no-repeat";
        document.getElementById('contact_comments_call_me').style.background = "url(images/call.png) no-repeat";
    }
    */
    
    if (method == '1') {
        document.getElementById('contact_comments_call_me').style.backgroundPosition = "left bottom";
        document.getElementById('contact_comments_email_me').style.backgroundPosition = "left top";
        document.getElementById('contact_comments_both').style.backgroundPosition = "left top";
    } else if (method == '2') {
        document.getElementById('contact_comments_email_me').style.backgroundPosition = "left bottom";
        document.getElementById('contact_comments_call_me').style.backgroundPosition = "left top";
        document.getElementById('contact_comments_both').style.backgroundPosition = "left top";
    } else {
        document.getElementById('contact_comments_both').style.backgroundPosition = "left bottom";
        document.getElementById('contact_comments_call_me').style.backgroundPosition = "left top";
        document.getElementById('contact_comments_email_me').style.backgroundPosition = "left top";
    }
    
    
    
    //ajaxSend();
}


function ajaxSend() {
	
    if(contact_method != '1' && contact_method != '2' && contact_method !='3'){
        alert('Please select how you would like us to contact you');
        return false;
    }
    
    
    var contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
	var ajaxRequest;
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert('Sorry, we could not send your contact request at this time.');
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function() {
		if (ajaxRequest.readyState == 4) {
			document.getElementById('contact_comments_footer').innerHTML = ajaxRequest.responseText;
            
            document.getElementById('form_comments').value = '';
            document.getElementById('form_name').value = '';
            document.getElementById('form_email').value = '';
            document.getElementById('form_tel').value = '';
            document.getElementById('form_area').value = '';
            document.getElementById('form_call').selectedIndex = 0;
            
            document.getElementById('contact_comments_call_me').style.backgroundPosition = "left top";
            document.getElementById('contact_comments_email_me').style.backgroundPosition = "left top";
            document.getElementById('contact_comments_both').style.backgroundPosition = "left top";
            
		}
	}
    
    
	queryString = validateForm();

	
     
	if (queryString != false) {
        
        switch(contact_method){
            case '1':
            queryString += '&form_contact_method=Call';
            break;
            case '2':
            queryString += '&form_contact_method=Email';
            break;
            case '3':
            queryString += '&form_contact_method=Both';
            break;
        }
        
		ajaxRequest.open("POST", "includes/contact_us_mailer.php", true);

		/*
		document.getElementById('contact').style.display = 'none';
		document.getElementById('contact-form').innerHTML = '<br /><br /><span style="text-align:center;"><img src="images/loading.gif" /><br/><p>Please wait.. while we send your request.</p></span>';
		*/

        document.getElementById('contact_comments_footer').innerHTML = "Sending...";
        
		ajaxRequest.setRequestHeader('Content-Type', contentType);
		ajaxRequest.send(queryString);
	}
}

var fn = new Array();
fn['form_comments'] = 'Comments';
fn['form_name'] = 'Name';
fn['form_email'] = 'Email';
fn['form_tel'] = 'Tel';
fn['form_area'] = 'Area Code';
fn['form_call'] = 'Best time to call';


function validateForm() {
	elems = document.getElementById('contact_form').elements;
	var ret = Array();
	var error = new Array();
	for (var i=0;i<elems.length;i++) {
		if (typeof fn[elems[i].name] != 'undefined') {
			if (elems[i].type == 'select-one') {
				if (elems[i].options[elems[i].selectedIndex].value == '') {
						error.push(fn[elems[i].name]);
				}
			} else {
				if (elems[i].value == '') {
					error.push(fn[elems[i].id]);
				}
			}
		}
		ret.push(elems[i].name+'='+elems[i].value);
	}
	if (error.length == 0) {
		return ret.join('&')
	} else {
		//alert("Submission Error - The following fields require data.\n\nPlease correct the following:\n  - "+error.join("\n  - "));
		alert("Please fill in all fields");
		return false;
	}
}


	
function payOrder() {
    
    var order_contact_method = document.getElementById('form_contact_method').value;
    
    if(order_contact_method != 'call' && order_contact_method != 'email' && order_contact_method !='both'){
        alert('Please select how you would like us to contact you');
        return false;
    }
    
    
    if(validateOrderForm())
    {    
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
        setTimeout("document.getElementById('mainForm').submit()",2000);
        
        //document.getElementById('mainForm').submit();
    }
    
}



var reqFields = new Array();
reqFields['form_name'] = 'Name';
reqFields['form_email'] = 'Email';
reqFields['form_phone'] = 'Telephone';
reqFields['form_confirm_area'] = 'Area Code';


function validateOrderForm(){
    elems = document.getElementById('mainForm').elements;
    var ret = Array();
    var error = new Array();
    for (var i=0;i<elems.length;i++) {
        if (typeof reqFields[elems[i].name] != 'undefined') {
            if (elems[i].type == 'select-one') {
                if (elems[i].options[elems[i].selectedIndex].value == '') {
                        error.push(reqFields[elems[i].name]);
                }
            } else {
                if (elems[i].value == '') {
                    error.push(reqFields[elems[i].id]);
                }
            }
        }
        ret.push(elems[i].name+'='+elems[i].value);
    }
    if (error.length == 0) {
        //return ret.join('&')
        return true;
    } else {
        alert("Submission Error - The following fields require data.\n\nPlease correct the following:\n  - "+error.join("\n  - "));
        //alert("Please fill in all fields");
        return false;
    }
}


function hover_websites(hovering){

    if(hovering == true)
    {       
        document.getElementById('quote_websites_img1').style.display = 'none';
        document.getElementById('quote_websites_img2').style.display = 'block';
    }
    else
    {
        document.getElementById('quote_websites_img1').style.display = 'block';
        document.getElementById('quote_websites_img2').style.display = 'none';           
    }    
    
}


function clear_box_input(boxObj, defaultValue) {
    
    if(boxObj.value == defaultValue){
        boxObj.value = '';
    }
     
}

function reset_home_contact() {
    
    document.getElementById('form_name').value = "Your name...";
    document.getElementById('form_email').value = "Your email...";
    document.getElementById('form_comments').value = "Comments...";
}


function homeContactSend() {
    

    var contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
    var ajaxRequest;
    try{
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                alert('Sorry, we could not send your contact request at this time.');
                return false;
            }
        }
    }
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4) {
            document.getElementById('home_contact_message').innerHTML = ajaxRequest.responseText;
        }
    }
    
    
    queryString = homeValidateForm();


    if (queryString != false) {
        ajaxRequest.open("POST", "includes/home_contact_us_mailer.php", true);

        document.getElementById('home_contact_message').innerHTML = "Sending...";
        
        ajaxRequest.setRequestHeader('Content-Type', contentType);
        ajaxRequest.send(queryString);
    }
}


var hfn = new Array();
hfn['form_comments'] = 'Comments';
hfn['form_name'] = 'Name';
hfn['form_email'] = 'Email';


function homeValidateForm() {
    elems = document.getElementById('home_contact_form').elements;
    var ret = Array();
    var error = new Array();
    for (var i=0;i<elems.length;i++) {
        if (typeof hfn[elems[i].name] != 'undefined') {
            if (elems[i].type == 'select-one') {
                if (elems[i].options[elems[i].selectedIndex].value == '') {
                        error.push(hfn[elems[i].name]);
                }
            } else {
                if (elems[i].value == '') {
                    error.push(hfn[elems[i].id]);
                }
            }
        }
        ret.push(elems[i].name+'='+elems[i].value);
    }
    if (error.length == 0) {
        return ret.join('&')
    } else {
        //alert("Submission Error - The following fields require data.\n\nPlease correct the following:\n  - "+error.join("\n  - "));
        alert("Please fill in all fields");
        return false;
    }
}
