// JavaScript Document
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) {alert('The following error(s) occurred:\n'+errors); var Eml=document.getElementById("email"); Eml.setAttribute("style","border:3px inset #009;");}
    document.MM_returnValue = (errors == '');
	if(!errors) hideme();
  } 
}

function hideme(){
	document.getElementById("formsug").style.display = 'none';
	var Email = document.getElementById("email");
	document.body.scrollIntoView();
	document.getElementById("textareaDiv").innerHTML = 'Thank you for submitting a suggestion<br /> <br /><div align="center"><input type="button" value="Close" onClick="closepop()" /></div>';
}
function closepop(){
	$('#DivSuggest').remove();
	$('#DivSugcont').remove();
}
function openpop(Cont){
	var Cont = Cont;
/*	var div = document.createElement('div');
	var divCont = document.createElement('div');

	div.setAttribute('id','mydiv');
	
	var h = eval(document.body.scrollHeight);
	var w = eval(window.screen.availWidth) - 5;

	div.setAttribute('style','background:#000; filter:Alpha(opacity=50); opacity:0.5;-moz-opacity:0.5; width:'+w+'px; height:'+h+'px; position:absolute; z-index:1000; top:0px; left:0px;');
	
	// container
	var cw = eval(window.screen.width);
	var cl = (cw/2);
	cl = cl - (700/2);
	divCont.setAttribute('id','mydivCont');
	divCont.setAttribute("style","position:absolute; top:100px;left:"+cl+"px;z-index:10001;");
	divCont.innerHTML = Cont;
	document.body.appendChild(div);
	document.body.appendChild(divCont);*/
	var DivCont = $('<div>' + Cont + '</div>').attr("id","DivSugcont");
	var DivShadow = $('<div></div>').attr("id","DivSuggest");
	var h = eval(document.body.scrollHeight);
	var w = eval(window.screen.availWidth) - 5;
	
	// container
	var cw = eval(window.screen.width);
	var cl = (cw/2);
	cl = cl - (700/2);

	DivCont.css({position:'absolute',top:'100px',left:cl+'px','z-index':'100001',opacity:'100',background:'#FFF'});
	DivShadow.css({position:'absolute',background:'#000',opacity:'0.5',width:w+'px',height:h+'px','z-index':'10000',top:'0px',left:'0px'});
		
	$('body').append(DivCont);
	$('body').append(DivShadow);
	
}

function sendSuggest(){
	var emailaddressVal = $("#email").val(), Err='no',
	emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/,
	emailblockReg = /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)([\w-]+\.)+[\w-]{2,4})?$/;;
	
	if(emailaddressVal==''){
		$("#emailerr").html('<span style="color:#FF0">Please enter your email address.</span>');
		Err = 'yes';
	}else if(!emailReg.test(emailaddressVal)) {
		$("#emailerr").html('<span style="color:#FF0 !important">Enter a valid email address.</span>');
		Err = 'yes';
//	}else if(!emailblockReg.test(emailaddressVal)) {
//		$("#emailerr").html('<span style="color:#FF0 !important">No yahoo, gmail or hotmail emails.</span>');
	}
	
	var host = document.location.hostname + '/';
	if(host == "localhost/") host = host + 'new';
	var url = 'http://'+ host +'cic/resources/sendsug.php';
	if(Err=="no"){
		$.post(url,{
				email	: $('#email').attr('value'),
				subject	: $('#subject').attr('value'),
				fname 	: $('#fname').attr('value'),
				seljob 	: $('#seljob').attr('value'),
				msg 	: $('#msg').attr('value'),
				sendmsg : 'ok'
			},
			function(data){
				hideme();
		});
	}
}



