// SWICH ELEMENT
function SwichElement(ElementName,ElementID,TotalElements) {
var i = 1;
while (i <= TotalElements) {
document.getElementById(ElementName+'_'+i).style.display = 'none';
document.getElementById(ElementName+'_Button_'+i).className = '';
i++;
} 
document.getElementById(ElementName+'_'+ElementID).style.display = 'block';
document.getElementById(ElementName+'_Button_'+ElementID).className = 'Selected';
} 
// SWICH ELEMENT

// SWICH COMMENT BOXES 
function SwichComments(ElementName,ElementID,Type) {

if (document.getElementById('PostSentBox_'+ElementName+'_'+ElementID)) {
document.getElementById('PostSentBox_'+ElementName+'_'+ElementID).style.display = 'none';
}

if (Type == 'View') {
if (document.getElementById('CommentBox_'+ElementName+'_'+ElementID).style.display == 'block') {
document.getElementById('CommentBox_'+ElementName+'_'+ElementID).style.display = 'none';
} else {
document.getElementById('CommentBox_'+ElementName+'_'+ElementID).style.display = 'block';
document.getElementById('PostBox_'+ElementName+'_'+ElementID).style.display = 'none';
}
}

if (Type == 'Post') {
if (document.getElementById('PostBox_'+ElementName+'_'+ElementID).style.display == 'block') {
document.getElementById('PostBox_'+ElementName+'_'+ElementID).style.display = 'none';
} else {
document.getElementById('CommentBox_'+ElementName+'_'+ElementID).style.display = 'none';
document.getElementById('PostBox_'+ElementName+'_'+ElementID).style.display = 'block';
}
}

} 
// SWICH COMMENT BOXES

// CHECK COMMENT BOXES INPUT

// CHECK FORM
function CheckFormInput (FormName) {
var checkEmail = document[FormName].email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
valid = true;

if (checkEmail){ 
} else {
document[FormName].email.value = 'REQUIRED';
valid = false;   
}

var RequiredVariable = 'name';
if (document[FormName][RequiredVariable].value == '' || document[FormName][RequiredVariable].value == 'REQUIRED') {
document[FormName][RequiredVariable].value = 'REQUIRED';
valid = false;  
}

var RequiredVariable = 'comment';
if (document[FormName][RequiredVariable].value == '' || document[FormName][RequiredVariable].value == 'REQUIRED') {
document[FormName][RequiredVariable].value = 'REQUIRED';
valid = false;  
}

return valid;
}

// CLEAN REQUIRED
function ClearRequired (divID) {
if (divID.value == 'REQUIRED' || divID.value == 'Invalid Login') {
divID.value = '';
}
}

// CHECK COMMENT BOXES INPUT


// POP UP
function viewpopup(loadpage,PageWidth,PageHeight) {
	var intWidth = PageWidth;
	var intHeight = PageHeight;
	var intLeft = (screen.availWidth / 2) - (intWidth / 2 );
	var intTop = (screen.availHeight / 2) - (intHeight / 2 );	
	OpenWin = this.open(loadpage, "Load", 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width='+PageWidth+',height='+PageHeight+', screenX=' + intLeft + ',screenY=' + intTop + ',left=' + intLeft + ',top= ' + intTop + ''); 
	OpenWin.focus();
}
// POP UP


// FONT SIZE
var CurrentFontSize = 0;
function fontSize (Mode) {

if (Mode == 'up') {
if (CurrentFontSize == 0) {
document.styleSheets[2].disabled=false;
document.styleSheets[3].disabled=true;
CurrentFontSize = 1;
} else {
document.styleSheets[2].disabled=true;
document.styleSheets[3].disabled=true;
CurrentFontSize = 2;
}
} 
if (Mode == 'down') {
if (CurrentFontSize == 2) {
document.styleSheets[2].disabled=false;
document.styleSheets[3].disabled=true;
CurrentFontSize = 1;
} else {
document.styleSheets[2].disabled=false;
document.styleSheets[3].disabled=false;
CurrentFontSize = 0;
}
}
}
// FONT SIZE

/// SEARCH REQUIRED FILEDS 
function RequiredSeacherFiled (RequiredFiled) {
for (i=0; i< RequiredFiled.length; i++) {
	if (RequiredFiled[i].match(/email/gi)) {
	var checkEmail = document.getElementById(RequiredFiled[i]).value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (checkEmail){ 
		} else {
		document.getElementById(RequiredFiled[i]).value = 'REQUIRED';
		document.getElementById(RequiredFiled[i]).style.color = "#FF0000";
		valid = false; 
		}
	} else {	
		if (document.getElementById(RequiredFiled[i]).value == '' || document.getElementById(RequiredFiled[i]).value == 'REQUIRED' || document.getElementById(RequiredFiled[i]).value == 'n/a') {
		document.getElementById(RequiredFiled[i]).value = 'REQUIRED';
		document.getElementById(RequiredFiled[i]).style.color = "#FF0000";
		valid = false;
		}
	}	
}
return valid;
}	
/// SEARCH REQUIRED FILEDS


/// CLEAN SEARCH FILEDS 
function RequiredCleanFileds (RequiredFiled) {
	for (i=0; i< RequiredFiled.length; i++) {
	document.getElementById(RequiredFiled[i]).value = '';
	}
}	
/// CLEAN SEARCH FILEDS 

function ClearRequired (divID) {
if (divID.value == 'REQUIRED' || divID.value == 'Invalid Login') {
divID.value = '';
}
divID.style.color = "#000000";
}

function TestFileType( fileName, fileTypes ) {
if (!fileName) return;
dots = fileName.split(".")
//get the part AFTER the LAST period.
fileType = "." + dots[dots.length-1];
return (fileTypes.join(".").indexOf(fileType) != -1) ?
alert('That file is OK!') : 
alert("Please only upload files that end in types: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");
}

function TestFileType2( fileName, fileTypes ) {
if (!fileName) return;
dots = fileName.split(".")
//get the part AFTER the LAST period.
fileType = "." + dots[dots.length-1];
return (fileTypes.join(".").indexOf(fileType) != -1) ?
true : 
false;
}
