// JavaScript Document
//rules

function startUpload()
{
	document.getElementById('msgBlock').innerHTML='';
	var Name = document.getElementById("Name").value;
	var Company = document.getElementById("Company").value;
	var Email = document.getElementById("Email").value;
	var Phone = document.getElementById("Phone").value;
	var Country = document.getElementById("Country").value;
	var Attachment = document.getElementById("Attachment").value;
	var Comments = document.getElementById("Comments").value;
	var captcha = document.getElementById("captcha").value;
	if(Name == ""){
		alert("Please enter your name!");
		document.getElementById("Name").focus();
		return false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Email)){}
	else{	alert("Invalid E-mail Address!")
			document.getElementById('Email').focus();
			return false;
		}
		if(Comments == ""){
		alert("Please enter your comments!");
		document.getElementById("Comments").focus();
		return false;
	}
	if(captcha == ""){
		alert("Please enter the verification code as shown!");
		document.getElementById("captcha").focus();
		return false;
	}
	/*document.getElementById("btns").value="Please wait";
	document.getElementById("btns").disabled = true;
    document.getElementById('f1_upload_process').style.visibility = 'visible';*/
    return true;
}

function stopUpload(str)
{
    alert('hi');
    //document.getElementById('msgBlock').innerHTML="Thank you for contacting WIT Innovation, your request will be processed shortly. In case you have any questions please feel free to get in touch at  <a href='mailto:info@witinnovation.com'>info@witinnovation.com</a>";
	if(1) // Ok, mail sent
		document.getElementById('msgBlock').innerHTML = str;
	else if("-2"==str) // Attachment size more then 1MB
		document.getElementById('msgBlock').innerHTML='<font color="red"><b>Maximum 1 MB allowed for attachment</b></font>';
	else if("-3"==str) // Attachment size more then 1MB  INI
		document.getElementById('msgBlock').innerHTML='<font color="red"><b>Maximum 1 MB allowed for attachment.</b></font>';
	else if("-8"==str) // Extension restriction
		document.getElementById('msgBlock').innerHTML='<font color="red"><b>This type of file is not allowed to attach</b></font>';
	else if("-99"==str) // Attachemnt failed
		document.getElementById('msgBlock').innerHTML='<font color="red"><b>We are sorry but we can not attach your attachment</b></font>';
	else if("-9"==str) // mail sent failed
		document.getElementById('msgBlock').innerHTML='<font color="red"><b>We are sorry but your request can not be process this time, please try again.</b></font>';


		document.getElementById("btns").value = "submit";
    	document.getElementById("btns").disabled = false;
		document.getElementById('f1_upload_process').style.visibility = 'hidden';
		if("1"==str)
			document.reqForm.reset();
}
/*function loadMenu(str){
var xmlhttp = getXMLHTTP();
					if(!xmlhttp){
						alert("Browser doesn't support XMLHTTP");
					}
					url = "functions.php";
					xmlhttp.onreadystatechange = function(){
						if(xmlhttp.readyState == 4){
							if(xmlhttp.status == 200){
								document.getElementById('menu').innerHTML = xmlhttp.responseText;
							}else alert("There was a problem processing request!");
						}
					}
					xmlhttp.open("POST", url, true);
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlhttp.send("tbl="+escape("menu")+"&action="+escape("loadmenu")+"&enable="+escape(str));
}
*/

function loadHeader(){
var xmlhttp = getXMLHTTP();
					if(!xmlhttp){
						alert("Browser doesn't support XMLHTTP");
					}
					url = "functions.php";
					xmlhttp.onreadystatechange = function(){
						if(xmlhttp.readyState == 4){
							if(xmlhttp.status == 200){
								document.getElementById('quickform').innerHTML = xmlhttp.responseText;
							}else alert("There was a problem processing request!");
						}
					}
					xmlhttp.open("POST", url, true);
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlhttp.send("tbl="+escape("header")+"&action="+escape("loadheader"));
}


function applyJob(jobId){
					var xmlhttp = getXMLHTTP();	
					if(!xmlhttp){
						alert("Browser doesn't support XMLHTTP");
					}
					url = "common/functions.php";
					xmlhttp.onreadystatechange = function(){
						if(xmlhttp.readyState == 4){
							if(xmlhttp.status == 200){ 
								document.getElementById('jobs').innerHTML = xmlhttp.responseText;
							}else alert("There was a problem processing request!");
						}
					}
					xmlhttp.open("POST", url, true);
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlhttp.send("tbl="+escape("wit_jobs")+"&action="+escape("applyJob")+"&job_id="+escape(jobId));
	
}
function loadCaptcha(){
					var xmlhttp = getXMLHTTP();	
					if(!xmlhttp){
						alert("Browser doesn't support XMLHTTP");
					}
					url = "captcha1.php";
					xmlhttp.onreadystatechange = function(){
						if(xmlhttp.readyState == 4){
							if(xmlhttp.status == 200){ 
							//= xmlhttp.responseText;
							document.getElementById('captchaCurrentValue').value = xmlhttp.responseText;
							}else alert("There was a problem processing request!");
						}
					}
					xmlhttp.open("POST", url, true);
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlhttp.send(null);

}
function viewJobDetails(jobId){
					var xmlhttp = getXMLHTTP();	
					if(!xmlhttp){
						alert("Browser doesn't support XMLHTTP");
					}
					url = "common/functions.php";
					xmlhttp.onreadystatechange = function(){
						if(xmlhttp.readyState == 4){
							if(xmlhttp.status == 200){ 
								document.getElementById('jobs').innerHTML = xmlhttp.responseText;
							}else alert("There was a problem processing request!");
						}
					}
					xmlhttp.open("POST", url, true);
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlhttp.send("tbl="+escape("wit_jobs")+"&action="+escape("viewJobDetails")+"&job_id="+escape(jobId));
	
}
function loadJobs(){
					var xmlhttp = getXMLHTTP();	
					if(!xmlhttp){
						alert("Browser doesn't support XMLHTTP");
					}
					url = "common/functions.php";
					xmlhttp.onreadystatechange = function(){
						if(xmlhttp.readyState == 4){
							if(xmlhttp.status == 200){ 
								document.getElementById('jobs').innerHTML = xmlhttp.responseText;
							}else alert("There was a problem processing request!");
						}
					}
					xmlhttp.open("POST", url, true);
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlhttp.send("tbl="+escape("wit_jobs")+"&action="+escape("load_jobs"));

}
function loadJobs1(str){
	//""+escape("wit_jobs")+"&action="+escape("load_jobs")
					var xmlhttp = getXMLHTTP();	
					if(!xmlhttp){
						alert("Browser doesn't support XMLHTTP");
					}
					url = "common/functions.php?page="+str+"&tbl=wit_jobs"+"&action=load_jobs";
					xmlhttp.onreadystatechange = function(){
						if(xmlhttp.readyState == 4){
							if(xmlhttp.status == 200){ 
								document.getElementById('jobs').innerHTML = xmlhttp.responseText;
							}else alert("There was a problem processing request!");
						}
					}
					xmlhttp.open("GET", url, true);
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlhttp.send();

}




function deleteSelected(thisform, what){
with(thisform){
		c = count.value;
		var a = new Array();
		for(var i=0;i<c;i++)
		{
			if(document.getElementById("delete"+i).checked==true){
				 if(a.length == 0){
					j = 0; 
				 }
				a[j] = document.getElementById("delete"+i).value;
				j++;
				
			}
			
		}
		
		if(a.length == 0)
		alert("Please select atleast one to delete!");
		else if(confirm("Are You sure you want to delete "+a.length+" items permanently!")){
			document.getElementById("deletemm").innerHTML = "Deleting "+a.length+" rows <img src='../../images/loading.gif' />";
			strURL = "../../common/functions.php";
			strURL = strURL+"?ids="+a+"&tbl="+what+"&action=delete";
			strURL = strURL+"&sid="+Math.random();
			
			  var req1 = getXMLHTTP();
			 
			  if (req1) 
			  {
				   req1.onreadystatechange = function()
				   {
					if (req1.readyState == 4) 
					{
					  if (req1.status == 200) 
					  {
						  
									location.href = "index.php";
								
					  }
					  else
					  {
						alert("There was a problem while using XMLHTTP:\n" + req1.statusText);
					  }
					}               
				   }            
				   req1.open("GET", strURL, true);
				   req1.send(null);
			} 					
		}
}
}

function changeTo(thisform){
	
	with(thisform){
		c = count.value;
		if(deleteAll.checked == true){
			
			for(var i=0;i<c;i++)
			{ 
			  document.getElementById("delete"+i).checked=true;
			}
			
		}
		else {
			for(var i=0;i<c;i++)
			{ 
			  document.getElementById("delete"+i).checked=false;
			}
		  }
		  
	}
	
}

function check(node, msg){
	if(checknull(node.value)){
		document.getElementById(node.name).innerHTML = msg;
	}
	else document.getElementById(node.name).innerHTML = '';
}

function getXMLHTTP(){
var xmlhttp;
try{
	xmlhttp = new XMLHttpRequest();
}catch(e){
	try{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			return false;
		}
	}
}
return xmlhttp;
}



function validate(thisform){
		switch(thisform.name){
			case "loginform":
			with(thisform){
					if(checknull(log_id.value)){
						alert("Please enter your user_id/email-id to login");
						log_id.focus();
						return false;
					}
					else if(checknull(password.value)){
									alert("Please enter a password!");
									password.focus();
									return false;
					}	
					else return true;
				}
			break;
			case "refregform":
			var invalid="'/,-+=!@$%^&*<>?";
			with(thisform){
					if(checknull(fname.value)){
						alert("Please enter your name");
						fname.focus();
						return false;
					}
					else if(!checkemail(email.value)){
						alert("Please enter the correct email address");
						email.focus();
						return false; 
					}
					 else if(checkinvalid(contact.value,invalid) || checknull(contact.value) || checkchar(contact.value) || contact.value.length<10){
                         alert("Please enter a valid 10 digit phone number!");
                        contact.focus();
                        return false;

                    }
					else if(checknull(user.value)){
						alert("Please choose a user_id");
						user.focus();
						return false;
					}
					
					else if(checknull(password.value)){
									alert("Please choose a password!");
									password.focus();
									return false;
					}
					else if(!checkbox.checked){
									alert("Please accept all the terms and conditions!");
									checkbox.focus();
									return false;
					}
					else return true;
			}
			break;
			case "applyJob":
				var invalid="'/,-+=!@$%^&*<>?";
				with(thisform){
					if(checknull(fname.value)){
						alert("Please enter name field");
						fname.focus();
						return false;
					}
					else if(checknull(experience.value)){
						alert("Please enter total Experience");
						experience.focus();
						return false;
					}
					 else if(checkinvalid(contact.value,invalid) || checknull(contact.value) || checkchar(contact.value) || contact.value.length<10){
                         alert("Please enter a valid 10 digit phone number!");
                        contact.focus();
                        return false;

                    }
					else if(!checkemail(email.value)){
						alert("Please enter the correct email address");
						email.focus();
						return false; 
					}
					else if(checknull(profile.value)){
									alert("Please upload the profile!");
									profile.focus();
									return false;
					}
					else return true;
				}
			break;
            case "reqForm":
                with(thisform){
                    if(Name.value == ""){
		alert("Please enter your name!");
		document.getElementById("Name").focus();
		return false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Email.value)){}
	else{	alert("Invalid E-mail Address!")
			document.getElementById('Email').focus();
			return false;
		}
		if(Comments.value == ""){
		alert("Please enter your comments!");
		document.getElementById("Comments").focus();
		return false;
	}
	if(security_code.value == ""){
		alert("Please enter the verification code as shown!");
		document.getElementById("security_code").focus();
		return false;
	}
    return true;
}
            break;
            case "quick_contact":
                var invalid="'/,-+=!@$%^&*<>?";
                with(thisform){
                    if(checknull(fname.value) || fname.value == " Name"){
                        alert("Please enter your name!");
                        fname.focus();
                        return false;
                    }
                    /*else if(checkinvalid(phone.value,invalid) || checknull(phone.value) || checkchar(phone.value) || phone.value.length<10){
                         alert("Please enter a valid 10 digit phone number!");
                        phone.focus();
                        return false;

                    }*/
                   else if(!checkemail(email.value)  || email.value == " Email"){
                        alert("Please enter the correct email address");
                        email.focus();
                        return false;
                    }
                    else {
                            var xmlhttp = getXMLHTTP();
                            if(!xmlhttp){
                                alert("Browser doesn't support XMLHTTP");
                            }
                            url = "functions.php";
                            xmlhttp.onreadystatechange = function(){
                                if(xmlhttp.readyState == 4){
                                    if(xmlhttp.status == 200){
                                        document.getElementById('quickform').innerHTML = xmlhttp.responseText;
										return false;
                                    }else alert("There was a problem processing request!");
                                }
                            }
                            xmlhttp.open("POST", url, true);
                            xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                            xmlhttp.send("tbl="+escape("mail")+"&action="+escape("mail")+"&fname="+escape(fname.value)+"&phone="+escape(phone.value)+"&email="+escape(email.value)+"&comments="+escape(comments.value));
                        return false;
                    }
                }
            break;
			case "job_add":
			with(thisform){
				if(checknull(job_code.value)){
					document.getElementById('job_code').innerHTML = job_code_msg;
					job_code.focus();
				}
				else if(checknull(job_title.value)){
					document.getElementById('job_title').innerHTML = job_title_msg;
					job_title.focus();
				}
				else if(checknull(positions_open.value)){
					document.getElementById('positions_open').innerHTML = positions_open_msg;
					positions_open.focus();
				}
				else if(checknull(job_experience.value)){
					document.getElementById('job_experience').innerHTML = job_experience_msg;
					job_experience.focus();
				}
				else if(checknull(reqired_skills.value) || reqired_skills.value == "Please enter the skills required!"){
					document.getElementById('reqired_skills').innerHTML = reqired_skills_msg;
					reqired_skills.focus();
				}
				else if(checknull(job_description.value) || job_description.value == "Please enter the job description!"){
					document.getElementById('job_description').innerHTML = job_description_msg;
					job_description.focus();
				}
				else thisform.submit();

			}
			break;
			case "login": 
			with(thisform){
				if(checknull(username.value)){
					document.getElementById('errotMsg').innerHTML = "Username cannot be empty!";
					username.focus();
				}
				else if(checknull(password.value)){
					document.getElementById('errotMsg').innerHTML = "Password cannot be empty!";
					password.focus();
				}
				else {
					var xmlhttp = getXMLHTTP();	
					if(!xmlhttp){
						alert("Browser doesn't support XMLHTTP");
					}
					url = "../common/functions.php";
					xmlhttp.onreadystatechange = function(){
						if(xmlhttp.readyState == 4){
							if(xmlhttp.status == 200){ 
								if(xmlhttp.responseText)
								thisform.submit();
								else document.getElementById('errotMsg').innerHTML = "Invalid Username OR Password!";
							}else alert("There was a problem processing request!");
						}
					}
					xmlhttp.open("POST", url, true);
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlhttp.send("tbl="+escape(tbl.value)+"&action="+escape(action.value)+"&username="+escape(username.value)+"&password="+escape(password.value));
				}
			}
			break;
	case "request_qoute":
	with(thisform){
		var invalid="'/,-+=!@$%^&*<>?";
		 if(checkinvalid(Name.value,invalid) || checknull(Name.value) || !checkchar(Name.value)){
			alert("Please enter a valid Name!");
			Name.focus();
			return false;
		}
		
		else if(Company.value == ''){
			alert("Please Enter company name!");
			Company.focus();
			return false;
		}
		else if(!checkemail(Email.value)){
			alert("Please enter the correct email address");
			Email.focus();
			return false; 
		}
		else if(Country.value == ''){
			alert("Please select the Country Name!");
			Country.focus();
			return false;
		}
		else if(Comments.value == ''){
			alert("Please enter your comments!");
			Comments.focus();
			return false;
		}
		else if(captcha.value == ''){
			alert("Please enter the verification code as shown!");
			captcha.focus();
			return false;
			
		}
		else thisform.submit();

	}
	break;	
		
	}
	
}
