var domainName = 'http://www.ejjbed.com/';

if($("#loginPage")==true){
	$(document).ready(function() {
		$("#loginPage").validate();
	});
}

if($("#sectionForm")==true){
	$(document).ready(function() {
		$("#sectionForm").validate();
	});
}
if($("#newsForm")==true){
	$(document).ready(function() {
		$("#newsForm").validate();
	});
}

function newsValidator(){
	if($('#newsTitle').val() == ''){
		alert('الرجاء ادخال عنوان الخبر');
		$('#newsTitle').focus();
		return false;
	}
	if($('#newsBrief').val() == ''){
		alert('الرجاء ادخال مختصر الخبر');
		$('#newsBrief').focus();
		return false;
	}
}


function adsValidator(){
	if($('#bannerName').val() == ''){
		alert('الرجاء ادخال اسم الاعلان');
		$('#bannerName').focus();
		return false;
	}
	if($('#bannerType').val() == 'x'){
		alert('الرجاء اختيار نوع الاعلان');
		$('#bannerType').focus();
		return false;
	}
	if($('#bannerPlace').val() == 'x'){
		alert('الرجاء اختيار مكان الاعلان');
		$('#bannerPlace').focus();
		return false;
	}
	if($('#bannerAppear').val() == ''){
		alert('الرجاء اختيار عدد مرات ظهور الاعلان');
		$('#bannerAppear').focus();
		return false;
	}
}

function checkCommentForm(){
	if($('#commentUserName').val() == ''){
		$('#commentUserName').css('border','1px solid red');
		$('#UserNameField').fadeIn('speed');
		$('#commentUserName').focus();
		return false;
	} else {
		$('#commentUserName').css('border','1px solid #999999');
		$('#UserNameField').fadeOut('speed');
	}

	if($('#commentDesc').val() == ''){
		$('#commentDesc').css('border','1px solid red');
		$('#descField').fadeIn('speed');
		$('#commentDesc').focus();
		return false;
	} else {
		$('#commentDesc').css('border','1px solid #999999');
		$('#descField').fadeOut('speed');
	}
	document.commentForm.submit();
	 /*var commentUserName = $('#commentUserName').val();
	 var commentEmail = $('#commentEmail').val();
	 var commentDesc = $('#commentDesc').val();
	 var commentType = $('#commentType').val();
	 var communityId = $('#communityId').val();
	 document.getElementById('addCommDiv').style.display="none";
	 var queryString = "commentName=" + commentUserName + "&commentEmail=" + commentEmail + "&commentDesc=" + commentDesc + '&commentType=' + commentType + "&communityId=" + communityId;
     AJAXGet("ajaxResponse/addComment.php?"+queryString,resultHandleAddComment,false,true,"loader");
*/
}

function resultHandleAddComment(sText){
	if(sText == 1){
		$('#thxDiv').fadeIn('slow');
		setTimeout("hideThxMessage()",1000)
		document.getElementById('addCommDiv').style.display="block";
		document.getElementById('commentUserName').value = '';
		document.getElementById('commentEmail').value = '';
		document.getElementById('commentDesc').value = '';
		document.getElementById('loader').innerHTML = '';
	}
}

function hideThxMessage(){
	$('#thxDiv').fadeOut('slow');
}

function hideThxEmailMessage(){
	document.getElementById('email').disabled = false;
	$('#thxEmail').hide();
	document.getElementById('email').value = '';
	$('#titleEmail').fadeIn("speed");
	$('#newsLetter').fadeIn("speed");
	$('#buttonId').fadeIn("speed");
}

function addEmail(){
	 var email = $('#email').val();
	 if(email == '' || email == 'الرجاء ادخال البريد الالكتروني ...'){
		 document.getElementById('email').value = '';
		 $('#email').val='';
		 $('#email').css('border','1px solid red');
		 $('#email').focus();
		 return false;
	 }
	 var at="@"
     var dot="."
	 var lat=email.indexOf(at)
	 var lstr=email.length
	 var ldot=email.indexOf(dot)
	 if (email.indexOf(at)==-1){
	     $('#email').css('border','1px solid red');
	     return false
	 }
	 if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){
		 $('#email').css('border','1px solid red');
		 return false
	 }
     if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
    	 $('#email').css('border','1px solid red');
    	 return false
	 }
	 if (email.indexOf(at,(lat+1))!=-1){
		 $('#email').css('border','1px solid red');
		 return false
	 }
	 if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
		 $('#email').css('border','1px solid red');
		 return false
	 }
	 if (email.indexOf(dot,(lat+2))==-1){
		 $('#email').css('border','1px solid red');
		 return false
	 }
	 if (email.indexOf(" ")!=-1){
		 $('#email').css('border','1px solid red');
		 return false
	 }
	 document.getElementById('email').disabled = true;
	 var queryString = "email=" + email;
     AJAXGet("ajaxResponse/addEmail.php?"+queryString,resultHandleAddEmail,false,true,"loader");
}

function resultHandleAddEmail(sText){
	if(sText == 1){
		$('#titleEmail').hide();
		$('#newsLetter').hide();
		$('#buttonId').hide();
		$('#thxEmail').fadeIn('slow');
		setTimeout("hideThxEmailMessage()",2000)
	}
}

function commentTextFocus(field , txt) {
	if(document.getElementById(field).value == txt){
		document.getElementById(field).value = '';
		document.getElementById(field).style.color="#000000";
	}
}


function commentTextBlur(field , txt) {
	if(document.getElementById(field).value == ''){
		document.getElementById(field).style.border="1px solid #AB9444";
		document.getElementById(field).style.color="#909090";
		document.getElementById(field).value = txt;
	}
}

function submitSearch(){
		var searchTxt = document.getElementById("search").value;
		if(searchTxt == '' || searchTxt == 'الرجاء ادخال كلمة البحث ...'){
			$('#search').css('border','1px solid red');
			document.getElementById('search').value = '';
			$('#search').focus();
			return false
		}
}

function checkContactUsForm(){
	if($('#name').val() == ''){
		$('#name').css('border','1px solid red');
		$('#nameField').fadeIn('speed');
		$('#name').focus();
		return false;
	} else {
		$('#name').css('border','1px solid #999999');
		$('#nameField').fadeOut('speed');
	}

	if($('#emailTxt').val() == ''){
		$('#emailTxt').css('border','1px solid red');
		$('#emailField').fadeIn('speed');
		$('#emailTxt').focus();
		return false;
	} else {
		$('#emailTxt').css('border','1px solid #999999');
		$('#emailField').fadeOut('speed');
	}
	
	if($('#subject').val() == ''){
		$('#subject').css('border','1px solid red');
		$('#subjectField').fadeIn('speed');
		$('#subject').focus();
		return false;
	} else {
		$('#subject').css('border','1px solid #999999');
		$('#subjectField').fadeOut('speed');
	}
	
	if($('#message').val() == ''){
		$('#message').css('border','1px solid red');
		$('#messageField').fadeIn('speed');
		$('#message').focus();
		return false;
	} else {
		$('#message').css('border','1px solid #999999');
		$('#messageField').fadeOut('speed');
	}
	 var name = $('#name').val();
	 var emailTxt = $('#emailTxt').val();
	 var subject = $('#subject').val();
	 var message = $('#message').val();
	 document.getElementById('contactForm').style.display="none";
	 var queryString = "name=" + name + "&emailTxt=" + emailTxt + "&subject=" + subject + '&message=' + message;
     AJAXGet("ajaxResponse/sendMessage.php?"+queryString,resultHandleSendMessage,false,true,"loader");
}


function resultHandleSendMessage(sText){
	if(sText == 1){
		$('#thxDiv').fadeIn('slow');
		setTimeout("hideThxMessage()",4000)
		document.getElementById('contactForm').style.display="block";
		document.getElementById('name').value = '';
		document.getElementById('emailTxt').value = '';
		document.getElementById('subject').value = '';
		document.getElementById('message').value = '';
		document.getElementById('loader').innerHTML = '';
	}
}

