
//********* START -- News Validation -- *********
function ValidateNews() {

var retval = true;
if (document.getElementById('txtHeadline').value == "") {
	alert("Please enter a headline.")
	retval = false;
	document.getElementById('txtHeadline').focus();
}

else if (document.getElementById('txtBody').value == "") {
	alert("Please enter a description.")
	retval = false;
	document.getElementById('txtBody').focus();
} 

else if (document.getElementById('txtLocation').value == "") {
	alert("Please enter a location.")
	retval = false;
	document.getElementById('txtLocation').focus();
} 
else if (valDate(document.getElementById('txtPublishDate').value) == false) {
	alert("Please enter a valid publish date.")
	retval = false;
	document.getElementById('txtPublishDate').focus();
} 

else if (valDate(document.getElementById('txtExpireDate').value) == false) {
	alert("Please enter a valid expiry date.")
	retval = false;
	document.getElementById('txtExpireDate').focus();
} 

 return retval;
 
 
 }
 
//start
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Please enter a valid email address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter a valid email address.")
		    return false
		}

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter a valid email address.")
		    return false
		 }

		
 		 return true					
	}

//end





//********* END News admin *********



//********* START -- Document upload Validation -- *********

function ValidateDocs() {

var retval = true;
if (document.getElementById('ddlSection').value == "0") {
	alert("Please select a section.")
	document.getElementById('ddlSection').focus();
	retval = false;
}
else if (document.getElementById('txtDocumentTitle').value == "") {
	alert("Please enter a document title.");
	retval = false;
	document.getElementById('txtDocumentTitle').focus();
} 

 return retval;
}
//********* END document upload *********



//*********  START -- Integrator Admin Validation -- *********

function ValidateIntegrators() {

var retval = true;
if (document.getElementById('txt_ci_contact').value == "") {
	alert("Please enter a contact name.")
	retval = false;
	document.getElementById('txt_ci_contact').focus();
}

else if (echeck((document.getElementById('txt_ci_contact_email')).value)==false){
	//	(document.getElementById(control + ':' + 'txt_ui_email')).value=""
	retval = false;
	document.getElementById('txt_ci_contact_email').focus();
		return false
}	

else if (document.getElementById('txt_ci_company').value == "") {
	alert("Please enter a company name.");
	retval = false;
	document.getElementById('txt_ci_company').focus();
	
} 
else if (document.getElementById('txt_ci_addline1').value == "") {
	alert("Please enter a company address.");
	retval = false;
	document.getElementById('txt_ci_addline1').focus();
	
} 

else if (document.getElementById('txt_ci_city').value == "") {
	alert("Please enter a city.");
	retval = false;
	document.getElementById('txt_ci_city').focus();
	
} 
else if (document.getElementById('txt_ci_state').value == "") {
	alert("Please select a state.")
	retval = false;
	document.getElementById('txt_ci_state').focus();
} 


else if (document.getElementById('txt_ci_postal').value == "") {
	alert("Please enter a zip or postal code.");
	retval = false;
	document.getElementById('txt_ci_postal').focus();
} 

 return retval;
}

//********* END Integrator Admin *********




//********* START Email Validation *********


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Please enter a valid email address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter a valid email address.")
		    return false
		}

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter a valid email address.")
		    return false
		 }
	
 		 return true					
	}

//********* END Email Validation *********




//********* START -- Profile Info Validation -- *********
function ValidateProfileInfo(control) {
//alert(control)

var retval = true;

if (document.getElementById(control + ':' + 'txt_ui_password'))
{
	password1 = document.getElementById(control + ':' + 'txt_ui_password').value
	password2 = document.getElementById(control + ':' + 'txt_ui_password2').value
	
	if (password1.length < 4)
	{
		alert("Please enter a password longer than 4 characters.")
		retval = false;
	}
	else if (password1 != password2)
	{
		alert("Password confirmation does not match.")
		retval = false;
	}
}


if (document.getElementById(control + ':' + 'txt_ui_fname').value == "") {
	alert("Please enter a first name.")
	retval = false;
	document.getElementById(control + ':' + 'txt_ui_fname').focus();
}

else if (document.getElementById(control + ':' + 'txt_ui_lname').value == "") {
	alert("Please enter a last name.")
	retval = false;
		document.getElementById(control + ':' + 'txt_ui_lname').focus();
} 

else if (document.getElementById(control + ':' + 'txt_ui_email').value == "") {
	alert("Please enter an email address.")
	retval = false;
	document.getElementById(control + ':' + 'txt_ui_email').focus();
	}

else if (echeck((document.getElementById(control + ':' + 'txt_ui_email')).value)==false){
	//	(document.getElementById(control + ':' + 'txt_ui_email')).value=""
	retval = false;
	document.getElementById(control + ':' + 'txt_ui_email').focus();
		return false
	}	


else if (document.getElementById(control + ':' + 'txt_ui_login') && document.getElementById(control + ':' + 'txt_ui_login').value.length < 5) {
	alert("Please enter a user name with at least 5 characters.")
	retval = false;
	document.getElementById(control + ':' + 'txt_ui_login').focus();
}


//else if (document.getElementById(control + ':' + 'txt_ui_password')) {
 //if (document.getElementById(control + ':' + 'txt_ui_password').value == "")
	//{alert("Please enter a Password.")
	//retval = false;
	//document.getElementById(control + ':' + 'txt_ui_password').focus();
	//}
	
//}


else if (document.getElementById(control + ':' + 'txt_ci_company') && document.getElementById(control + ':' + 'txt_ci_company').value == "") {
	alert("Please enter a company name.")
	retval = false;
	document.getElementById(control + ':' + 'txt_ci_company').focus();
} 

else if (document.getElementById(control + ':' + 'txt_ci_addline1').value == "") {
	alert("Please enter a company address.")
	retval = false;
	document.getElementById(control + ':' + 'txt_ci_addline1').focus();
} 

else if (document.getElementById(control + ':' + 'txt_ci_city').value == "") {
	alert("Please enter a city.")
	retval = false;
	document.getElementById(control + ':' + 'txt_ci_city').focus();
} 

else if (document.getElementById(control + ':' + 'txt_ci_state').value == "") {
	alert("Please select a state.")
	retval = false;
	document.getElementById(control + ':' + 'txt_ci_state').focus();
} 


else if (document.getElementById(control + ':' + 'txt_ci_postal').value == "") {
	alert("Please enter a zip / postal code.")
	retval = false;
	document.getElementById(control + ':' + 'txt_ci_postal').focus();
} 

else if (document.getElementById(control + ':' + 'ddl_ci_country').value == "") {
	alert("Please select a country.")
	retval = false;
	document.getElementById(control + ':' + 'ddl_ci_country').focus();
} 


 return retval;
}
//********* END -- Profile Info Validation -- *********



//********* START -- Change Password -- *********

function ValidateChangePW() {

var retval = true;
if (document.getElementById('txtPassword1').value == "") {
	alert("Please enter a password.")
	retval = false;
	document.getElementById('txtPassword1').focus();
}
else if (document.getElementById('txtPassword2').value == "") {
	alert("Please RE ENTER the password.");
	retval = false;
	document.getElementById('txtPassword2').focus();
	
} 

 return retval;
}
//********* END Change Password *********



//********* START -- general popup window function *********

function OpenPopup(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//********* END general popup window function *********



//********* START -- default focus *********
function LoginFocus() {

	document.getElementById('txtUserName').focus();
}

//********* END default focus *********
 



//********* START -- Forum Validation -- *********

function ValidateForum() {

var retval = true;
if (document.getElementById('txtTopicTitle').value == "") {
	alert("Please enter a forum topic.")
	document.getElementById('txtTopicTitle').focus();
	retval = false;
}
else if (document.getElementById('txtTopicBody').value == "") {
	alert("Please enter a forum description.");
	retval = false;
	document.getElementById('txtTopicBody').focus();
} 

 return retval;
}
//********* END Forum Validation*********


function valDate(val)
{
	var isvalid = true;
	
	if (!Date.parse(val))
		isvalid = false;
	else
	{
		dparts = val.split('/');
		
		if (dparts.length == 3)
		{
			year = dparts[2];
			day = dparts[1];
			month = dparts[0];
			
			if (year < 1970 || year > 2010)
				isvalid = false;
			if (month > 12 || month < 1)
			    isvalid = false;
			if (day > getDays(month - 1,year) || day < 1)
				isvalid = false;
		}		
		else
		   isvalid = false;
	}
	
	
	return isvalid;
	
}


function isLeapyear(y)
	{
		if(y%100==0) {
			if(y%400==0)
			return true;
			}
		else if(y%4==0)
			return true;
		else
			return false;		 
	}
	
	function getDays(m,y)
	{
		var ar = new Array();
		ar[0]=31;
		ar[1]=isLeapyear(y)?29:28;
		ar[2]=31;
		ar[3]=30;
		ar[4]=31;
		ar[5]=30;
		ar[6]=31;
		ar[7]=31;
		ar[8]=30;
		ar[9]=31;
		ar[10]=30;
		ar[11]=31;
	    
	return ar[m];
	}

