// form validation function //
function customerFormValidation(){
	var name = $("#name").val();
	var email = $("#email").val();
	var subject = $("#subject").val();
	var description = $("#description").val();
	
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		
	if(name == "") {
		inlineMsg('name','<strong>Error</strong> You must enter your name.',2);
		return false;
	}
	if(!name.match(nameRegex)) {
		inlineMsg('name','<strong>Error</strong> You have entered an invalid name.',2);
		return false;
	}
	if(email == "") {
		inlineMsg('email','<strong>Error</strong><br />You must enter your email.',2);
		return false;
	}
	if(!email.match(emailRegex)) {
		inlineMsg('email','<strong>Error</strong> You have entered an invalid email.',2);
		return false;
	}
	if(subject == "") {
		inlineMsg('subject','<strong>Error</strong> You must enter your email.',2);
		return false;
	}
	if(description == "") {
		inlineMsg('description','<strong>Error</strong> You must enter a message.', 2);
		return false;
	}
	return true;
}// end customerFormValidation() function

function regValidationEdtPrfl(){
	var txtfname = jQuery("#txtfname").val();
	var txtlname = jQuery("#txtlname").val();
	var txtemail = jQuery("#txtemail").val();
	var txtaddress1 = jQuery("#txtaddress1").val();
	var regcbostates = jQuery("#regcbostates").val();
	
	var regcbocities = jQuery("#cbocities").val();
	var txtCity = jQuery("#txtCity").val();
	var txtzipcode = jQuery("#txtzipcode").val();
	//alert(cbostates);return false;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		
	if(txtfname == ""){
		inlineMsg('txtfname','<strong>Error</strong> Please enter your first name.',2);
		return false;
	}
	if(!txtfname.match(nameRegex)){
		inlineMsg('txtfname','<strong>Error</strong> Please entered a valid name.',2);
		return false;
	}
	if(txtlname == ""){
		inlineMsg('txtlname','<strong>Error</strong> Please enter your last name.',2);
		return false;
	}
	if(!txtlname.match(nameRegex)){
		inlineMsg('txtlname','<strong>Error</strong> Please enter a valid name.',2);
		return false;
	}
	
	if(txtemail == ""){
		inlineMsg('txtemail','<strong>Error</strong><br /> Please enter your email.',2);
		return false;
	}
	if(!txtemail.match(emailRegex)){
		inlineMsg('txtemail','<strong>Error</strong> Please entered a valid email.',2);
		return false;
	}
	if(txtaddress1 == ""){
		inlineMsg('txtaddress1','<strong>Error</strong><br /> Please enter your address.',2);
		return false;
	}
	if(regcbostates == 0){
		inlineMsg('regcbostates','<strong>Error</strong> Please select state.', 2);
		return false;
	}
	if(regcbocities == 0){
		inlineMsg('cbocities','<strong>Error</strong> Please select city.', 2);
		return false;
	}
	
	if(regcbocities == 'OTHER'){
		if(txtCity == ''){	
			inlineMsg('txtCity','<strong>Error</strong> Please enter other city.', 2);
			return false;
		}
	}
	
	if(txtzipcode == ""){
		inlineMsg('txtzipcode','<strong>Error</strong> Please select city.', 2);
		return false;
	}
	return true;
}// end regValidation() function

function regValidation(){
	var txtfname = jQuery("#txtfname").val();
	var txtlname = jQuery("#txtlname").val();
	var txtpaswd = jQuery("#txtpaswd").val();
	var txtrepaswd = jQuery("#txtrepaswd").val();
	var txtemail = jQuery("#txtemail").val();
	var txtaddress1 = jQuery("#txtaddress1").val();
	var regcbostates = jQuery("#regcbostates").val();
	
	var regcbocities = jQuery("#cbocities").val();
	var txtCity = jQuery("#txtCity").val();
	var txtzipcode = jQuery("#txtzipcode").val();
	//alert(cbostates);return false;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		
	if(txtfname == ""){
		inlineMsg('txtfname','<strong>Error</strong> Please enter your first name.',2);
		return false;
	}
	if(!txtfname.match(nameRegex)){
		inlineMsg('txtfname','<strong>Error</strong> Please entered a valid name.',2);
		return false;
	}
	if(txtlname == ""){
		inlineMsg('txtlname','<strong>Error</strong> Please enter your last name.',2);
		return false;
	}
	if(!txtlname.match(nameRegex)){
		inlineMsg('txtlname','<strong>Error</strong> Please enter a valid name.',2);
		return false;
	}
	if(txtpaswd == ""){
		inlineMsg('txtpaswd','<strong>Error</strong> Please enter password.',2);
		return false;
	}
	if(txtrepaswd == ""){
		inlineMsg('txtrepaswd','<strong>Error</strong> Please enter re-password.',2);
		return false;
	}
	if(txtpaswd != txtrepaswd){
		inlineMsg('txtrepaswd','<strong>Error</strong> Provided passwords are not matching.',2);
		return false;
	}
	if(txtemail == ""){
		inlineMsg('txtemail','<strong>Error</strong><br /> Please enter your email.',2);
		return false;
	}
	if(!txtemail.match(emailRegex)){
		inlineMsg('txtemail','<strong>Error</strong> Please entered a valid email.',2);
		return false;
	}
	if(txtaddress1 == ""){
		inlineMsg('txtaddress1','<strong>Error</strong><br /> Please enter your address.',2);
		return false;
	}
	if(regcbostates == 0){
		inlineMsg('regcbostates','<strong>Error</strong> Please select state.', 2);
		return false;
	}
	if(regcbocities == 0){
		inlineMsg('cbocities','<strong>Error</strong> Please select city.', 2);
		return false;
	}
	
	if(regcbocities == 'OTHER'){
		if(txtCity == ''){	
			inlineMsg('txtCity','<strong>Error</strong> Please enter other city.', 2);
			return false;
		}
	}
	
	if(txtzipcode == ""){
		inlineMsg('txtzipcode','<strong>Error</strong> Please select city.', 2);
		return false;
	}
	return true;
}// end regValidation() function


function regValidationFree(){
	var txtfname = jQuery("#txtfname").val();
	var txtlname = jQuery("#txtlname").val();
	var txtpaswd = jQuery("#txtpaswd").val();
	var txtrepaswd = jQuery("#txtrepaswd").val();
	var txtemail = jQuery("#txtemail").val();
	var txtaddress1 = jQuery("#txtaddress1").val();
	var regcbostates = jQuery("#regcbostates").val();
	var regcbocities = jQuery("#cbocities").val();
	var txtCity = jQuery("#txtCity").val();
	var txtzipcode = jQuery("#txtzipcode").val();
	//alert(cbostates);return false;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	
	if(txtfname == ""){
		inlineMsg('txtfname','<strong>Error</strong> Please enter your first name.',2);
		return false;
	}
	
	if(!txtfname.match(nameRegex)){
		inlineMsg('txtfname','<strong>Error</strong> Please entered a valid name.',2);
		return false;
	}
	if(txtlname == ""){
		inlineMsg('txtlname','<strong>Error</strong> Please enter your last name.',2);
		return false;
	}
	if(!txtlname.match(nameRegex)){
		inlineMsg('txtlname','<strong>Error</strong> Please enter a valid name.',2);
		return false;
	}
	if(txtpaswd == ""){
		inlineMsg('txtpaswd','<strong>Error</strong> Please enter password.',2);
		return false;
	}
	if(txtrepaswd == ""){
		inlineMsg('txtrepaswd','<strong>Error</strong> Please enter re-password.',2);
		return false;
	}
	if(txtpaswd != txtrepaswd){
		inlineMsg('txtrepaswd','<strong>Error</strong> Provided passwords are not matching.',2);
		return false;
	}
	if(txtemail == ""){
		inlineMsg('txtemail','<strong>Error</strong><br /> Please enter your email.',2);
		return false;
	}
	if(!txtemail.match(emailRegex)){
		inlineMsg('txtemail','<strong>Error</strong> Please entered a valid email.',2);
		return false;
	}
	if(txtaddress1 == ""){
		inlineMsg('txtaddress1','<strong>Error</strong><br /> Please enter your address.',2);
		return false;
	}
	if(regcbostates == 0){
		inlineMsg('regcbostates','<strong>Error</strong> Please select state.', 2);
		return false;
	}
	if(regcbocities == 0){
		inlineMsg('cbocities','<strong>Error</strong> Please select city.', 2);
		return false;
	}
	
	if(regcbocities == 'OTHER'){
		if(txtCity == ''){	
			inlineMsg('txtCity','<strong>Error</strong> Please enter other city.', 2);
			return false;
		}
	}
	
	if(txtzipcode == ""){
		inlineMsg('txtzipcode','<strong>Error</strong> Please enter zip.', 2);
		return false;
	}
	return true;
}
function quoteFormValidation(){
	var txtname = $("#txtname").val();
	var txtemail = $("#txtemail").val();
	var txtphoneno = $("#txtphoneno").val();
	var txtactrequired = $("#txtactrequired").val();
	var txttimeperiod = $("#txttimeperiod").val();
	var txtlocation = $("#txtlocation").val();
	var txteventdesc = $("#txteventdesc").val();
	//alert(cbostates);return false;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		
	if(txtname == "") {
		inlineMsg('txtname','<strong>Error</strong> Please enter your name.',2);
		return false;
	}
	if(!txtname.match(nameRegex)) {
		inlineMsg('txtname','<strong>Error</strong> Please entered a valid name.',2);
		return false;
	}
	if(txtemail == "") {
		inlineMsg('txtemail','<strong>Error</strong><br /> Please enter your email.',2);
		return false;
	}
	if(!txtemail.match(emailRegex)) {
		inlineMsg('txtemail','<strong>Error</strong> Please entered a valid email.',2);
		return false;
	}
	if(txtphoneno == "") {
		inlineMsg('txtphoneno','<strong>Error</strong> Please enter your phone number.', 2);
		return false;
	}
	if(txtactrequired == 0) {
		inlineMsg('txtactrequired','<strong>Error</strong> Please enter date.', 2);
		return false;
	}
	if(txtlocation == 0) {
		inlineMsg('txtlocation','<strong>Error</strong> Please enter your location.', 2);
		return false;
	}
	if(txteventdesc == 0) {
		inlineMsg('txteventdesc','<strong>Error</strong> Please enter some description.', 2);
		return false;
	}
	return true;	
}// end quoteFormValidation() function

function venuFormValidation(){
	var txtfname = $("#txtfname").val();
	var txtlname = $("#txtlname").val();
	var txtpaswd = $("#txtpaswd").val();
	var txtrepaswd = $("#txtrepaswd").val();
	var txtemail = $("#txtemail").val();
	var regcbostates = $("#regcbostates").val();
	var cbocities = $("#cbocities").val();
	var txtzipcode = $("#txtzipcode").val();
	//alert(cbostates);return false;
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		
	if(txtfname == "") {
		inlineMsg('txtfname','<strong>Error</strong> Please enter your Venue name.',2);
		return false;
	}
	if(!txtfname.match(nameRegex)) {
		inlineMsg('txtfname','<strong>Error</strong> Please entered a valid name.',2);
		return false;
	}
	if(txtlname == "") {
		inlineMsg('txtlname','<strong>Error</strong> Please enter your Owner name.',2);
		return false;
	}
	if(!txtlname.match(nameRegex)) {
		inlineMsg('txtlname','<strong>Error</strong> Please enter a valid name.',2);
		return false;
	}
	if(txtpaswd == "") {
		inlineMsg('txtpaswd','<strong>Error</strong> Please enter password.',2);
		return false;
	}
	if(txtrepaswd == "") {
		inlineMsg('txtrepaswd','<strong>Error</strong> Please enter re-password.',2);
		return false;
	}
	if(txtpaswd != txtrepaswd){
		inlineMsg('txtrepaswd','<strong>Error</strong> Provided passwords are not matching.',2);
		return false;
	}
	if(txtemail == "") {
		inlineMsg('txtemail','<strong>Error</strong><br /> Please enter your email.',2);
		return false;
	}
	if(!txtemail.match(emailRegex)) {
		inlineMsg('txtemail','<strong>Error</strong> Please entered a valid email.',2);
		return false;
	}
	if(regcbostates == 0) {
		inlineMsg('regcbostates','<strong>Error</strong> Please select state.', 2);
		return false;
	}
	if(cbocities == 0) {
		inlineMsg('cbocities','<strong>Error</strong> Please select city.', 2);
		return false;
	}
	if(txtzipcode == '') {
		inlineMsg('txtzipcode','<strong>Error</strong> Please enter zip code.', 2);
		return false;
	}
	return true;
}// end venuFormValidation() function

function soundFormValidation(){
	var txtfiletitle = $("#txtfiletitle").val();
	var flupload = $("#flupload").val();
	
	if(txtfiletitle == "") {
		inlineMsg('txtfiletitle','<strong>Error</strong> Please enter title of the file.', 2);
		return false;
	}
	if(flupload == "") {
		inlineMsg('flupload','<strong>Error</strong> Please brows the file.', 2);
		return false;
	}
	return true;
}// end soundFormValidation() function

function videoFormValidation(){
	var txtfiletitle = $("#txtfiletitle").val();
	var flupload = $("#flupload").val();
	var txtfile = $("#txtfile").val();
	
	if(txtfiletitle == "") {
		inlineMsg('txtfiletitle','<strong>Error</strong> Please enter title of the file.', 2);
		return false;
	}

	if($("input[name='rdvtype']:checked").val() == "youtube"){
		if(txtfile == ""){
			inlineMsg('txtfile','<strong>Error</strong> Please enter the URL.', 2);
			return false;
		}
	}else if($("input[name='rdvtype']:checked").val() == "filelink"){
		if(flupload == "") {
			inlineMsg('flupload','<strong>Error</strong> Please brows the file.', 2);
			return false;
		}
	}
	return true;
}// end videoFormValidation() function

function photoFormValidation(){
	var flupload = $("#flupload").val();
	
	if(flupload == "") {
		inlineMsg('flupload','<strong>Error</strong> Please brows the file.', 2);
		return false;
	}
	return true;
}// end photoFormValidation() function

function searchFormValidation(){
	var cbostates = $("#cbostates").val();
	var cboperformertype = $("#cboperformertype").val();
	var cbocategory = $("#cbocategory").val();
	
	if(cbostates == 0) {
		alert("Please select state.");
		$("#cbostates").focus();
		return false;
	}
	if(cboperformertype == 0) {
		alert("Please select performer.");
		$("#cboperformertype").focus();
		return false;
	}
	if(cbocategory == 0) {
		alert("Please select category.");
		$("#cbocategory").focus();
		return false;
	}
	return true;
}// end searchFormValidation() function

function checkEmailExists(email){
	jQuery.ajax({
		type: "GET",
		url: "ajaxfunctions.php?action=chekEmailExists&emial="+email,
		dataType: "html",
		success: function(response){
			if(response == 1){
				inlineMsg('txtemail','<strong>Error</strong> This email address is not available. Please enter another.', 4);
			}
			//jQuery('#ViewMap').html(response);
			//$('#Div_State').show();
		},
		error: function(){
			alert("Error occured during Ajax request...");
		}
	});
}// end checkEmailExists() function

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

//function to toggle eu and usa search
function toggleSearch(type){
	
	if(type == "EU"){
		
		jQuery("#us_search").fadeOut(500);
		setTimeout('jQuery("#eu_search").fadeIn(1000)',500);
		
	}else{
		
		jQuery("#eu_search").fadeOut(500);
		setTimeout('jQuery("#us_search").fadeIn(1000)',500);
		
	}
	
}



// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "../images/msg_arrow.gif"; 
}
