
// JavaScript Document

function check_form(frm){
	if(frm.username.value==""){
		document.getElementById("err").innerHTML= "Please enter Username";
		frm.username.focus();
		return false;
	}
	
	if(frm.password.value==""){
		document.getElementById("err").innerHTML= "Please enter Password";
		frm.password.focus();
		return false;		
	}
		
}

function checkPermission(str)
{
	error="";
	if(str=="0"){
		error ="Select The Permission";
	}
	return error;
}
function checkFirstName (strng) 
{
	var error = "";
	if (strng == "") 
	{
	   error = "Please enter Firstname.\n";
	}
	return error
}
function checkLastName (strng) 
{
	var error = "";
	if (strng == "") 
	{
	   error = "Please enter Lastname.\n";
	}
	return error
}
function checkUserId (strng) 
{
	var error = "";
	if (strng == "") 
	{
   		error = "Please enter UserId.\n";
  	 	return error;
	}
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) 
	{
       error = "UserId must be greater than 4 character.\n";
    }
    else if (illegalChars.test(strng)) 
	{
		   error = "UserId contains illegal characters.\n";
    } 
return error;
}       
// username validation
function checkUsername (strng) {
	var error = "";
	if (strng == "") {
	   error = "Please enter Username.\n";
	   return error;
	}

    if ((strng.length < 4) || (strng.length > 100)) {
       error = "Username must be at least 4 and no more than 100 characters in length.\n";
    }

	return error;
}       

 // password validation
function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
   return error; 
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 100)) {
       error = "The password must be between 6 and 100 characters.\n";
    }
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    

 // confirm password validation
function checkcPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a confirm password.\n";
   return error; 
}
return error;    
}    

 // email validation
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
   return error; 
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}
   
function validate_check(theForm) {
    var why = "";
	why = checkUsername(theForm.username.value);
	if (why != "") {	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.username.focus();
       return false;
    }
	why = checkPassword(theForm.password.value);
	if (why != "") {	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.password.focus();
       return false;
    }
	why = checkcPassword(theForm.confirm.value);		
	if (why != "") {	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.confirm.focus();
       return false;
    }
    why = checkEmail(theForm.email.value);	
	if (why != "") {	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.email.focus();
       return false;
    }

}

function validate_update_check(frm){
	if(frm.username.value==""){
		document.getElementById("div_errmsg").innerHTML = "Please enter username";
		frm.username.focus();
		return false;
	}
	if(frm.email.value==""){
		document.getElementById("div_errmsg").innerHTML = "Please enter email";
		frm.email.focus();
		return false;
	}
	why = checkEmail(frm.email.value);	
	if (why != "") {	  
       document.getElementById("div_errmsg").innerHTML= why;
	   frm.email.focus();
       return false;
    }
}

function validate_admin(theForm)
{
    var why = "";
	var error="";
	why = checkFirstName(theForm.fusername.value);
	if (why != "")
	{	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.fusername.focus();
       return false;
    }
	why = checkLastName(theForm.lusername.value);
	if (why != "")
	{	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.lusername.focus();
       return false;
    }
	why = checkUserId(theForm.userid.value);
	if (why != "")
	{	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.userid.focus();
       return false;
    }
	why = checkPassword(theForm.password.value);
	if (why != "") 
	{	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.password.focus();
       return false;
    }
	why = checkPassword(theForm.cpassword.value);
	if (why != "") 
	{	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.cpassword.focus();
       return false;
    }
	why = matchPassword(theForm.password.value,theForm.cpassword.value);
	if (why != "") 
	{	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.cpassword.focus();
       return false;
    }
	why = checkPermission(theForm.permission.value);
	if (why != "") 
	{	  
       document.getElementById("div_errmsg").innerHTML= why;
	   theForm.cpassword.focus();
       return false;
    }
	
}



///preview

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 180;	// maximum image size.
var defaultimagewidth = 135;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

function showtrail(title,width,height){
	t = title
	w = width
	h = height
	timer = setTimeout("show(t,w,h);",200);
}
function show(title,width,height){
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width

		document.onmousemove=followmouse; 
	
		newHTML = '<div class="border_preview_i" style="width:'+  width +'px;height:'+ height +'px">';
		newHTML = newHTML + '<font color="#33FF00">'+ title + '</font>';
		newHTML = newHTML + '</div>'; 
		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			//newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
		}		
		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}


///

function valuevalidation(entered, min, max, alertbox, datatype)
{
	with(entered)
	{
		checkvalue=parseFloat(value);
		if (datatype)
		  {smalldatatype=datatype.toLowerCase();
		   if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
		  }
		if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue){
			if (alertbox!="") {alert(alertbox);} 
			return false;}
		else {return true;}
	}
}

function popUp(URL, w, h) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + "');");
}

function CheckAll() {
  for (var i=0;i<document.bannerDetails.elements.length;i++) {
    var e = document.bannerDetails.elements[i];
	if ((e.type=='checkbox')) {
      document.bannerDetails.elements[i].checked=true;
      }
    }
}
  
function UnCheckAll() {
  for (var i=0;i<document.bannerDetails.elements.length;i++) {
    var e = document.bannerDetails.elements[i];
	if ((e.type=='checkbox')) {
      document.bannerDetails.elements[i].checked=false;
      }
    }
  }
  
  //called from admin -> banner_management.php
 function validate_Add_edit_banner(){
	
	missinginfo = "";
	
	if (document.form.title!=null && document.form.title.value=='') {
		missinginfo += "\n - Please Enter Title.";
	}
	
	if (document.form.url!=null && document.form.url.value!='') {
	}
	
	if (document.form.old_banner!=null && document.form.old_banner.value=='') {
		
		if (document.form.banner!=null && document.form.banner.value=='') {
			missinginfo += "\n - Please Enter Banner image.";
		}
	}
	if (document.form.banner!=null && document.form.banner.value!='') {
		
			if((document.form.banner.value.lastIndexOf(".jpg")==-1)) {
			   missinginfo += "\n - Please upload only .jpg extention file.";
			}
	}
	
	if (missinginfo != "") 
	{
		missinginfo ="__________________________________\n" +
		"Required information is missing: \n" +
		missinginfo + "\n__________________________________" +
		"\nPlease check and resubmit.";
		alert(missinginfo);
		return false;
	}
	
	return true
 }