/*global FB, $*/

FB.init("62969d99e47f2476b3123bcb0b94825d","xd_receiver.htm");
var logging_in = false;

function go_fb() {
}

function showLogin() {
    var lf = document.getElementById('login_form');
    lf.style.display = 'block';
    $("#login_form").animate({"top": "19px"}, 200);
    logging_in = true;
}

function slideDown() {
    $("#login_container").slideUp(200);
    $("#facebook_container").slideUp(200);
	showLogin();
}

function go_login(div_id) {
    var goLogin = document.getElementById(div_id);
   	goLogin.submit();
}

function toggle_on(div_id) {
    var toToggle = document.getElementById(div_id);
   	toToggle.style.display = 'block';
}

function toggle_off(div_id) {
    var toToggle = document.getElementById(div_id);
   	toToggle.style.display = 'none';
}

function pink_label(div_id) {
    var image = document.getElementById(div_id);
   	image.src = 'http://www.prettyposts.com/images/pink_label.png';
}

function grey_label(div_id) {
    var image = document.getElementById(div_id);
   	image.src = 'http://www.prettyposts.com/images/grey_label.png';
}

function edit_label(div_id,div_idB) {
	var toToggle = document.getElementById(div_id);
	var toToggleB = document.getElementById(div_idB);
	toToggle.style.display = 'none';
	toToggleB.style.display = 'block';
}

function preload(){
	var myimages = new Array();
	for (x=0; x < preload.arguments.length; x++){
		myimages[x] = new Image();
		myimages[x].src = preload.arguments[x];
	}
}

function toggle_all_off() {
    toggle_off('post_shadeA1');
    toggle_off('post_shadeB1');
    toggle_off('post_shadeC1');
    toggle_off('post_shadeA2');
    toggle_off('post_shadeB2');
    toggle_off('post_shadeC2');
    toggle_off('post_shadeA3');
    toggle_off('post_shadeB3');
    toggle_off('post_shadeC3');
    toggle_off('post_shadeA4');
    toggle_off('post_shadeB4');
    toggle_off('post_shadeC4');
    
    toggle_off('post_chooseA1');
    toggle_off('post_chooseB1');
    toggle_off('post_chooseC1');
    toggle_off('post_chooseA2');
    toggle_off('post_chooseB2');
    toggle_off('post_chooseC2');
    toggle_off('post_chooseA3');
    toggle_off('post_chooseB3');
    toggle_off('post_chooseC3');
    toggle_off('post_chooseA4');
    toggle_off('post_chooseB4');
    toggle_off('post_chooseC4');
    
    toggle_off('post_previewA1');
    toggle_off('post_previewB1');
    toggle_off('post_previewC1');
    toggle_off('post_previewA2');
    toggle_off('post_previewB2');
    toggle_off('post_previewC2');
    toggle_off('post_previewA3');
    toggle_off('post_previewB3');
    toggle_off('post_previewC3');
    toggle_off('post_previewA4');
    toggle_off('post_previewB4');
    toggle_off('post_previewC4');
}

function toggle_all_off_free() {
    toggle_off('post_shadeA1');
    toggle_off('post_shadeB1');
    toggle_off('post_shadeC1');
    
    toggle_off('post_chooseA1');
    toggle_off('post_chooseB1');
    toggle_off('post_chooseC1');
    
    toggle_off('post_previewA1');
    toggle_off('post_previewB1');
    toggle_off('post_previewC1');
}

function toggle_labels_pink() {
    pink_label('livepostA1label');
    pink_label('livepostB1label');
    pink_label('livepostC1label');
    pink_label('livepostD1label');
    pink_label('livepostE1label');
    
    pink_label('livepostA2label');
    pink_label('livepostB2label');
    pink_label('livepostC2label');
    pink_label('livepostD2label');
    pink_label('livepostE2label');
    
    pink_label('livepostA3label');
    pink_label('livepostB3label');
    pink_label('livepostC3label');
    pink_label('livepostD3label');
    pink_label('livepostE3label');
    
    pink_label('livepostA4label');
    pink_label('livepostB4label');
    pink_label('livepostC4label');
    pink_label('livepostD4label');
    pink_label('livepostE4label');
}

function toggle_edit_labels() {
    edit_label('livepostA1overtext','livepostA1text');
    edit_label('livepostB1overtext','livepostB1text');
    edit_label('livepostC1overtext','livepostC1text');
    edit_label('livepostD1overtext','livepostD1text');
    edit_label('livepostE1overtext','livepostE1text');
    
    edit_label('livepostA2overtext','livepostA2text');
    edit_label('livepostB2overtext','livepostB2text');
    edit_label('livepostC2overtext','livepostC2text');
    edit_label('livepostD2overtext','livepostD2text');
    edit_label('livepostE2overtext','livepostE2text');
    
    edit_label('livepostA3overtext','livepostA3text');
    edit_label('livepostB3overtext','livepostB3text');
    edit_label('livepostC3overtext','livepostC3text');
    edit_label('livepostD3overtext','livepostD3text');
    edit_label('livepostE3overtext','livepostE3text');
   
    edit_label('livepostA4overtext','livepostA4text');
    edit_label('livepostB4overtext','livepostB4text');
    edit_label('livepostC4overtext','livepostC4text');
    edit_label('livepostD4overtext','livepostD4text');
    edit_label('livepostE4overtext','livepostE4text');
}

function toggle_labels_pink_noposts() {
    pink_label('livepostA3label');
    pink_label('livepostB3label');
    pink_label('livepostC3label');
    pink_label('livepostD3label');
    pink_label('livepostE3label');
    
    pink_label('livepostA4label');
    pink_label('livepostB4label');
    pink_label('livepostC4label');
    pink_label('livepostD4label');
    pink_label('livepostE4label');
}

function toggle_edit_labels_noposts() {
    edit_label('livepostA3overtext','livepostA3text');
    edit_label('livepostB3overtext','livepostB3text');
    edit_label('livepostC3overtext','livepostC3text');
    edit_label('livepostD3overtext','livepostD3text');
    edit_label('livepostE3overtext','livepostE3text');
   
    edit_label('livepostA4overtext','livepostA4text');
    edit_label('livepostB4overtext','livepostB4text');
    edit_label('livepostC4overtext','livepostC4text');
    edit_label('livepostD4overtext','livepostD4text');
    edit_label('livepostE4overtext','livepostE4text');
}
   
function toggle_labels_pink_nodrafts() {
    pink_label('livepostA1label');
    pink_label('livepostB1label');
    pink_label('livepostC1label');
    pink_label('livepostD1label');
    pink_label('livepostE1label');
    
    pink_label('livepostA2label');
    pink_label('livepostB2label');
    pink_label('livepostC2label');
    pink_label('livepostD2label');
    pink_label('livepostE2label');
}

function toggle_edit_labels_nodrafts() {
    edit_label('livepostA1overtext','livepostA1text');
    edit_label('livepostB1overtext','livepostB1text');
    edit_label('livepostC1overtext','livepostC1text');
    edit_label('livepostD1overtext','livepostD1text');
    edit_label('livepostE1overtext','livepostE1text');
    
    edit_label('livepostA2overtext','livepostA2text');
    edit_label('livepostB2overtext','livepostB2text');
    edit_label('livepostC2overtext','livepostC2text');
    edit_label('livepostD2overtext','livepostD2text');
    edit_label('livepostE2overtext','livepostE2text');
}

function roll(img_name, img_src) {
   var image = document.getElementById(img_name);
   image.src = img_src;
}

function changeLogin() {
    var cl = document.getElementById('userLogin');
    cl.value = '';
    cl.style.color = '#000';
}

function changePass() {
    var cp = document.getElementById('userPass');
    var cpB = document.getElementById('userPassB');
    cp.style.display = 'none';
    cpB.style.display = 'block';
    cpB.focus();
}

function getW(){
	var w;
	if (document.innerWidth) {
		w = document.innerWidth;
	} else if (document.documentElement.clientWidth) {
		w = document.documentElement.clientWidth;
	} else if (document.body) {
		w=document.body.clientWidth;
	}
	return w;
}

function mouseX(e) {
	var ev = e || window.event;
    var cursorX;
	if (ev.pageX) {
        cursorX = ev.pageX;
	} else if (ev.clientX) {
        cursorX = ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	}
    return cursorX - (getW() / 2);
}

function mouseY(e) {
	var ev = e || window.event;
    var cursorY;
	if (ev.pageY) {
        cursorY = ev.pageY;
	} else if (ev.clientY) {
        cursorY = ev.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	return cursorY;
}

function moveHelp(evt) {
    var helpBox = document.getElementById('forgot_password_container');
    helpBox.style.marginLeft = (mouseX(evt) - 40) + 'px';
	helpBox.style.top = (mouseY(evt) + 20) + 'px';
}

function moveDS(evt) {
    var diskSpace = document.getElementById('diskSpace_container');
    diskSpace.style.marginLeft = (mouseX(evt) - 40) + 'px';
	diskSpace.style.top = (mouseY(evt) - 132) + 'px';
}

function moveNewPost(evt) {
    var postBox = document.getElementById('dash_postHelp');
    postBox.style.marginLeft = (mouseX(evt) + 192) + 'px';
	postBox.style.marginTop = (mouseY(evt) -162) + 'px';
}

function moveHousing(evt) {
    var housingBox = document.getElementById('housing_hover');
    housingBox.style.marginLeft = (mouseX(evt) -24) + 'px';
	housingBox.style.marginTop = (mouseY(evt) -482) + 'px';
}

function moveAuto(evt) {
    var autoBox = document.getElementById('auto_hover');
    autoBox.style.marginLeft = (mouseX(evt) -24) + 'px';
	autoBox.style.marginTop = (mouseY(evt) -482) + 'px';
}

function moveForsale(evt) {
    var forsaleBox = document.getElementById('forsale_hover');
    forsaleBox.style.marginLeft = (mouseX(evt) -24) + 'px';
	forsaleBox.style.marginTop = (mouseY(evt) -482) + 'px';
}

function movePersonal(evt) {
    var personalBox = document.getElementById('personal_hover');
    personalBox.style.marginLeft = (mouseX(evt) -24) + 'px';
	personalBox.style.marginTop = (mouseY(evt) -482) + 'px';
}

function moveJobs(evt) {
    var forsaleBox = document.getElementById('jobs_hover');
    forsaleBox.style.marginLeft = (mouseX(evt) -24) + 'px';
	forsaleBox.style.marginTop = (mouseY(evt) -482) + 'px';
}

function moveOther(evt) {
    var otherBox = document.getElementById('other_hover');
    otherBox.style.marginLeft = (mouseX(evt) -24) + 'px';
	otherBox.style.marginTop = (mouseY(evt) -482) + 'px';
}

function showDS() {
	$("#diskspace_hover").fadeIn(250);
}

function hideDS() {
	$("#diskspace_hover").fadeOut(250);
}

function showPasswordHelp() {
    if (logging_in === true) {
	    $("#forgot_password_hover").fadeIn(250);
	}
}

function hidePasswordHelp() {
	$("#forgot_password_hover").fadeOut(250);
}

function showPostHelp() {
	$("#dash_postHelp").fadeIn(250);
}

function hidePostHelp() {
	$("#dash_postHelp").fadeOut(250);
}

function showFade(div) {
	$(div).fadeIn(0);
}

function hideFade(div) {
	$(div).fadeOut(0);
}

function go_fb() {
	window.location="fbDash.php";
}

function go_post() {
	window.location="addpost.html";
}

function go_home() {
	window.location="index.html";
}

function go_to(theLoc) {
	window.location=theLoc;
}

function go_url(theLoc) {
	window.open(theLoc);
}

function setperms() {
	FB.Connect.showPermissionDialog('publish_stream,email',permsresult);
}

function showCrop(height) {
	toggle_on("body_header_crop");
	toggle_on("crop_bkg");
	$("#crop_class").animate({"height": (height+10) + "px"}, 400);
}

function showCrop2(height) {
	toggle_on("body_header_crop2");
	toggle_on("crop_bkg2");
	$("#crop_class2").animate({"height": (height+10) + "px"}, 400);
}

function showCrop3(height) {
	toggle_on("body_header_crop3");
	toggle_on("crop_bkg3");
	$("#crop_class3").animate({"height": (height+10) + "px"}, 400);
}

function resizeCrop(height) {
	$("#crop_class").animate({"height": height + "px"}, 400);
}

function resizeCrop2(height) {
	$("#crop_class2").animate({"height": height + "px"}, 400);
}

function resizeCrop3(height) {
	$("#crop_class3").animate({"height": height + "px"}, 400);
}

function showForgotFields() {
	window.location = 'http://www.prettyposts.com/login_error.html';
}

function submitForgot(email) {
	var userEmail = document.getElementById(email);
	if (userEmail.value != '') {
      $.post("forgot.php", { name: userEmail.value }, function(data) {
        userEmail.value = data;
      });
	}
}

function resetForgot(passForm) {
	var userForm = document.getElementById(passForm);
	userForm.submit();
}

function submitVerify(email) {
	var userEmail = document.getElementById(email);
	if (userEmail.value != '') {
		$.post("confirmResend.php", { name: userEmail.value } );
		userEmail.value = 'Sent!';
	}
}

function permsresult(result) {
	if(result){
		window.location="fb_step_3.html";
	}
	else{
		alert("Please authorize PrettyPosts to work with your Facebook account");
	}
}

function getCookie(name) {
    var theCookies = document.cookie.split(/[; ]+/);
    for (var i = 0 ; i < theCookies.length; i++) {
        var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));
        if (aName == name) {
            return theCookies[i].substring(3,theCookies[i].length);
        }
    }
}

var r = 0; // global variable to submit form multiple times (chromium bug)

function saveDraft(userForm,mode,crops) {
	r++;

	var cropStatus = document.getElementById('cropStatus');
	var cropStatus2 = document.getElementById('cropStatus2');
	var cropStatus3 = document.getElementById('cropStatus3');
	var postStatus = document.getElementById('postStatus');
	var mainPhoto = document.getElementById('mainPhoto');
	var mainPhoto2 = document.getElementById('mainPhoto2');
	var mainPhoto3 = document.getElementById('mainPhoto3');
	var mainTitle = document.getElementById('mainTitle');
	var mainContact = document.getElementById('mainContact');
	var requiredFields = true;
	
	if (mainPhoto == null && mainPhoto2 == null && mainPhoto3 == null) {
		crops = 0;
	}
	
	switch (crops) {
		case 1: if (mainPhoto && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
		case 2: if (mainPhoto && mainPhoto2 && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
		case 3: if (mainPhoto && mainPhoto2 && mainPhoto3 && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
	}
	if (requiredFields == true) {
		postStatus.value = 'draft';
		var userPost = document.getElementById('userPost');
		userPost.setAttribute('target','_self');
		switch(mode) {
			case "update":
				switch(userForm) {
					case 1: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_auto.php?r='+r); break;
					case 2: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_housing.php?r='+r); break;
					case 3: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_jobs.php?r='+r); break;
					case 4: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_other.php?r='+r); break;
					case 5: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_event.php?r='+r); break;
					case 6: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_sale.php?r='+r); break;
				}
			break;
			
			case "create":
				switch(userForm) {
					case 1: userPost.setAttribute('action','http://www.prettyposts.com/createPost_auto.php?r='+r); break;
					case 2: userPost.setAttribute('action','http://www.prettyposts.com/createPost_housing.php?r='+r); break;
					case 3: userPost.setAttribute('action','http://www.prettyposts.com/createPost_jobs.php?r='+r); break;
					case 4: userPost.setAttribute('action','http://www.prettyposts.com/createPost_other.php?r='+r); break;
					case 5: userPost.setAttribute('action','http://www.prettyposts.com/createPost_event.php?r='+r); break;
					case 6: userPost.setAttribute('action','http://www.prettyposts.com/createPost_sale.php?r='+r); break;
				}
			break;
		}
		switch (crops) {
			case 0: userPost.submit(); break;
			case 1: if (cropStatus.value == 'cropped') {
				userPost.submit();
				} else {
					parent.cropFrame.ppCrop.cropSave();
				}
				break;
			case 2: if (cropStatus.value == 'cropped' && cropStatus2.value == 'cropped') {
				userPost.submit();
				} else {
					if (cropStatus.value != 'cropped') {
						parent.cropFrame.ppCrop.cropSave();
					}
					if (cropStatus2.value != 'cropped') {
						parent.cropFrame2.ppCrop2.cropSave();
					}
				}
				break;
			case 3: if (cropStatus.value == 'cropped' && cropStatus2.value == 'cropped' && cropStatus3.value == 'cropped') {
				userPost.submit();
				} else {
					if (cropStatus.value != 'cropped') {
						parent.cropFrame.ppCrop.cropSave();
					}
					if (cropStatus2.value != 'cropped') {
					parent.cropFrame2.ppCrop2.cropSave();
					}
					if (cropStatus3.value != 'cropped') {
					parent.cropFrame3.ppCrop3.cropSave();
					}
				}
				break;
		}
	} else {
		alert('Please enter all required fields.');
	}
}

function preview_post(userForm,mode,crops) {
	r++;
	
	var cropStatus = document.getElementById('cropStatus');
	var cropStatus2 = document.getElementById('cropStatus2');
	var cropStatus3 = document.getElementById('cropStatus3');
	var postStatus = document.getElementById('postStatus');
	var mainPhoto = document.getElementById('mainPhoto');
	var mainPhoto2 = document.getElementById('mainPhoto2')
	var mainPhoto3 = document.getElementById('mainPhoto3')
	var mainTitle = document.getElementById('mainTitle');
	var mainContact = document.getElementById('mainContact');
	var requiredFields = false;
	
	switch (crops) {
		case 1: if (mainPhoto && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
		case 2: if (mainPhoto && mainPhoto2 && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
		case 3: if (mainPhoto && mainPhoto2 && mainPhoto3 && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
	}
	
	if (requiredFields == true) {
		var userPost = document.getElementById('userPost');
		userPost.setAttribute('target','_blank');
		switch(mode) {
			case "update":
				postStatus.value = 'preview';
				switch(userForm) {
					case 1: userPost.setAttribute('action','http://www.prettyposts.com/createPost_auto.php?r='+r); break;
					case 2: userPost.setAttribute('action','http://www.prettyposts.com/createPost_housing.php?r='+r); break;
					case 3: userPost.setAttribute('action','http://www.prettyposts.com/createPost_jobs.php?r='+r); break;
					case 4: userPost.setAttribute('action','http://www.prettyposts.com/createPost_other.php?r='+r); break;
					case 5: userPost.setAttribute('action','http://www.prettyposts.com/createPost_event.php?r='+r); break;
					case 6: userPost.setAttribute('action','http://www.prettyposts.com/createPost_sale.php?r='+r); break;
				}
			break;
			
			case "create":
				postStatus.value = 'preview';
				switch(userForm) {
					case 1: userPost.setAttribute('action','http://www.prettyposts.com/createPost_auto.php?r='+r); break;
					case 2: userPost.setAttribute('action','http://www.prettyposts.com/createPost_housing.php?r='+r); break;
					case 3: userPost.setAttribute('action','http://www.prettyposts.com/createPost_jobs.php?r='+r); break;
					case 4: userPost.setAttribute('action','http://www.prettyposts.com/createPost_other.php?r='+r); break;
					case 5: userPost.setAttribute('action','http://www.prettyposts.com/createPost_event.php?r='+r); break;
					case 6: userPost.setAttribute('action','http://www.prettyposts.com/createPost_sale.php?r='+r); break;
				}
			break;
		}
		switch (crops) {
			case 1: if (cropStatus.value == 'cropped') {
				userPost.submit();
				} else {
					parent.cropFrame.ppCrop.cropSave();
				}
				break;
			case 2: if (cropStatus.value == 'cropped' && cropStatus2.value == 'cropped') {
				userPost.submit();
				} else {
					if (cropStatus.value != 'cropped') {
						parent.cropFrame.ppCrop.cropSave();
					}
					if (cropStatus2.value != 'cropped') {
						parent.cropFrame2.ppCrop2.cropSave();
					}
				}
				break;
			case 3: if (cropStatus.value == 'cropped' && cropStatus2.value == 'cropped' && cropStatus3.value == 'cropped') {
				userPost.submit();
				} else {
					if (cropStatus.value != 'cropped') {
						parent.cropFrame.ppCrop.cropSave();
					}
					if (cropStatus2.value != 'cropped') {
					parent.cropFrame2.ppCrop2.cropSave();
					}
					if (cropStatus3.value != 'cropped') {
					parent.cropFrame3.ppCrop3.cropSave();
					}
				}
				break;
		}
	} else {
		alert('Please enter all required fields.');
	}
}

function changeDesign(userForm,mode,crops) {
	r++;
	
	var cropStatus = document.getElementById('cropStatus');
	var cropStatus2 = document.getElementById('cropStatus2');
	var cropStatus3 = document.getElementById('cropStatus3');
	var postStatus = document.getElementById('postStatus');
	var mainPhoto = document.getElementById('mainPhoto');
	var mainPhoto2 = document.getElementById('mainPhoto2')
	var mainTitle = document.getElementById('mainTitle');
	var mainContact = document.getElementById('mainContact');
	var requiredFields = true;
	
	var answer = confirm("Warning: Changing layouts will reset image uploads.")
	if (answer){
		var userPost = document.getElementById('userPost');
		userPost.setAttribute('target','_self');
		switch(mode) {
			case "update":
				postStatus.value = 'change';
				switch(userForm) {
					case 1: userPost.setAttribute('action','http://www.prettyposts.com/createPost_auto.php?r='+r); break;
					case 2: userPost.setAttribute('action','http://www.prettyposts.com/createPost_housing.php?r='+r); break;
					case 3: userPost.setAttribute('action','http://www.prettyposts.com/createPost_jobs.php?r='+r); break;
					case 4: userPost.setAttribute('action','http://www.prettyposts.com/createPost_other.php?r='+r); break;
					case 5: userPost.setAttribute('action','http://www.prettyposts.com/createPost_event.php?r='+r); break;
					case 6: userPost.setAttribute('action','http://www.prettyposts.com/createPost_sale.php?r='+r); break;
				}
			break;
			
			case "create":
				postStatus.value = 'change';
				switch(userForm) {
					case 1: userPost.setAttribute('action','http://www.prettyposts.com/createPost_auto.php?r='+r); break;
					case 2: userPost.setAttribute('action','http://www.prettyposts.com/createPost_housing.php?r='+r); break;
					case 3: userPost.setAttribute('action','http://www.prettyposts.com/createPost_jobs.php?r='+r); break;
					case 4: userPost.setAttribute('action','http://www.prettyposts.com/createPost_other.php?r='+r); break;
					case 5: userPost.setAttribute('action','http://www.prettyposts.com/createPost_event.php?r='+r); break;
					case 6: userPost.setAttribute('action','http://www.prettyposts.com/createPost_sale.php?r='+r); break;
				}
			break;
		}
		userPost.submit();
	}
}

function publishDraft(userForm,mode,crops) {
	r++;
	
	var cropStatus = document.getElementById('cropStatus');
	var cropStatus2 = document.getElementById('cropStatus2');
	var cropStatus3 = document.getElementById('cropStatus3');
	var postStatus = document.getElementById('postStatus');
	var mainPhoto = document.getElementById('mainPhoto');
	var mainPhoto2 = document.getElementById('mainPhoto2')
	var mainPhoto3 = document.getElementById('mainPhoto3')
	var mainTitle = document.getElementById('mainTitle');
	var mainContact = document.getElementById('mainContact');
	var requiredFields = false;
	switch (crops) {
		case 1: if (mainPhoto && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
		case 2: if (mainPhoto && mainPhoto2 && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
		case 3: if (mainPhoto && mainPhoto2 && mainPhoto3 && mainTitle.value !='' && mainContact.value !='') {requiredFields = true;} break;
	}
	if (requiredFields == true) {
		postStatus.value = 'live';
		var userPost = document.getElementById('userPost');
		userPost.setAttribute('target','_self');
		switch(mode) {
			case "update":
				switch(userForm) {
					case 1: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_auto.php?r='+r); break;
					case 2: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_housing.php?r='+r); break;
					case 3: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_jobs.php?r='+r); break;
					case 4: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_other.php?r='+r); break;
					case 5: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_event.php?r='+r); break;
					case 6: userPost.setAttribute('action','http://www.prettyposts.com/updatePost_sale.php?r='+r); break;
				}
			break;
			
			case "create":
				switch(userForm) {
					case 1: userPost.setAttribute('action','http://www.prettyposts.com/createPost_auto.php?r='+r); break;
					case 2: userPost.setAttribute('action','http://www.prettyposts.com/createPost_housing.php?r='+r); break;
					case 3: userPost.setAttribute('action','http://www.prettyposts.com/createPost_jobs.php?r='+r); break;
					case 4: userPost.setAttribute('action','http://www.prettyposts.com/createPost_other.php?r='+r); break;
					case 5: userPost.setAttribute('action','http://www.prettyposts.com/createPost_event.php?r='+r); break;
					case 6: userPost.setAttribute('action','http://www.prettyposts.com/createPost_sale.php?r='+r); break;
				}
			break;
		}
		switch (crops) {
			case 1: if (cropStatus.value == 'cropped') {
				userPost.submit();
				} else {
					parent.cropFrame.ppCrop.cropSave();
				}
				break;
			case 2: if (cropStatus.value == 'cropped' && cropStatus2.value == 'cropped') {
				userPost.submit();
				} else {
					if (cropStatus.value != 'cropped') {
						parent.cropFrame.ppCrop.cropSave();
					}
					if (cropStatus2.value != 'cropped') {
					parent.cropFrame2.ppCrop2.cropSave();
					}
				}
				break;
			case 3: if (cropStatus.value == 'cropped' && cropStatus2.value == 'cropped' && cropStatus3.value == 'cropped') {
				userPost.submit();
				} else {
					if (cropStatus.value != 'cropped') {
						parent.cropFrame.ppCrop.cropSave();
					}
					if (cropStatus2.value != 'cropped') {
					parent.cropFrame2.ppCrop2.cropSave();
					}
					if (cropStatus3.value != 'cropped') {
					parent.cropFrame3.ppCrop3.cropSave();
					}
				}
				break;
		}
	} else {
		alert('Please enter all required fields.');
	}
}

function cropSet() {
	var cropStatus = document.getElementById('cropStatus');
	cropStatus.value = 'cropped';
}

function sendPost(postId) {
	var postEmails = document.getElementById('postEmails');
	var postSub = document.getElementById('postSub');
   	
   	$.post("emailPost.php", { addresses: postEmails.value, postSub: postSub.value, post: postId } );
	postEmails.value = 'Sent!';
	postSub.value = '';
}

function selectTa() {
    var textArea = document.getElementById('publishTa');
    textArea.select();
}

function selectTa2() {
    var textArea = document.getElementById('publishTa2');
    textArea.select();
}

function closeAlert(nId) {
    $("#alertWin").fadeOut(250);
    $("#dash_col1").animate({"margin-top":"-200px"}, 350);
   	$("#dash_col2").animate({"margin-top":"201px"}, 350);
   	$("#dash2_footer").animate({"top":"375px"}, 350);
   	$.post("notify.php", { notification: nId } );
}

