// JavaScript Document




function contentPageValidate() {
	if(SelectValidate(document.frmContentPage.PageTitleID,"Title")==false) { return false;	}
	//if(TextAreaValidate(document.frmContentPage.PageContent,"Description")==false) { return false;	}
	
	if(document.frmContentPage.ImagePath.value!=""){
		if (!/(\.(gif|jpg|jpeg))$/i.test(document.frmContentPage.ImagePath.value)){
		alert("Please attach a valid Image file");
		document.frmContentPage.ImagePath.focus();
		return false;
		}
	}
	document.frmContentPage.action = "contentPage.php";
	document.frmContentPage.submit();
}

function energyValidate() {
	if(TextValidate(document.frmEnergy.EnergyTitle,"Title")==false) { return false;	}
	//if(TextAreaValidate(document.frmContentPage.PageContent,"Description")==false) { return false;	}
	
	if(document.frmEnergy.ImagePath.value!=""){
		if (!/(\.(gif|jpg|jpeg))$/i.test(document.frmEnergy.ImagePath.value)){
		alert("Please attach a valid Image file");
		document.frmEnergy.ImagePath.focus();
		return false;
		}
	}
	document.frmEnergy.action = "energy.php";
	document.frmEnergy.submit();
}
function deleteEnergy(id) {
	if(confirm("Are you sure you want to delete the Renewable Energy?")) {
	    document.form1.action="energy.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteContentPage(id) {
	if(confirm("Are you sure you want to delete the Content Page?")) {
	    document.form1.action="contentPage.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function newsValidate() {
	if(TextValidate(document.frmnews.PageTitle,"News Title")==false) { return false;	}
	if(TextValidate(document.frmnews.ShortDescription,"Teaser")==false) { return false;	}
	var ShortDescription = document.frmnews.ShortDescription.value;
	if(ShortDescription.length>255) {
		alert("The maximun length should be 255 character!");
		document.frmnews.ShortDescription.focus();
		return false;
	}
	if(document.frmnews.ImagePath1.value!=""){
		if (!/(\.(gif|jpg|jpeg))$/i.test(document.frmnews.ImagePath1.value)){
		alert("Please select a valid Image");
		document.frmnews.ImagePath1.focus();
		return false;
		}
	}
	if(document.frmnews.ImagePath2.value!=""){
		if (!/(\.(gif|jpg|jpeg))$/i.test(document.frmnews.ImagePath2.value)){
		alert("Please select a valid Image");
		document.frmnews.ImagePath2.focus();
		return false;
		}
	}	
	document.frmnews.action = "news.php";
	document.frmnews.submit();
}

function deleteNews(id) {
	if(confirm("Are you sure you want to delete the News?")) {
	    document.form1.action="news.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function projectValidate() {
	if(TextValidate(document.frmproject.ProjectTitle,"Project Title")==false) { return false;	}
	if(SelectValidate(document.frmproject.ProjectType,"Project Type")==false) { return false;	}
	//if(TextValidate(document.frmproject.Monthofcompletion,"Month of completion")==false) { return false;	}
	//if(TextValidate(document.frmproject.YearofCompletion,"Year of Completion")==false) { return false;	}
	//if(TextAreaValidate(document.frmproject.ProjectDescription,"Project Description")==false) { return false;	}
	if(document.frmproject.YearofCompletion.value!="" && document.frmproject.Monthofcompletion.value=="") {
		if(SelectValidate(document.frmproject.Monthofcompletion,"Year of Completion")==false) { return false;	}
	}
	if(document.frmproject.Monthofcompletion.value!="" && document.frmproject.YearofCompletion.value=="") {
		if(SelectValidate(document.frmproject.YearofCompletion,"Year of Completion")==false) { return false;	}
	}
	if(document.frmproject.Monthofcompletion.value!="" && document.frmproject.YearofCompletion.value!="") {
		if(ProjectDateValidate(document.frmproject.ProjectType,document.frmproject.Monthofcompletion,document.frmproject.YearofCompletion)==false) { return false;	}	
	}
	document.frmproject.action = "project.php";
	document.frmproject.submit();
}
 



// To validate change password form fields

function changePwdvalidate()
{
	var form_name=document.frmpassword;
	if(TextValidate(form_name.old_password,"Old Password")==false){return false;}
	if(TextValidate(form_name.new_password,"New Password")==false){return false;}
	if(TextValidate(form_name.confirm_password,"Confirm Password")==false){return false;}
	if(Comparetextboxes(form_name.new_password,form_name.confirm_password)==false){return false;}
}

//To validate forgot password form

function forgetValidate()
{
	var form_name=document.frmforget;
	if(TextValidate(form_name.txtemail,"Email")==false){return false;}
	if(TextValidate(form_name.txtusername,"User Name")==false){return false;}
	document.frmforget.action = "forgotPassword.php?status=submit";
	document.frmforget.submit();
}


function onCareerFormSubmit(){
	var form = document.form1;
	if(TextValidate(form.Name,"Name")==false) { return false;}		
	if(TextValidate(form.JobTitle,"Job Title")==false) { return false;}	
	if(EmailValidate(form.Email,"E-mail")==false) { return false;}	
	if(TextValidate(form.Telephone,"Telephone")==false) { return false;}
	var file = form.fileatt.value;
	if(trim(file)!="") {		
		var filearray = file.split(".");
		if(filearray.length<=1) {
			alert("Please attach a valid file");
			form.fileatt.focus();
			return false;
		}
	}
	form.action="careers.php";
	form.submit();
	return true;
}

function onServiceEnquiryFormSubmit(){
	var form = document.form1;
	if(TextValidate(form.Name,"Name")==false) { return false;}		
	if(TextValidate(form.CompanyName,"Institution / Company Name")==false) { return false;}	
	if(TextAreaValidate(form.Address,"Address")==false) { return false;}		
	if(TextValidate(form.PinCode,"Pin Code")==false) { return false;}			
	if(TextValidate(form.Telephone,"Telephone")==false) { return false;}
	if(EmailValidate(form.Email,"E-mail")==false) { return false;}	
	if(SelectValidate(form.ServiceRequestedFor,"Service Requested for")==false) { return false;}	
	if(TextValidate(form.Product,"Product")==false) { return false;}
	if(trim(form.DateofInstallation.value)!="") {
		if(DateValidate1(form.DateofInstallation,"Date of Installation")==false) { return false;}
	}	
	form.action="serviceEnquiry.php";
	form.submit();	
}


function onSalesEnquiryFormSubmit(){
	var form = document.form1;
	if(TextValidate(form.Name,"Name")==false) { return false;}		
	if(TextValidate(form.CompanyName,"Institution / Company Name")==false) { return false;}	
	if(TextAreaValidate(form.Address,"Address")==false) { return false;}		
	if(TextValidate(form.PinCode,"Pin Code")==false) { return false;}			
	if(TextValidate(form.Telephone,"Telephone")==false) { return false;}
	if(EmailValidate(form.Email,"E-mail")==false) { return false;}	
	if(SelectValidate(form.ServiceRequestedFor,"Service Requested for")==false) { return false;}	
	var chkcount = document.getElementById("InterestedInCount").value;
	var InterestedIn = "";
	var flag = "";
	for(var i=1;i<=chkcount;i++) {
		var id = "InterestedIn_"+i;
		if(document.getElementById(id).checked==true) {
			flag = "1";
			if(InterestedIn=="") {
				InterestedIn = document.getElementById(id).value;
			}else {
				InterestedIn = InterestedIn+ ", "+document.getElementById(id).value ;
			}
		}
	}
	document.getElementById("InterestedIn").value = InterestedIn;
	if(InterestedIn=="") {
		alert("Please choose an option for Interested in");
		document.getElementById("InterestedIn_1").focus();
		return false;
	}
	form.action="salesEnquiry.php";
	form.submit();	
}




function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// to validate the prenious job fields
function previousjobValidate(){
	if(TextValidate(document.frmpreviousjobs.txtproductname	,"Product name")==false) { return false;}		
	if(TextValidate(document.frmpreviousjobs.txtuser,"Customer name")==false) { return false;}	
	if(TextValidate(document.frmpreviousjobs.txtprice,"Price")==false) { return false;}		
	if(NumberValidate(document.frmpreviousjobs.txtprice,"Price")==false) { return false;}			
	if(TextValidate(document.frmpreviousjobs.txtquantityordered,"Quantity ordered")==false) { return false;}
	if(NumberValidate(document.frmpreviousjobs.txtquantityordered,"Quantity ordered")==false) { return false;}	
	if(TextValidate(document.frmpreviousjobs.txtordereddate,"Ordered date")==false) { return false;}	
	if(DateFormatValidate1(document.frmpreviousjobs.txtordereddate,"Ordered date")==false) { 
		document.frmpreviousjobs.txtordereddate.value="";
		document.frmpreviousjobs.txtordereddate.focus();
		return false;}		
	//if(DateFormatValidate(document.frmpreviousjobs.txtordereddate,"Ordered date")==false){return false};			
	if(TextValidate(document.frmpreviousjobs.txtinvoicenumber,"Invoice number")==false) { return false;}	
	document.frmpreviousjobs.action="previousjob.php";
	document.frmpreviousjobs.submit();	
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Alert message for deleting admin user

function deleteAdmin(id) {
	if(confirm("Are you sure you want to delete the Admin?")) {
	    document.form1.action="admin.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}




// To validate admin form fields

function adminValidate() {
	if(SelectValidate(document.frmadmin.seladminsalutation,"Salutation")==false) { return false;	}
	if(SelectValidate(document.frmadmin.UserRights,"Type")==false) { return false;	}
	if(TextValidate(document.frmadmin.txtadminname,"Admin Name")==false) { return false;	}
 	if(TextValidate(document.frmadmin.txtadminemail,"Email")==false) { return false;	}
	if(EmailValidate(document.frmadmin.txtadminemail,"Email")==false) { return false;	}
	if(TextValidate(document.frmadmin.txtadminusername,"User Name")==false) { return false;	}
	if(TextValidate(document.frmadmin.pwdadminpassword,"Password")==false) { return false;	}
	if(TextValidate(document.frmadmin.pwdadminconfirmpassword,"Confirm Password")==false) { return false;}
   	if(document.frmadmin.pwdadminconfirmpassword.value != document.frmadmin.pwdadminpassword.value){
		alert("Your Password and Confirm Password does not match.");
		document.frmadmin.pwdadminconfirmpassword.focus();
		return false;
	}
	document.frmadmin.UserRights.disabled = false;
	document.frmadmin.action = "admin.php";
	document.frmadmin.submit();
}


// To call the page inside iframe

function callpage(pagename){
	var page=pagename+"?pagename="+pagename;
	//alert(page);
	window.frames.iframecontent.src=page;
	
}

