﻿var validateMsg=document.createElement("DIV");validateMsg.style.backgroundColor="#FFFF99";validateMsg.style.padding="5px";validateMsg.style.borderStyle="solid";validateMsg.style.borderWidth="1px";validateMsg.style.borderColor="#FF3333";validateMsg.style.position="absolute";validateMsg.style.zIndex="999";validateMsg.style.cursor="hand";validateMsg.style.visibility="hidden";validateMsg.onclick=function(){validateMsg.style.visibility="hidden";};
function validateInit(){document.body.appendChild(validateMsg);};
function getLeft(obj){var left=obj.offsetLeft;while(obj.offsetParent&&obj.offsetParent.tagName!="BODY"){left+=obj.offsetParent.offsetLeft;obj=obj.offsetParent}return left;};function getTop(obj){var top=obj.offsetTop;while(obj.offsetParent&&obj.offsetParent.tagName!="BODY"){top+=obj.offsetParent.offsetTop;obj=obj.offsetParent;}return top;};function getWidth(obj){return obj.offsetWidth;};function getHeight(obj){return obj.offsetHeight}
function check(obj){var is=new Array("INPUT","TEXTAREA","SELECT");for(var j=0;j<is.length;j++){var inputs=obj.getElementsByTagName(is[j]);for(var i=0;i<inputs.length;i++){if(inputs[i].accept){if(!checks(inputs[i],inputs[i].accept)){validateMsg.style.top=(getTop(inputs[i])+getHeight(inputs[i])).toString()+"px";validateMsg.style.left=(getLeft(inputs[i])).toString()+"px";validateMsg.innerHTML=inputs[i].alt;validateMsg.style.visibility="visible";setTimeout("validateMsg.style.visibility='hidden'",6000);inputs[i].focus();return false;}}}}document.getElementById("submit").disabled=true;return true;}
function checks(obj,code)
{var r=true;var cl=code.split("|");for(var i=0;(i<cl.length);i++){if(r){var codes=cl[i].split(",");switch(codes[0]){
case "Text":r = isLen(obj.value,parseInt(codes[1]),parseInt(codes[2]));break;
}}}return r;}

function isLen(str,min,max){var c=0;for(var i=0;i<str.replace(/(^\s*)|(\s*$)/g,"").length;i++){if(str.charCodeAt(i)>255){c+=2;}else{c++;}}if(min>0&&c<min){return false;}if(max>0&&c>max){return false;}return true;}
function isEmail(str) {
    if (str.match(/^\w+([-+']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/ig) != str)
    { return false; }

    else { return true; }
}
