// form validation function //
//-------------1----------------//
function make_blank(id)
{
var txt =document.getElementById(id)
txt.value="";
}

function validate(form) {
  var name = document.getElementById('txtName1').value;
  var email = document.getElementById('txtEmail1').value;
  var phone = document.getElementById('txtPhone1').value;
  var message = document.getElementById('txtRequest').value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var phoneRegex = /^\d{8,16}/;


  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  if(name == "") {
    inlineMsg('txtName1','<Strong>You must enter your name.</Strong>',2);
    return false;
  }
  if(!name.match(nameRegex)) {
    inlineMsg('txtName1','<Strong>You have entered an invalid name.</Strong>',2);
    return false;
  }
  if(email == "") {
    inlineMsg('txtEmail1','<strong>You must enter your email.</Strong>',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('txtEmail1','<strong>You have entered an invalid email.</Strong>',2);
    return false;
  }
     
  if(phone == "") {
    inlineMsg('txtPhone1','<strong>You must enter your phone number.</Strong>',2);
    return false;
  }
  if(!phone.match(phoneRegex)){
  inlineMsg('txtPhone1','<Strong>Mobile/Landline number Please.</Strong>',2)
  return false;
  }
  if(message == "") {
    inlineMsg('txtRequest','<Strong>You must enter a message.</Strong>',2);
    return false;
  }
  if(message.match(messageRegex)) {
    inlineMsg('txtRequest','<Strong>You have entered an invalid message.</Strong>',2);
    return false;
    }
  
    return true;
  }
  
  // Call Back Validation
  
  //-----------------2--------------------//
  
  function validateCallback(forms) {
  var name = document.getElementById('txtName').value;
  var email = document.getElementById('txtEmail').value;
  var phone = document.getElementById('txtPhone').value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var phoneRegex = /^\d{8,16}$/;
  
  if(name == "") {
    inlineMsgCall('txtName','<Strong>You must enter your name.</Strong>',2);
    return false;
  }
  if(!name.match(nameRegex)) {
    inlineMsgCall('txtName','<Strong>You have entered an invalid name.</Strong>',2);
    return false;
  }
  if(email == "") {
    inlineMsgCall('txtEmail','<strong>You must enter your email.</Strong>',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsgCall('txtEmail','<strong>You have entered an invalid email.</Strong>',2);
    return false;
  }
  if(phone == "") {
    inlineMsgCall('txtPhone','<strong>You must enter your phone number.</Strong>',2);
    return false;
    }
    if(!phone.match(phoneRegex)){
   
  inlineMsgCall('txtPhone','<Strong>Mobile/Landline number Please.</Strong>',2);
  return false;
  }
  return true;
}

//-----------------3----------------------------//
function friendvalidate(form1) {
  var name = document.getElementById('ctl00_yourname').value;
  var fromemail = document.getElementById('ctl00_Text1').value;
  var toemail = document.getElementById('ctl00_Text2').value;
  
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

  
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  if(name == "") {
    inlineMsgfrnd('ctl00_yourname','<Strong>You must enter your name.</Strong>',2);
    return false;
  }
  if(!name.match(nameRegex)) {
    inlineMsgfrnd('ctl00_yourname','<Strong>You have entered an invalid name.</Strong>',2);
    return false;
  }
  if(fromemail == "") {
    inlineMsgfrnd('ctl00_Text1','<strong>You must enter your email.</Strong>',2);
    return false;
  }
  if(!fromemail.match(emailRegex)) {
    inlineMsgfrnd('ctl00_Text1','<strong>You have entered an invalid email.</Strong>',2);
    return false;
  }
     
  if(toemail == "") {
    inlineMsgfrnd('ctl00_Text2','<strong>You must enter your email.</Strong>',2);
    return false;
  }
  if(!toemail.match(emailRegex)){
  inlineMsgfrnd('ctl00_Text2','<Strong>You have entered an invalid email.</Strong>',2);
  return false;
  }
  
    return true;
  }
  

// START OF MESSAGE SCRIPT  FOR VALIDATION//


// build out the divs, set attributes and call the fade function //
//---------------------function validate(form)-------------------//
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 +3;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", 20);
  if(!autohide) {
    autohide = 3;  
  }
  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)", 20);
  }
}

// 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 + 5;
  } else {
    value = msg.alpha - 5;
  }
  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.x) {
    top += target.x;
  }
  return top;
}

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

// for call

function inlineMsgCall(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msgcall')) {
    msg = document.createElement('div');
    msg.id = 'msgcall';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontentcall';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msgcall');
    msgcontent = document.getElementById('msgcontentcall');
  }
  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 = topPositionCall(targetdiv);
  var leftposition = leftPositionCall(targetdiv);
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsgCall(1)", 30);
  if(!autohide) {
    autohide = 3;  
  }
  window.setTimeout("hideMsgCall()", (autohide * 1000));
}

// hide the form alert //
function hideMsgCall(msg) {
  var msg = document.getElementById('msgcall');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsgCall(0)", 20);
  }
}

// face the message box //
function fadeMsgCall(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msgcall');
  var value;
  if(flag == 1) {
    value = msg.alpha + 10;
  } else {
    value = msg.alpha - 15;
  }
  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 leftPositionCall(target) {
  var left = -230;
  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 topPositionCall(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    top += target.x;
  }
  return top;
}

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




//Fuction for Friend Mail
function inlineMsgfrnd(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 = topPositionfrnd(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPositionfrnd(targetdiv) + targetwidth +3;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsgfrnd(1)", 20);
  if(!autohide) {
    autohide = 3;  
  }
  window.setTimeout("hideMsgfrnd()", (autohide * 1000));
}

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

// face the message box //
function fadeMsgfrnd(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + 5;
  } else {
    value = msg.alpha - 5;
  }
  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 leftPositionfrnd(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 topPositionfrnd(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    top += target.x;
  }
  return top;
}

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