/*################################################################*\
       PCDosTu 2007 | Sedran Production :)
\*################################################################*/
/////// Defining the source domain of images.
/////// don't change these variables
/////////////////////////////////////////////
if(location.href.match(/https/))
	var url = "https://www.jotform.com";
else
	var url = "http://www.jotform.com";

//////// Prototype's $ function
///////////////////////////////
function $(){
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) { 
    var element = arguments[i];
    if (typeof element == 'string')
	  element = document.getElementById(element);
    if (arguments.length == 1)	
      return element;
    elements.push(element);
  }
  return elements;
}

//////// Tooltip code
///////////////////////
var offsetfromcursorX=12
var offsetfromcursorY=12
var offsetdivfrompointerX=12
var offsetdivfrompointerY=12
var table = '<div id="tooltip" style="display:none; position:absolute;z-index: 100;opacity: .9;filter: alpha(opacity=90);">\
<table border="0" cellpadding="0" cellspacing="0">\
  <tr><td width="1" height="8" ></td>\
    <td align="left" </td>\
    <td width="1" ></td>\
  </tr><tr>\
  <td bgcolor="#b1bfcc"></td>\
    <td bgcolor="#edf4fa"><div style="padding:10px; font-family:\'Trebuchet MS\'; font-size:12px; color:black" id="tooltipinner"></div></td>\
    <td bgcolor="#b1bfcc"></td>\
  </tr><tr>\
    <td height="1" bgcolor="#b1bfcc"></td>\
    <td bgcolor="#b1bfcc"></td>\
    <td bgcolor="#b1bfcc"></td>\
  </tr>\
</table>\
</div>';
document.write(table)
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj     = document.all? document.all["tooltipinner"] : document.getElementById? $("tooltipinner") : ""
var pointerobj = document.all? document.all["tooltip"]      : document.getElementById? $("tooltip") : ""
function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function ddrivetip(thetext, thewidth, thecolor){
	if(thetext != ""){
		if (ns6||ie){
		 	if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
			if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
			tipobj.innerHTML=thetext;
			enabletip=true;
			return false;
		}		
	}
}
function positiontip(e){
	if (enabletip){
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
		if (rightedge<tipobj.offsetWidth){
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
		nondefaultpos=true
	}
	else if (curX<leftedge)
		tipobj.style.left="5px"
	else{
		tipobj.style.left=(curX+offsetfromcursorX-offsetdivfrompointerX-25)+"px" //position the horizontal position of the menu where the mouse is positioned
		pointerobj.style.left=(curX+offsetfromcursorX-25)+"px"
	}
	if (bottomedge<tipobj.offsetHeight){
		tipobj.style.top=(curY-tipobj.offsetHeight-offsetfromcursorY+15)+"px"
		nondefaultpos=true
	}
	else{
		tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
		pointerobj.style.top=curY+offsetfromcursorY+"px"
	}
	//tipobj.style.visibility="visible"
	tipobj.style.display = "block"
	pointerobj.style.display = "block"
	}
}
function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		//tipobj.style.visibility="hidden"
		tipobj.style.display = "none"
		pointerobj.style.display = "none"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}
document.onmousemove=positiontip
//////// Validation library V2
//////////////////////////////
var errored = false;            // Global for validate function
var exClassName = new Object(); // Global for Changed classnames
var styleAdded = false;         // Global for checking sytle status
function validate(elem,type,option){	// Main function
	var option = (option)? option : "";
	if(!styleAdded){			// Add style for Error warnings
		var style = document.createElement('style');
		var sprop = '.error{ border:2px red solid; background:#FCFCFC; }\
		             .Errortext{ color:#FF0000;font-family:"Trebuchet MS"; font-size:11px; }';
		style.setAttribute("type", "text/css");
		if (style.styleSheet){   // for IE
			style.styleSheet.cssText = sprop;
		} else {
			var newStyle = document.createTextNode(sprop);
			style.appendChild(newStyle);
		}
		document.getElementsByTagName('head')[0].appendChild(style);
		styleAdded = true; //don't add again.
	}

	
	///////////////
	// Check for optional validations
	if(option['LessThan']){
		if(elem.value.length >= option['LessThan']){
			error(elem,"LessThan",option['message']);
			return false;
		}else
			correct(elem);
	}
	if(option['GreaterThan']){
		if(elem.value.length <= option['GreaterThan']){
			error(elem,"GreaterThan",option['message']);
			return false;
		}else
			correct(elem);
	}
		
	//////////////
	// Make all the validations
	switch(type){
		case "Alphabetic":
			var charpos = elem.value.search(/[^a-zA-Z\s\-\_]/);
			if(charpos >= 0) error(elem,type,option['message']); else correct(elem);
			break;
		case "RequiredAlphabetic":
			if(elem.value.length <= 0) error(elem,type,option['message']); 
			else{
				var charpos = elem.value.search(/[^a-zA-Z\s\-\_]/);
				if(charpos >= 0) error(elem,type,option['message']); else correct(elem);
			}
			break;
		case "Numeric":
			var charpos = elem.value.search(/[^0-9\.\,\s\-\_]/);
			if(charpos >= 0) error(elem,type,option['message']); else correct(elem);
			break;
		case "RequiredNumeric":
			if(elem.value.length <= 0) error(elem,type,option['message']); 
			else{
				var charpos = elem.value.search(/[^0-9\.\,\s\-\_]/);
				if(charpos >= 0) error(elem,type,option['message']); else correct(elem);
			}
			break;
		case "Email":
			if(!checkmail(elem.value)) error(elem,type,option['message']); else correct(elem);
			break;
		case "Required":
			if(elem.type == "checkbox" || elem.type == "radio"){
				var parent = elem.parentNode;
				var ok = false;
				for(x = 0; x < parent.childNodes.length; x++)
					if(parent.childNodes[x].checked == true)
						ok = true;
				if(ok) correct(elem,true); else error(elem,type,option['message']);
			}else{
				if(elem.options)	
					// Here can be edited for checking text to "Please Select one" or similar text
					// in this example it looks for blank <option> to give error
					if(elem.options[elem.selectedIndex].text.length <= 0) error(elem,type,option['message']); else correct(elem);
				else
					if(elem.value.length <= 0) error(elem,type,option['message']); else correct(elem);
			}
			break;
		case "Regex":
			if(elem.value.match(option['expression'])) correct(elem);
			else error(elem,type,option['message']);
			break;
		default:	// Default is for defining the form and setting onsubmit function
			var form = document.forms[elem]
			form.onsubmit = function(){ onSubmit(elem); return false; };
			break;
	}		
}

