// JavaScript Document




function validationcontact(){
	
	if(document.getElementById('username').value==''){
		inlineMsg('username','Name is missing',2);
		
		return false;
	}

	if(!isValidEmail(trim(document.getElementById('email').value))){
		
		inlineMsg('email',' Invalid email',2);
		
		return false;
	}
	/*if(!IsNumeric(trim(document.getElementById('phone').value))){
		inlineMsg('phone','Please enter valid telephone',2);
		
		return false;
		}
	if(document.getElementById('address').value==''){
		inlineMsg('address','Address is missing ',2);
		
		return false;
	}*/
	

	if(document.getElementById('comment').value==''){
		inlineMsg('comment','Comment is missing ',2);
		
		return false;
	}
	
	if(document.getElementById('verificationcode').value==''){
		inlineMsg('verificationcode','verification code is missing',2);
		
		return false;
	}
	
	
}

function validationquote(){
	
	if(document.getElementById('username').value==''){
		inlineMsg('username','Name is missing',2);
		
		return false;
	}

	if(!isValidEmail(trim(document.getElementById('email').value))){
		
		inlineMsg('email',' Invalid email',2);
		
		return false;
	}
	if(document.getElementById('bname').value==''){
		inlineMsg('bname','Name is missing',2);
		
		return false;
	}	
	if(document.getElementById('comment').value==''){
		inlineMsg('comment','Comment is missing ',2);
		
		return false;
	}
	
	if(document.getElementById('verificationcode').value==''){
		inlineMsg('verificationcode','verification code is missing',2);
		
		return false;
	}
	
	
}



	
function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.+";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
  
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

	function isDate(str)
	{
		  var myDate = new Date(str);
	 
		  return !isNaN(myDate);
	 }
	 
// Credit Card Validation Javascript
// copyright 12th May 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateCreditCard(s) {
	function cardval(s) {
	// remove non-numerics
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) {
	x = s.charAt(i);
	if (v.indexOf(x,0) != -1)
	w += x;
	}
	// validate number
	j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) return false;
	k = Math.floor(j);
	m = Math.ceil(j) - k;
	c = 0;
	for (i=0; i<k; i++) {
	a = w.charAt(i*2+m) * 2;
	c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	return (c%10 == 0);
	}
}

// START OF MESSAGE SCRIPT //

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

function inlineMsg(target, string, autohide) {	

  var msg;
  var msgcontent;  
	//alert(string);
	//alert(autohide);

  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 = "http://192.168.51.2/humorsite/js/images/msg_arrow.gif"; 
   arrow.src = "http://www.fun2workwith.com/wlsol/images/msg_arrow.gif";// alert(arrow.src);
 // arrow.src = "http://localhost/wlsol/images/msg_arrow.gif";// alert(arrow.src);
  //arrow.src = "http://wlsol.com/humor/js/images/msg_arrow.gif"; 
  
}
