/*
*	Utility file for various JavaScript Functions
*/
// Method to enlarge the image size
function enlargeImage(img){
	document.getElementById(img.id).height = 400;
	document.getElementById(img.id).width = 300;
	var url = " "+document.getElementById(img.id).src;
	//createPopUp(img,ht,wt);
}
// Method to reduce the image size
function reduceImage(img){
	document.getElementById(img.id).height = 120;
	document.getElementById(img.id).width = 100;
}

// Method to enlarge Directions image.
function enlargeDirectionImage(img){
	document.getElementById(img.id).height = 300;
	document.getElementById(img.id).width = 600;
	var url = " "+document.getElementById(img.id).src;
	//createPopUp(img,ht,wt);
}

// Method to reduce Directions image.
function reduceDirectionImage(img){
	document.getElementById(img.id).height = 150;
	document.getElementById(img.id).width = 300;
}


// Pop Up 
function createPopUp(img,ht,wt) {
	var url = " "+document.getElementById(img.id).src;
	// alert('URL = '+url+' \nHeight = '+ht+' \nWidth = '+wt+'');
	newwindow=window.open(url,'name','height='+ht+',width='+wt+'');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}



// Search Form submission Method 
function submitSearch(){
 document.searchForm.submit();
 document.getElementById("searchText").value = "";  
}

function clearForm(){
 // document.getElementById("searchText").value = "";  
	document.searchForm.searchText.value="";
 }

// Method to validate the Download Form 
function validate_userRegistration_form(){

	var name			= (document.downloadForm.name.value).trim();
	var loginName		= (document.downloadForm.loginName.value).trim();
	var loginPasswd		= (document.downloadForm.loginPasswd.value).trim();
	var confirmPasswd	= (document.downloadForm.confirmPasswd.value).trim();
	var company			= (document.downloadForm.company.value).trim();
	var email			= (document.downloadForm.email.value).trim();
	var telephone		= (document.downloadForm.telephone.value).trim();
	var address			= (document.downloadForm.address.value).trim();
	var seqQuest		= (document.downloadForm.seqQuest.value).trim();
	var seqAns			= (document.downloadForm.seqAns.value).trim();
	var privacy			=  document.downloadForm.privacy.checked;

	// Setting the strings without Whitespaces.
	document.downloadForm.name.value	  = name;
	document.downloadForm.loginName.value = loginName;
	document.downloadForm.company.value   = company;
	document.downloadForm.email.value	  = email;
	document.downloadForm.telephone.value = telephone;
	document.downloadForm.address.value   = address;

	// Validatig Name. 
	if (name == '' || !isAlphaNumeric(name)) {
		alert('Please enter First Name');
		(document.downloadForm.name).focus();
		return false;
	}
	// Validatig loginName. 
	if (loginName == '' || !isAlphaNumeric(loginName)) {
		alert('Please enter Login Name');
		(document.downloadForm.loginName).focus();
		return false;
	}
	// Validatig Login Password. 
	if (loginPasswd == '') {
		alert('Please enter Login Password');
		(document.downloadForm.loginPasswd).focus();
		return false;
	}
	// Validatig Confirm Password. 
	if (confirmPasswd == '') {
		alert('Please enter Confirm Password');
		(document.downloadForm.confirmPasswd).focus();
		return false;
	}
	// Validate whether Login Password and Confirm Password matches
	if (loginPasswd != confirmPasswd) {
		alert('Login Password and Confirm Password mismatch !'+loginName+" and "+confirmPasswd);
		(document.downloadForm.confirmPasswd).focus();
		return false;
	}

	// Cehck the Company field for Alphanumeric
	if(company!=''){
		if(!isAlphaNumeric(company)){
			(document.downloadForm.company).focus();
			return false;
		}
	}
	// Validating Email.
	if ((email==null)||(email=='')){
		alert('Please Enter your Email ID');
		(document.downloadForm.email).focus();
		return false;
	}
	if (validateEmail(email)==false){
		email.value="";
		(document.downloadForm.email).focus();
		return false;
	}
	// Validating Telephone.
	if ((telephone == null) || (telephone == '')) {
		alert('Please enter telephone');
		(document.downloadForm.telephone).focus();
		return false;
	}
	if (checkInternationalPhone(telephone)==false){
		alert("Please Enter a Valid Phone Number");
		telephone="";
		(document.downloadForm.telephone).focus();
		return false;
	}
	// Cehck the addres field for Alphanumeric
	if(address!=''){
	 if(!isAlphaNumeric(address)){
		(document.downloadForm.address).focus();
		return false;
	 }
	}
	// Validatig Sequrity Question. 
	if (seqQuest == '') {
		alert('Please enter Sequrity Question');
		(document.downloadForm.seqQuest).focus();
		return false;
	}
	// Validatig Sequrity Answer. 
	if (seqAns == '' || !isAlphaNumeric(seqAns)) {
		alert('Please enter Sequrity Answer');
		(document.downloadForm.seqAns).focus();
		return false;
	}
	// Check for use of Privacy Policy selection.
	if(privacy == false){
		alert("Please read our privacy policy and confirm to proceed!");
		return false;
	}

}

// Method to validate the Alumni Form
function validate_alumni_form(){
	var aluFirstName		= (document.alumniForm.aluFirstName.value).trim();
	var aluEmail			= (document.alumniForm.aluEmail.value).trim();
	var aluPhone			= (document.alumniForm.aluPhone.value).trim();
	var aluCompName			= (document.alumniForm.aluCompName.value).trim();
	// var aluAddress			= (document.alumniForm.aluAddress.value).trim();
	var privacy				=  document.alumniForm.privacy.checked;

	// Validatig First Name. 
	if (aluFirstName == '' || !isAlphaNumeric(aluFirstName)) {
		alert('Please enter First Name');
		(document.alumniForm.aluFirstName).focus();
		return false;
	}
	if(!isAlphaNumeric(aluCompName)){
		(document.alumniForm.aluCompName).focus();
		return false;
	}

	// Validating Email.
	if ((aluEmail==null)||(aluEmail=='')){
		alert('Please Enter your Email ID');
		(document.alumniForm.aluEmail).focus();
		return false;
	}
	if (validateEmail(aluEmail)==false){
		//aluEmail.value="";
		(document.alumniForm.aluEmail).focus();
		return false;
	}

	// Validating Telephone.
	if ((aluPhone == null) || (aluPhone == '')) {
		alert('Please enter telephone');
		(document.alumniForm.aluPhone).focus();
		return false;
	}
	if (checkInternationalPhone(aluPhone)==false){
		alert("Please Enter a Valid Phone Number");
		aluPhone="";
		(document.alumniForm.aluPhone).focus();
		return false;
	}

	/* if(!isAlphaNumeric(aluAddress)){
		(document.alumniForm.aluAddress).focus();
		return false;
	}*/
	// Check for use of Privacy Policy selection.
	if(privacy == false){
		alert("Please read our privacy policy and confirm to proceed!");
		return false;
	}
}

// Validate ApplyOnline Form
function validateApplyOnline(){
	var txtName   = (document.applyOnlineForm.txtName.value).trim();
	var keySkills = (document.applyOnlineForm.keySkills.value).trim();
	var txtEmail  = (document.applyOnlineForm.txtEmail.value).trim();
	var txtPhone  = (document.applyOnlineForm.txtPhone.value).trim();
	// var txtAddress = (document.applyOnlineForm.txtAddress.value).trim();
	var privacy	  =  document.applyOnlineForm.privacy.checked;


	// Validatig Name. 
	if((txtName==null) || (txtName == '') || !isAlphaNumeric(txtName)) {
		alert('Please enter Name');
		(document.applyOnlineForm.txtName).focus();
		return false;
	}
	// Validatig Key Skills. 
	if((keySkills==null) || (keySkills == '')) {
		alert('Please enter Key Skills');
		(document.applyOnlineForm.keySkills).focus();
		return false;
	}
	// Validating Email
	if (validateEmail(txtEmail)==false){
		(document.applyOnlineForm.txtEmail).focus();
		return false;
	}
	// Validatig Phone. 
	if((txtPhone==null) || (txtPhone == '')) {
		alert('Please enter Phone Number');
		(document.applyOnlineForm.txtPhone).focus();
		return false;
	}
	if (checkInternationalPhone(txtPhone)==false){
		alert("Please Enter a Valid Phone Number");
		txtPhone="";
		(document.applyOnlineForm.txtPhone).focus();
		return false;
	}
	// Check address filed for Alphanumeric input	
	/* if(!isAlphaNumeric(txtAddress)){
		(document.applyOnlineForm.txtAddress).focus();
		return false;
	}*/
	// Check for use of Privacy Policy selection.
	if(privacy == false){
		alert("Please read our privacy policy and confirm to proceed!");
		return false;
	}
}
// Sales Enquary Validation Form
function validateSalesEnqueryForm(){
	var name		= (document.salesEnquiry.name.value).trim();
	var email		= (document.salesEnquiry.email.value).trim();
	var telephone	= (document.salesEnquiry.phno.value).trim();
	var privacy	    =  document.salesEnquiry.privacy.checked;

	// Validatig First Name. 
	if (name == '') {
		alert('Please enter First Name');
		(document.salesEnquiry.name).focus();
		return false;
	}
	// Validating Email.
	if ((email==null)||(email=='')){
		alert('Please Enter your Email ID');
		(document.salesEnquiry.email).focus();
		return false;
	}
	if (validateEmail(email)==false){
		email.value='';
		(document.salesEnquiry.email).focus();
		return false;
	}
	// Validatig Phone. 
	if((telephone==null) || (telephone == '')) {
		alert('Please enter Phone Number');
		(document.salesEnquiry.phno).focus();
		return false;
	}
	if (checkInternationalPhone(telephone)==false){
		alert("Please Enter a Valid Phone Number");
		telephone="";
		(document.salesEnquiry.phno).focus();
		return false;
	}
	// Check for use of Privacy Policy selection.
	if(privacy == false){
		alert('Please accept our privacy policy to proceed !');
		return false;
	}
}
// Feedback form validation

	function validateFeedBackForm(){
		var name		= (document.feedBackForm.name.value).trim();
		var email		= (document.feedBackForm.email.value).trim();
		var telephone	= (document.feedBackForm.phno.value).trim();
		var privacy	    =  document.feedBackForm.privacy.checked;

		// Validatig First Name. 
		if (name == '') {
			alert('Please enter First Name');
			(document.feedBackForm.name).focus();
			return false;
		}
		// Validating Email.
		if ((email==null)||(email=='')){
			alert('Please Enter your Email ID');
			(document.feedBackForm.email).focus();
			return false;
		}
		if (validateEmail(email)==false){
			email.value='';
			(document.feedBackForm.email).focus();
			return false;
		}
		// Validatig Phone. 
		if((telephone==null) || (telephone == '')) {
			alert('Please enter Phone Number');
			(document.feedBackForm.phno).focus();
			return false;
		}
		if (checkInternationalPhone(telephone)==false){
			alert("Please Enter a Valid Phone Number")
			telephone="";
			(document.feedBackForm.phno).focus();
			return false
		}
		// Check for use of Privacy Policy selection.
		if(privacy == false){
			alert('Please accept our privacy policy to proceed !');
			return false;
		}
	}

function validate_createUser_form(){
	var name		= (document.createAcctForm.name.value).trim();
	var loginName	= (document.createAcctForm.loginName.value).trim();
	var loginPass	= (document.createAcctForm.loginPass.value).trim();
	var email		= (document.createAcctForm.email.value).trim();
	var seqQuest	= (document.createAcctForm.seqQuest.value).trim();
	var seqAns		= (document.createAcctForm.seqAns.value).trim();

	// Validatig Name. 
	if((name==null) || (name == '')) {
		alert('Please enter Name');
		(document.createAcctForm.name).focus();
		return false;
	}
	// Validatig Login Name. 
	if((loginName==null) || (loginName == '')) {
		alert('Please enter Login Name');
		(document.createAcctForm.loginName).focus();
		return false;
	}
	// Validatig Password. 
	if((loginPass==null) || (loginPass == '')) {
		alert('Please enter Password');
		(document.createAcctForm.loginPass).focus();
		return false;
	}
	// Validating Email
	if (validateEmail(email)==false){
		(document.createAcctForm.email).focus();
		return false;
	}
	// Validatig Sequrity Question. 
	if((seqQuest==null) || (seqQuest == '')) {
		alert('Please enter Sequrity Question.');
		(document.createAcctForm.seqQuest).focus();
		return false;
	}
	// Validatig Sequrity Answer. 
	if((seqAns==null) || (seqAns == '')) {
		alert('Please enter Sequrity Answer.');
		(document.createAcctForm.seqAns).focus();
		return false;
	}
}

function validate_updateUser_form(){

	var name		= (document.updateUserForm.name.value).trim();
	var email		= (document.updateUserForm.email.value).trim();
	var seqQuest	= (document.updateUserForm.seqQuest.value).trim();
	var seqAns		= (document.updateUserForm.seqAns.value).trim();

	// Validatig Name. 
	if((name==null) || (name == '')) {
		alert('Please enter Name');
		(document.updateUserForm.name).focus();
		return false;
	}
	// Validating Email
	if (validateEmail(email)==false){
		(document.updateUserForm.email).focus();
		return false;
	}
	// Validatig Sequrity Question. 
	if((seqQuest==null) || (seqQuest == '')) {
		alert('Please enter Sequrity Question.');
		(document.updateUserForm.seqQuest).focus();
		return false;
	}
	// Validatig Sequrity Answer. 
	if((seqAns==null) || (seqAns == '')) {
		alert('Please enter Sequrity Answer.');
		(document.updateUserForm.seqAns).focus();
		return false;
	}
}

function validate_changePassword_form(){
	var oldPassword		= (document.changePasswordForm.oldPassword.value).trim();
	var newPassword		= (document.changePasswordForm.newPassword.value).trim();
	var confirmPassword	= (document.changePasswordForm.confirmPassword.value).trim();

	
	// Validatig Password. 
	if((oldPassword==null) || (oldPassword == '')) {
		alert('Please enter Old Password');
		(document.changePasswordForm.oldPassword).focus();
		return false;
	}
	// Validatig Password. 
	if((newPassword==null) || (newPassword == '')) {
		alert('Please enter New Password');
		(document.changePasswordForm.newPassword).focus();
		return false;
	}
	// Validatig Password. 
	if((confirmPassword==null) || (confirmPassword == '')) {
		alert('Please enter Confirm Password');
		(document.changePasswordForm.confirmPassword).focus();
		return false;
	}


}

// Validating Email Method Declaration.
function validateEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
	return (true);
	}
	alert("Invalid E-mail Address! Please re-enter.");
	return (false);
}

// Function Declaration to remove blank spaces before of after the String.
String.prototype.trim = function(){
	  return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
// Function to check text input for Alphanumeric values
function isAlphaNumeric(val){
	if (val.match(/^[a-z A-Z0-9]+$/)){ return true;}
	else{ alert('Invalid alphanumeric characters.'); return false; }
}


/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
	var bracket=3
	strPhone=trim(strPhone)
	if(strPhone.indexOf("+")>1) return false
	if(strPhone.indexOf("-")!=-1)bracket=bracket+1
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
	var brchr=strPhone.indexOf("(")
	if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
	if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

/**
 * DHTML phone number validation script.- End
 */


/*
// Script to generate Date Form Filed dynamically in HTML form.
function populateDate(inForm){
	alert("Form Name : "+inForm);
	var temp=0;
	var today= new Date();
	var day= today.getDate();
	var month= today.getMonth();
	var year= today.getFullYear();
	// alert("Day - Month - Year"+day+month+year);
	t2= prompt("Enter the number of years to fetch",1);
	for (var i=0; i <31 ; i++){
		var x= String(i+1);		
		inForm.day.options[i] = new Option(x,x);
	}
	for (var i=0; i <31 ; i++){
		var d=0;
		d=inForm.day.options[i].value;
		if(d=day){
			inForm.day.options[i].selected=true;
			break;}
	}
	for (var i=0,j=year; i <t2 ; i++, j--){
		var y= String(j);
		inForm.year.options[i] = new Option(y,y);
	}
	for(var i=0;i<12;i++){
		if(i=month)
			{inForm.month.options[i].selected=true;
		break;}
	}
}
function populateDay(inForm2){
	var t3=0;
	if(inForm2.month.options[1].selected)
		t3=28;
	else if(inForm2.month.options[8].selected||inForm2.month.options[3].selected||inForm2.month.options[5].selected||inForm2.month.options[10].selected)
		t3=30;
	else
		t3=31;

	for(i=0;i<31;i++){
		inForm2.day.options[i]=null;
	}
	for (var i=0; i <t3 ; i++){
		var x= String(i+1);
		inForm2.day.options[i] = new Option(x);
	}
}
*/

// Script to execute a method onLoad of a page. It takes function name as a parameter.
function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      oldonload(); 
	      func(); 
	    } 
	  } 
} 
// Getting visior System informtion.
/*
   $ip = getenv ("REMOTE_ADDR");                // IP Address  
   $server_name = getenv ("SERVER_NAME");       // Server Name  
   $request_uri = getenv ("REQUEST_URI");       // Requested URI  
   $http_ref = getenv ("HTTP_REFERER");         // HTTP Referer  
   $http_agent = getenv ("HTTP_USER_AGENT");    // User Agent  
   $error_date = date("D M j Y g:i:s a T");     // Error Date  

*/
