function dp_toggle_tabPage( trigger, pageId ) {
	
	dp_toggle_page( pageId );
	dp_toggle_tab( trigger );
	
}


function dp_toggle_page( pageId ) {

	var pageObj = $(pageId);
	
	if( pageObj != null ) {
		
		var pageSiblingsObj = pageObj.siblings();
			pageSiblingsObj.each(Element.hide);
			
		pageObj.show();
		
	}
	
}

function dp_toggle_tab( trigger ) {
	
	var triggerSiblingsObj = $(trigger).siblings();
		
	for( var i = 0; i < triggerSiblingsObj.length; i++ )
		triggerSiblingsObj[i].className = "";
	
	$(trigger).className = "selected";

}

function dp_init_button_hovering() {

	var buttons = document.getElementsByClassName("button");
	
	for( i = 0; i < buttons.length; i++ ) {
		buttons[i].onmouseover = dp_button_hover;
		buttons[i].onmouseout = dp_button_out;
	}

}

function dp_button_hover() {

	this.className = "button_hover";
	
}

function dp_button_out() {

	this.className = "button";
	
}

function dp_thank_you_page() {

	if( document.location.search.indexOf("thank_you") != -1 )
		 dp_toggle_tabPage( 'tab_contact', 'contact_thank_you' );
	
}

////////////// FORM CHECKER ////////////////////

// Inits the form check by an on submit trigger and
// applys on key up check to none validating fields.

function dp_checkForm_init() {

	var inputs_arr = document.getElementsByTagName("input");
	var validates = true;
	
	if( inputs_arr ) {
	
		for( var i = 0; i < inputs_arr.length; i++ ) {
			
			if( inputs_arr[i].getAttribute("type") == "text" && !dp_checkField( inputs_arr[i] ) ) {
				inputs_arr[i].onkeyup = dp_checkField_onKeyUp;
				inputs_arr[i].onblur = dp_checkField_onKeyUp;
				validates = dp_checkField( inputs_arr[i] );
			}
			
		}
		
	}
	
	if( validates )
		$("campaign_form").submit();


}

// Field check triggerd by dp_checkForm_init

function dp_checkField( obj ) {

	if( dp_getLabel( obj.id ).innerHTML.indexOf("*") != -1 && obj.value.length < 2 ) {
		dp_getLabel( obj.id ).style.color = "red";
		return false;
	}
	else {
		dp_getLabel( obj.id ).style.color = "black";
		return true;
	}

}

// Field check triggerd by dp_checkForm_init error (on key up)

function dp_checkField_onKeyUp() {

	if( dp_getLabel( this.id ).innerHTML.indexOf("*") != -1 && this.value.length < 2 )
		dp_getLabel( this.id ).style.color = "red";
	else
		dp_getLabel( this.id ).style.color = "black";

}

function dp_getLabel( id_str ) {


	var labels_arr = document.getElementsByTagName("label");
	
	if( labels_arr ) {
	
		for( var i = 0; i < labels_arr.length; i++ ) {
			
			if( labels_arr[i].getAttribute("for") == id_str || labels_arr[i].attributes["for"].nodeValue == id_str )
				return labels_arr[i];
			
		}
		
		return false;
	
	}


}
