//
//   
//    Copyright     :   Confidential and Proprietary. 
//                      Copyright RISI, 2007
//                                      
//    File name     :   industryjobs.js
//   
//    Description   :   Javascript to handle Industryjobs
//   
//    Author        :   Cognizant
//   
//    Date          :   Sep 25, 2007
//    
//    Modification History      
//   
//    Revision No.      Author              Date                Comments
//      
//   
//
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];}}

}


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];}
}



function popup(pageurl)
{
window.open(pageurl,"home");
}



function getController()

{	

document.market.pageid.value="industryjobs";
document.market.action="/industry-jobs";
document.market.submit();

}


function textCounter(elem, helperMsg) {

	

if (elem.value.length > 2500){ // if too long.trim it!
	elem.value = elem.value.substring(0,2500);
	alert(helperMsg);
	elem.focus();
	return false;

	}else{

			return true;

	}

}

function headertextCounter(elem, helperMsg) {

if (elem.value.length > 250){ // if too long.trim it!
	elem.value = elem.value.substring(0,250);
	alert(helperMsg);

	elem.focus();

	return false;

			}else{

					return true;

				 }

}



//checking for maxlength in textareas-job header and jobdescription

function ismaxlength(obj){

	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""

	if (obj.getAttribute && obj.value.length>mlength)

	obj.value=obj.value.substring(0,mlength)

}





//validating email field

function emailValidator(elem, helperMsg){

	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

			if(elem.value.match(emailExp)){

			return true;

			}

			else{

				alert(helperMsg);

				elem.focus();

				return false;

				}

}





//checking for empty values

function isEmpty(elem, helperMsg){

	if(elem.value.length == 0){

		alert(helperMsg);

		elem.focus(); // set the focus to this input

		return false;

	}

	return true;

}



//validate upload image

function validateupload(elem,helperMsg)



    {

		if(elem.value.length>4)

			{

			   var str=elem.value;

			   var len=str.length;

			   //alert(len);

			   var i=0;

			   var j=0;
			   for(i=0;i<len;i++)

			   			{

			   				if(str.charAt(i)==".")

			   				{

						 		j++;

					   		}



						}

						var section=str.split(".");

						var subsection=section[j].toLowerCase();

			   			





        if(subsection == "jpeg"||subsection == "jpg"||subsection == "gif"||subsection == "bmp"||subsection == "png"||subsection == ".jpg"||subsection == ".gif"||subsection == ".bmp"||subsection == ".png")

			{

			

	   		return true;

			}

		else

			{

		  	alert(helperMsg);

		  	elem.focus();

	      		return false;

			}

            }

			else

				{

				 alert(helperMsg);

				 elem.focus();

				 return false;

				}



     }







//Checking for a valid URL

function validateURL(elem, helperMsg){



if(elem.value.length>7){

			

var len=elem.value.length;

var subElem = elem.value.substring(0,7);

			if(subElem.toLowerCase() == "http://")

			{

			

			return true;

			}

			else

			{

			alert(helperMsg);

			elem.focus();

			return false;

			}

	}

	else

	{

	alert(helperMsg);

	elem.focus();

	return false;



	}



}





function form_validator(){



		//make sure hidden and iframe values are in sync for all rtes before submitting form

	updateRTEs();

if(isEmpty(document.theForm.jobtitle,"Please Enter the Job Title")){

 if(isEmpty(document.theForm.conname,"Please Enter Contact Name")){

  if(isEmpty(document.theForm.conphone,"Please Enter Contact PhoneNumber")){

   if(isEmpty(document.theForm.location,"Please Enter the Location")){	

	 if(isEmpty(document.theForm.companyname,"Please Enter the Company Name")){

		if(isEmpty(document.theForm.URL,"Please Enter the URL")){

			if(validateURL(document.theForm.URL,"Please Enter a Valid URL")){

				if(isEmpty(document.theForm.headertext,"Please Enter the text in the Job Header field")){

					if(headertextCounter(document.theForm.headertext,"Maximum limit exceeded.You are allowed to enter only 250 characters.")){

					if(isEmpty(document.theForm.jobdesc,"Please enter text in the Job Description section")){

						if(textCounter(document.theForm.jobdesc,"Maximum limit exceeded.You are allowed to enter only 2500 characters.")){

								//if(isEmpty(document.theForm.uploadfile,"Please Select an Image to Upload")){

										 if(document.theForm.uploadfile.value.length>0)

										 {

											if(validateupload(document.theForm.uploadfile,"Please Select a Valid Image File"))

											 {

												if(isEmpty(document.theForm.email,"Please enter an Email Address"))

												{

													if(emailValidator(document.theForm.email,"Please enter a valid Email Address"))

													{

															return true;

													 }

												 }

											  }

										   }

										  else

										  {

												if(isEmpty(document.theForm.email,"Please enter an Email Address"))

												{

													if(emailValidator(document.theForm.email,"Please enter a valid Email Address"))

													 {

														return true;

													 }//email validator

												 }//email address should not be empty

										   }//else end

									}//job description

								}//job description should not be empty

							  }//job header text

							}//job header text must not be empty 

						}//URL

					}//URL must not be empty 

				}//company name should not be empty

			 }//location should not be empty

           }//phone number should not be empty

         }//contact name should not be empty

	 }//jobtitle should not be empty
          
 
				

					return false;

						

						

}




function getSubmit()

{		

		document.theForm.upload.value=document.theForm.uploadfile.value;

		document.theForm.jobdescription.value=document.theForm.jobdesc.value;

		document.theForm.page.value="industryjobs";

		document.theForm.action="/industryjobssendmail";

		document.theForm.submit();

		

}




