// form validation function //
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{	xmlhttp=new XMLHttpRequest();}
	catch(e){		
		try{	xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");}
		catch(e){
			try{	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");	}
			catch(e1){	xmlhttp=false;}
		}
	}	
	return xmlhttp;
}
function check_user(element){
	var unique_user_name = element.value;
	var strURL="check_user.php?s="+Math.random()+"&user_name="+unique_user_name;
	var req = getXMLHTTP();
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					if(unique_user_name == ''){
						document.getElementById('txtHint').innerHTML='false';
						}
					else{
						if(req.responseText.substr(0,24) == 'Username already exists.'){
							inlineMsg('unique_user_name','Username already exists. Please try another username.',2);
							document.getElementById('txtHint').innerHTML='false';
						}else{
							document.getElementById('txtHint').innerHTML='true';
						}
					}
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}
function check_email(element){
	var email_id = element.value;
	var strURL="check_email.php?s="+Math.random()+"&email_id="+email_id;
	var req = getXMLHTTP();
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					if(email_id == ''){
						document.getElementById('txtHint1').innerHTML='false';
						}
					else{
						if(req.responseText.substr(0,21) == 'Email already exists.'){
							inlineMsg('email_id','Email you have entered is already registered with us.',2);
							document.getElementById('txtHint1').innerHTML='false';
						}else{
							document.getElementById('txtHint1').innerHTML='true';
						}
					}					
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}

function frmRegister(form) {
  var first_name = form.first_name.value;
  var last_name = form.last_name.value;
  var unique_user_name = form.unique_user_name.value;
  var unique_password = form.unique_password.value;
  var email_id = form.email_id.value;
  var dob = form.dob.value;
  var address = form.address.value;
  var city = form.city.value;
  var country_code = form.country_code.value;
  var zipcode = form.zipcode.value;
  
  var txtHint = document.getElementById('txtHint').innerHTML;
  var txtHint1 = document.getElementById('txtHint1').innerHTML;
//  var gender = form.gender.value;
//  var message = form.message.value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var passwordRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  //var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  var emailRegex = /^[a-zA-Z][\w\.-_]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-_]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
   var zip = /^([A-Z0-9]{4,11})?$/i;
  if(first_name == "") {
    inlineMsg('first_name','Please enter first name.',2);
    return false;
  }else if(!first_name.match(nameRegex)) {
     inlineMsg('first_name','Please enter valid first name.',2);
    return false;
   }
  if(last_name == "") {
    inlineMsg('last_name','Please enter last name.',2);
    return false;
  }else if(!last_name.match(nameRegex)) {
     inlineMsg('last_name','Please enter valid last name.',2);
    return false;
   }
  if(unique_user_name == "") {
    inlineMsg('unique_user_name','Please enter user name.',2);
    return false;
  }else if(txtHint == 'false'){
	  inlineMsg('unique_user_name','Username already exists. Please try another username.',2);
    return false;
  }
 /* if(user_name.length < 8 ) {
    inlineMsg('user_name','Username must be alteast 8 characters in length.',2);
    return false;
  }*/
  if(unique_password == "") {
    inlineMsg('unique_password','Please enter your password.',2);
    return false;
  }
   if(email_id == "") {
     inlineMsg('email_id','Please enter your email.',2);
     return false;
   }else if(!email_id.match(emailRegex)) {
     inlineMsg('email_id','<strong>Error</strong><br />Please enter valid email.',2);
    return false;
   }else if(txtHint1 == 'false'){
	   inlineMsg('email_id','Email you have entered is already registered with us.',2);
	   return false;
   }
  if(dob == "") {
    inlineMsg('dob','Please enter your dob.',2);
    return false;
  }
  if(address == "") {
    inlineMsg('address','Please enter address.',2);
    return false;
  }
  if(city == "") {
    inlineMsg('city','Please enter city.',2);
    return false;
  }
  if(country_code == "") {
    inlineMsg('country_code','Please select country.',2);
    return false;
  }
  if(!zipcode.match(zip)) {
     inlineMsg('zipcode','<strong>Error</strong><br />Please enter valid Zipcode.',2);
     return false;
   }

//   if(!email.match(emailRegex)) {
//     inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',2);
//     return false;
//   }
//  if(gender == "") {
//    inlineMsg('gender','<strong>Error</strong><br />You must select your gender.',2);
//    return false;
//  }
//  if(message == "") {
//    inlineMsg('message','You must enter a message.');
//    return false;
// }
//  if(message.match(messageRegex)) {
//    inlineMsg('message','You have entered an invalid password.');
//    return false;
//  }
  return true;
}
function frmEditProfile(form) {
  var first_name = form.first_name.value;
  var last_name = form.last_name.value;
  var dob = form.dob.value;
  var address = form.address.value;
  var city = form.city.value;
  var country_code = form.country_code.value;
  var zipcode = form.zipcode.value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[a-zA-Z][\w\.-_]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-_]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
  var zip = /^([A-Z0-9]{4,11})?$/i;
  if(first_name == "") {
    inlineMsg('first_name','Please enter first name.',2);
    return false;
  }
  if(last_name == "") {
    inlineMsg('last_name','Please enter last name.',2);
    return false;
  }
  if(dob == "") {
    inlineMsg('dob','Please enter your dob.',2);
    return false;
  }
  if(address == "") {
    inlineMsg('address','Please enter address.',2);
    return false;
  }
  if(city == "") {
    inlineMsg('city','Please enter city.',2);
    return false;
  }
  if(country_code == "") {
    inlineMsg('country_code','Please select country.',2);
    return false;
  }
   if(!zipcode.match(zip)) {
     inlineMsg('zipcode','<strong>Error</strong><br />Please enter valid Zipcode.',2);
     return false;
   }

  return true;
}

function frmLogin(form) {
  var user_name = form.user_name.value;
  var password = form.password.value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var passwordRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  if(user_name == "" || user_name == "User Name") {
    inlineMsg('user_name','Please enter user name.',2);
    return false;
  }
  if(!user_name.match(nameRegex)) {
    inlineMsg('user_name','Please enter valid user name.',2);
    return false;
  }
  if(password == "") {
    inlineMsg('password','Please enter your password.',2);
    return false;
  }
  return true;
}
function ChangePassword(form) {
  var old_password = form.old_password.value;
  var new_password = form.new_password.value;
  var confirm_password = form.confirm_password.value;
  
  if(old_password == "") {
    inlineMsg('old_password','Please enter current password.',2);
    return false;
  }
  if(new_password == "") {
    inlineMsg('new_password','Please enter new password.',2);
    return false;
  }
  if(confirm_password == "") {
    inlineMsg('confirm_password','Please confirm your password.',2);
    return false;
  }
  if(new_password != confirm_password) {
    inlineMsg('confirm_password','Confirm password is not same as new password.',2);
    return false;
  }

  return true;
}

function validateContact(form) {
  var first_name = form.first_name.value;
  var last_name = form.last_name.value;
  var email = form.email.value;
  var emailRegex = /^[a-zA-Z][\w\.-_]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-_]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
  /*var phoneRegex = /^\(\d{3]\) \d{3}-\d{4}/;*/
  
 if(first_name == "") {
    inlineMsg('first_name','Please enter first name.',2);
    return false;
  }
  if(last_name == "") {
    inlineMsg('last_name','Please enter last name.',2);
    return false;
  }
  if(email == "") {
    inlineMsg('email','Please enter email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
     inlineMsg('email','<strong>Error</strong><br />Please enter valid email.',2);
     return false;
   }
  /* if(!mobile.match(phoneRegex)) {
     inlineMsg('mobile','<strong>Error</strong><br />Please enter valid mobile number.',2);
     return false;
   }*/

  return true;
}

function validateFeedback(form) {
  var name = form.name.value;
  var email_feedback = form.email_feedback.value;
  var mobile_feedback = form.mobile_feedback.value;
   var feedback = form.feedback.value;
  var emailRegex = /^[a-zA-Z][\w\.-_]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-_]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
  /*var phoneRegex = /^\(\d{3]\) \d{3}-\d{4}/; */
  var phoneRegex = /[^0-9\ \+\-\(\)]/;
  /*var phoneRegex = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/*/
  
 if(name == "" || name == "Name") {
    inlineMsg('name','Please enter your name.',2);
    return false;
  }
  if(email_feedback == "" || email_feedback == "Email ID") {
    inlineMsg('email_feedback','Please enter your Email.',2);
    return false;
  }
  if(!email_feedback.match(emailRegex)) {
     inlineMsg('email_feedback','<strong>Error</strong><br />Please enter valid email.',2);
     return false;
   }
   if(mobile_feedback.match(phoneRegex) && mobile_feedback != 'Mobile No') {
     inlineMsg('mobile_feedback','<strong>Error</strong><br />Please enter valid mobile number.',2);
     return false;
   }
   if(feedback == "" || feedback == "Comment") {
    inlineMsg('feedback','Please enter your comment.',2);
    return false;
  }

  sendFeedback(form);
}

function sendFeedback(form){
	var strURL="ajax_send_feedback.php?s="+Math.random();
	for(i=0;i<form.elements.length;i++){
	strURL += '&'+form.elements[i].name+'='+form.elements[i].value;
	}
	var req = getXMLHTTP();
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					document.getElementById('divFeedback').innerHTML=req.responseText;
					form.reset();
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}

function frmforgotPassword(form) {
  var email_password = form.email_password.value;
  var emailRegex = /^[a-zA-Z][\w\.-_]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-_]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
  
  if(email_password == "" || email_password == "Email ID") {
    inlineMsg('email_password','Please enter your Email.',2);
    return false;
  }
  if(!email_password.match(emailRegex)) {
     inlineMsg('email_password','<strong>Error</strong><br />Please enter valid email.',2);
     return false;
   }

  sendPassword(form);
}

function sendPassword(form){
	var email_password = document.getElementById('email_password').value;
	var strURL="ajax_send_password.php?email_password="+email_password+"&s="+Math.random();
	var req = getXMLHTTP();
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					document.getElementById('divForgotPassword').innerHTML=req.responseText;
					form.reset();
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}

function validateInvitation(form) {
  var event_title = form.event_title.value;
  var mobile = form.mobile.value;
  var phone = form.phone.value;
  var location = form.location.value;
  var address = form.address.value;
  var city = form.city.value;
  var country_code = form.country_code.value;
  var zipcode = form.zipcode.value;
  var start_date = form.start_date.value;
  var message = form.message.value;
 
  var phoneRegex = /^([0-9\ \+\-\(\)]{10,16})?$/i;
  var alphanumeric = /^[a-zA-Z0-9_ .,\-\'\\\/]*$/;
  var zip = /^([A-Z0-9]{4,11})?$/i;
  
 
  if(event_title == "") {
    inlineMsg('event_title','Please enter event title.',2);
    return false;
  }
  if(!mobile.match(phoneRegex)) {
     inlineMsg('mobile','<strong>Error</strong><br />Please enter valid mobile number.',2);
     return false;
   }
   if(!phone.match(phoneRegex)) {
     inlineMsg('phone','<strong>Error</strong><br />Please enter valid phone number.',2);
     return false;
   }
   if(!location.match(alphanumeric)) {
     inlineMsg('location','<strong>Error</strong><br />Please enter valid location.',2);
     return false;
   }
   if(!address.match(alphanumeric)) {
     inlineMsg('address','<strong>Error</strong><br />Please enter valid address.',2);
     return false;
   }
   if(!city.match(alphanumeric)) {
     inlineMsg('city','<strong>Error</strong><br />Please enter valid city.',2);
     return false;
   }
    if(country_code == "") {
    inlineMsg('country_code','Please select country.',2);
    return false;
  }
  if(!zipcode.match(zip)) {
     inlineMsg('zipcode','<strong>Error</strong><br />Please enter valid Zipcode.',2);
     return false;
   }
   if(start_date == "") {
    inlineMsg('start_date','Please enter start date.',2);
    return false;
  }
return true
}

function validateSend(form) {
  var contact_list = form.contact_list.value;
  var multipleEmailRegex = /^(([a-zA-Z][\w\.-_]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-_]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z])*([,])*)*$/;
  /*var multipleEmailRegex = /^((\w+([-_.']\w+)*@\w+([-_.]\w+)*\.\w+([-_.]\w+)*)*([,])*)*$/;*/
  if(contact_list == "") {
    inlineMsg('contact_list','Please enter atleast one email id.',2);
    return false;
  }
   if(!contact_list.match(multipleEmailRegex)) {
     inlineMsg('contact_list','<strong>Error</strong><br />Please enter valid comma seperated email ids.',2);
     return false;
   }
return true;
}

function removeSpaces(string) {
 return trim(string.split(/[\s\n\t\r\f]+/).join(''));
}
function ltrim(str) { 
	for(var k = 0; k < str.length && isComma(str.charAt(k)); k++);
	return str.substring(k, str.length);
}

function rtrim(str) {
	for(var j=str.length-1; j>=0 && isComma(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isComma(charToCheck) {
	var CommaChar = ",";
	return (CommaChar.indexOf(charToCheck) != -1);
}

function validatePayment(ele){
	var payment_amount = ele;
	/*var numberRegex = /^[0-9]*$/;*/
	var decimalNumberRegex = /^[0-9]*(\.)?[0-9]+$/;

   if(!payment_amount.match(decimalNumberRegex)) {
     inlineMsg('payment_amount','Please enter valid number.',2);
     return false;
   }
	return true;
}
function validatePartyIdea(form) {
	if(form.idea_title){
  var idea_title = form.idea_title.value;
  var suggestion = form.suggestion.value;
  if(idea_title == "") {
    inlineMsg('idea_title','Please enter party idea title.',2);
    return false;
  }
    if(suggestion == "") {
    inlineMsg('suggestion','Please enter your suggestion.',2);
    return false;
  }
	}else{
	 var name_comment = form.name_comment.value;
 	 var email = form.email.value;
	 var comment = form.comment.value;
	  var emailRegex = /^[a-zA-Z][\w\.-_]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-_]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	 
	  if(name_comment == "") {
    inlineMsg('name_comment','Please enter your name.',2);
    return false;
  }
    if(email == "") {
    inlineMsg('email','Please enter your email.',2);
    return false;
  }else if(!email.match(emailRegex)) {
     inlineMsg('email','<strong>Error</strong><br />Please enter valid email.',2);
     return false;
   }
   if(comment == "") {
    inlineMsg('comment','Please enter your comment.',2);
    return false;
  }
		}
return true
 // sendPassword(form);
}

function validatePopularEvent(form) {
  var popular_event_title = form.popular_event_title.value;
  var start_time = form.start_time.value;
  var venue = form.venue.value;
  var popular_event_desc = form.popular_event_desc.value;
  
  if(popular_event_title == "") {
    inlineMsg('popular_event_title','Please enter popular event title.',2);
    return false;
  }
    if(start_time == "") {
    inlineMsg('start_time','Please select start time.',2);
    return false;
  }
  if(venue == "") {
    inlineMsg('venue','Please enter popular event venue.',2);
    return false;
  }
  if(popular_event_desc == "") {
    inlineMsg('popular_event_desc','Please enter popular event description.',2);
    return false;
  }
 
return true
 // sendPassword(form);
}
function validateAnnouncementSend(form) {
  var contact_list = form.contact_list.value;
  var multipleEmailRegex = /^(([a-zA-Z][\w\.-_]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-_]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z])*([,])*)*$/;
  /*var multipleEmailRegex = /^((\w+([-_.']\w+)*@\w+([-_.]\w+)*\.\w+([-_.]\w+)*)*([,])*)*$/;*/
  if(contact_list == "") {
    inlineMsg('contact_list','Please enter atleast one email id.',2);
    return false;
  }
   if(!contact_list.match(multipleEmailRegex)) {
     inlineMsg('contact_list','<strong>Error</strong><br />Please enter valid comma seperated email ids.',2);
     return false;
   }
return true;
}
function validateAnnouncement(form) {
  var announcement_title = form.announcement_title.value;
  var mobile = form.mobile.value;
  var phone = form.phone.value;
  var message = form.message.value;
 
  var phoneRegex = /^([0-9\ \+\-\(\)]{10,16})?$/i;
  var alphanumeric = /^[a-zA-Z0-9_ .,\-\'\\\/]*$/;

  if(announcement_title == "") {
    inlineMsg('announcement_title','Please enter announcement title.',2);
    return false;
  }
  if(!mobile.match(phoneRegex)) {
     inlineMsg('mobile','<strong>Error</strong><br />Please enter valid mobile number.',2);
     return false;
   }
   if(!phone.match(phoneRegex)) {
     inlineMsg('phone','<strong>Error</strong><br />Please enter valid phone number.',2);
     return false;
   }
return true
}
function show_hide(ele){
	if(ele == 'div1'){
		document.getElementById('div1').style.display='block';
		document.getElementById('div2').style.display='none';
		document.getElementById('div3').style.display='none';
		document.getElementById('div4').style.display='none';
	}
	if(ele == 'div2'){
		document.getElementById('div1').style.display='none';
		document.getElementById('div2').style.display='block';
		document.getElementById('div3').style.display='none';
		document.getElementById('div4').style.display='none';
	}
	if(ele == 'div3'){
		document.getElementById('div1').style.display='none';
		document.getElementById('div2').style.display='none';
		document.getElementById('div3').style.display='block';
		document.getElementById('div4').style.display='none';
	}
	if(ele == 'div4'){
		document.getElementById('div1').style.display='none';
		document.getElementById('div2').style.display='none';
		document.getElementById('div3').style.display='none';
		document.getElementById('div4').style.display='block';
	}
	
}
function show_hide1(ele){
	if(ele == 'div1'){
		document.getElementById('div1').style.display='block';
		document.getElementById('div2').style.display='none';
	}
	if(ele == 'div2'){
		document.getElementById('div1').style.display='none';
		document.getElementById('div2').style.display='block';
	}
}

function validateViewInvitation(form){
	var responseYes = document.getElementById('responseYes').checked;
	var responseNo = document.getElementById('responseNo').checked;
	var responseMaybe = document.getElementById('responseMaybe').checked;
	if(responseYes == false && responseNo == false && responseMaybe == false){
	inlineMsg('GuestResponseDiv','Please indicate your response.',2);
	return false;
	}
	return true;
}
// 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;
}

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