// JavaScript Document

function openCenterWin(url,theWidth,theHeight)
{
  var theTop=(screen.height/102)-(theHeight/200);
  var theLeft=(screen.width/2)-(theWidth/2);
  var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",scrollbars=no";
  theWin=window.open(url,'',features);
}

//display text on status bar
function displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function popupMsg(msgStr) {
  alert(msgStr);
}

function validateRegistrationForm(form){
	count = 0;
	arrFields = new Array () ;
	
	//alert ( form.name.value + " -- " + form.email.value )	
	if( (typeof( form.firstname.value ) == "undefined") ||  ((resultName = checkName(form.firstname.value)) == false)) {	
		//alert("First name is not valid");
		arrFields[count++] = "first name"
	}
	
	if( (typeof( form.surname.value ) == "undefined") || ((resultName = checkName(form.surname.value)) == false)) {	
		//alert("Surname is not valid");
		arrFields[count++] = "surname"
	}
	
	if( (typeof( form.position.value ) == "undefined") || ((resultName = checkName(form.position.value)) == false)) {	
		//alert("Position is not valid");
		arrFields[count++] = "position"
	}
	if( (typeof( form.company.value ) == "undefined") || ((resultName = checkName(form.company.value)) == false)) {	
		//alert("Company name is not valid");
		arrFields[count++] = "company name"
	}
	
	if( (typeof( form.phone.value ) == "undefined") || ((resultName = checkName(form.phone.value)) == false)) {	
		//alert("Contact number is not valid");
		arrFields[count++] = "contact number"
	}

	if( (typeof( form.email.value ) == "undefined") || ((resultEmail = checkEmail(form.email.value)) == false) ){
		//alert("Email is not valid");
		arrFields[count++] = "email"
	}

	if(count > 0) {
		strAlert = "Please enter a valid "
		for(i = 0; i < (count); i++) {
			
			if((i > 0) && (count > 2)) {
				strAlert = strAlert + ", "
			}
			
			if(i == (count-1) && (count > 1)) {
				strAlert = strAlert + " and "
			}
			
			strAlert = strAlert + arrFields[i]
		}
		strAlert = strAlert + "."
		alert(strAlert)
		return false
	}
	
	return true
}

function validateRequestForm(form){
	count = 0;
	arrFields = new Array () ;
	
	//alert ("'" + form.name.value + "' -- " + form.email.value );
	
    //check if cancel button pressed
    if((typeof( form.goback.value ) != "undefined") && form.goback.value == 'Cancel' )  {
        
        if(typeof(cancelbutton) != "undefined") {
            //alert("Cancel button pressed! " + form.goback.value + " " + cancelbutton);
            return true;
        }
    }
    
    
	if( (typeof( form.name.value ) == "undefined") || ((resultName = checkName(form.name.value)) == false)  ){	
		//alert("Name is not valid");
		arrFields[count++] = "name"
	}
	
	if( (typeof( form.email.value ) == "undefined") || ((resultEmail = checkEmail(form.email.value)) == false) ){
		//alert("Email is not valid");
		arrFields[count++] = "email"
	}

	if(count > 0) {
		strAlert = "Please enter a valid "
		for(i = 0; i < (count); i++) {
			
			if((i > 0) && (count > 2)) {
				strAlert = strAlert + ", "
			}
			
			if(i == (count-1) && (count > 1)) {
				strAlert = strAlert + " and "
			}
			
			strAlert = strAlert + arrFields[i]
		}
		strAlert = strAlert + "."
		alert(strAlert)
		return false
	}
	
	return true
}


function validateEmailFriendForm(form){
	count = 0;
	arrFields = new Array () ;
	
	//alert ( form.name.value + " -- " + form.email.value )
	
    //check if cancel button pressed
    if((typeof( form.goback.value ) != "undefined") && form.goback.value == 'Cancel' )  {
        
        if(typeof(cancelbutton) != "undefined") {
            //alert("Cancel button pressed! " + form.goback.value + " " + cancelbutton);
            return true;
        }
    }
    
	if( (typeof( form.sname.value ) == "undefined") || ((resultName = checkName(form.sname.value)) == false)  ){	
		//alert("Name is not valid");
		arrFields[count++] = "name"
	}
	
	if( (typeof( form.semail.value ) == "undefined") || ((resultEmail = checkEmail(form.semail.value)) == false) ){
		//alert("Email is not valid");
		arrFields[count++] = "email"
	}

	if( (typeof( form.fname.value ) == "undefined") || ((resultName = checkName(form.fname.value)) == false)  ){	
		//alert("Name is not valid");
		arrFields[count++] = "friend's name"
	}
	
	if( (typeof( form.femail.value ) == "undefined") || ((resultEmail = checkEmail(form.femail.value)) == false) ){
		//alert("Email is not valid");
		arrFields[count++] = "friend's email"
	}
	
	if( form.captcha.value == ""  ){
		//alert("Email is not valid");
		arrFields[count++] = "validation code"
	}
	
	if(count > 0) {
		strAlert = "Please enter a valid "
		for(i = 0; i < (count); i++) {
			
			if((i > 0) && (count > 2)) {
				strAlert = strAlert + ", "
			}
			
			if(i == (count-1) && (count > 1)) {
				strAlert = strAlert + " and "
			}
			
			strAlert = strAlert + arrFields[i]
		}
		strAlert = strAlert + "."
		alert(strAlert)
		return false
	}
	
	return true
}

function validateFeedbackForm(form){
	count = 0;
	arrFields = new Array () ;
	
	//alert ( form.name.value + " -- " + form.email.value )
	//alert(typeof(form.respondyesno));
	
    //check if cancel button pressed
    if((typeof( form.goback.value ) != "undefined") && form.goback.value == 'Cancel' )  {
        
        if(typeof(cancelbutton) != "undefined") {
            //alert("Cancel button pressed! " + form.goback.value + " " + cancelbutton);
            return true;
        }
    }
    
	if( (typeof( form.respondyesno ) != "undefined") && (form.respondyesno[0].checked)  ){	 //if the yes option is checked
		//alert("Name is not valid");
		
		if( (typeof( form.name.value ) == "undefined") || ((resultName = checkName(form.name.value)) == false)  ){	
			//alert("Name is not valid");
			arrFields[count++] = "name"
		}
	
		if( (typeof( form.email.value ) == "undefined") || ((resultEmail = checkEmail(form.email.value)) == false) ){
			//alert("Email is not valid");
			arrFields[count++] = "email"
		}

	}

	if( (typeof( form.feedback.value ) == "undefined") || ((resultName = checkName(form.feedback.value)) == false)  ){	
		//alert("Name is not valid");
		arrFields[count++] = "feedback"
	}
	
	
	if(count > 0) {
		strAlert = "Please enter a valid "
		for(i = 0; i < (count); i++) {
			
			if((i > 0) && (count > 2)) {
				strAlert = strAlert + ", "
			}
			
			if(i == (count-1) && (count > 1)) {
				strAlert = strAlert + " and "
			}
			
			strAlert = strAlert + arrFields[i]
		}
		strAlert = strAlert + "."
		alert(strAlert)
		return false
	}
	
	return true
}


function checkName(strname){	
	if (!isEmpty(strname)){ 
		//alert("Name is valid");
		return true;
	} 	
	return false;
}

function checkEmail(stremail){	
	if (!isEmpty(stremail)){
		if (isValidEmail(stremail)){
			//alert("Email is valid"); 
			return true;
		}
	}	
	return false;
}

//function to check empty fields
function isEmpty(strfield) {	
    if(strfield.length == 0 || strfield == "" || strfield == null  )    {
		//alert(strfield + " is empty");
		return true;
    }
	return false;
}

function isValidEmail(stremail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;  
    if (stremail.search(validRegExp) == -1) {
      return false;
    } 
    return true; 
}


function chk_delete_user_form(form){
	count = 0;
	arrUsers = new Array () ;
	
    for(n in form.childNodes) {
    
        curr = form[n];
        if( (currtype = typeof( curr ) != "undefined") && curr.type=="checkbox" && curr.checked == true)  {
            arrUsers.push(new String(curr.value));   
            //alert("adding " + curr.value);
            
        }

        
        
    }
    
    cfm_str = "Are you sure you want to delete these users: \n";
    for(m in arrUsers) {
        strtmp = arrUsers[m].toString();
        cfm_str = cfm_str + strtmp + "\n";
    }
    result = confirm (cfm_str)
    return result

}



