
window.onunload = testme;
function testme() { //alert("11111111111111111111");
}

function $(id)
{
	if(document.all && !document.getElementById)
	{
		return document.all[id];
	}
	else
	{
		return document.getElementById(id);
	}
}

function trim(s) 
{
	return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

function  isSelectCheckbox(len,str)
{
	var flag=0;
	for(i=0;i<len;i++)
	{
		if($(str+i).checked==true)
		{
			flag==1;
			return true;
		}
	}
	if(flag==0)
	{
		return false;
	}
}

function isAlphaNumeric(inputStr)
{
	if (inputStr.match(/^[a-zA-Z0-9\-]+$/))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function emailCheck (emailStr) 
{
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) 
	{
		throw new Error("Please check that your e-mail address is correctly entered.");
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			throw new Error("Your e-mail address contains invalid characters.");
		}
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			throw new Error("Your e-mail domain name contains invalid characters.");
		}
	}
	if (user.match(userPat)==null) 
	{
		throw new Error("Your e-mail address doesn't seem to be valid - please check your spelling.");
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				throw new Error("Domain IP address is invalid!");
			}
		}
	return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			throw new Error("Your e-mail address does not seem to be valid - check your spelling, including wrong use of commas, or a full point [.] at the end of the address .");
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		throw new Error("Your e-mail address must end with a domain or two letter country.");
	}
	if (len<2) 
	{
		throw new Error("Your e-mail address is missing a hostname - check spelling. Or you may have added a blank space at the end of the address - backspace to remove this.");
	}
 return true;
}

// Remember me --- start---

function populatecookie()
{
	var email=$("email").value;
	var pwd=$("password").value;
	setCookie('email',$("email").value,30);
	setCookie('password',$("password").value,30);
}

function retrievecookie()
{
	if(getCookie('email') && getCookie('password'))
	{
		$("email").value=getCookie('email');
		$("password").value=getCookie('password');
		if (getCookie('email') != '' && getCookie('password') != '')
		{
			$("login").submit(); // autosubmit the form
		}
	}
}

function getCookie(c_name)
{
	var retStr = false;
	if (document.cookie.length > 0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
				retStr = unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return retStr;
}

function setCookie(c_name,value,expiredays)
{	
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name + "=" + escape(value)+ ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n)
{
	for (var i = 1; i <= n; i++)
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	} 
	return this
}

function isDate(dtStr)
{
	var dtCh= "/";
	var minYear=2007;
	var maxYear=2020;
	
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
 	year=parseInt(strYr)
    
 
	if (pos1==-1 || pos2==-1)
	{
		throw new Error("The date format should be : mm/dd/yyyy");
		return false
	}
	if (strMonth.length<1 || month<1 || month>12)
	{
		throw new Error("Please enter a valid month");
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
	{
		throw new Error("Please enter a valid day");
		return false
	}

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
	{
		throw new Error("Please enter a valid 4 digit year between  "+minYear+" and "+maxYear);
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		throw new Error("Please enter a valid date");
		return false
	}
	return true
}

function isInteger(s)
{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{ 
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()-. ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;

	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function validate()
{ 
	if ($("email").value == '')
	{
		$("errElem").innerHTML="Email cannot be empty.";
		$("email").select();
		$("email").focus();
		return false;
	}

	try
	{
		emailCheck(trim($("email").value));
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("email").select();
		$("email").focus();
		return false;
	}	

	if ($("password").value=="")
	{
		$("errElem").innerHTML="Password cannot be empty.";
		$("password").select();
		$("password").focus();
		return false;
	}
	if($("remember").checked)
	{
		//populatecookie(); // cannot do that here, must wait until login succeeds
	}
	return true;
}

function addUserStep2Validation()
{
	if($("ccemail").value!='')
    {
		try
		{
			emailCheck(trim($("ccemail").value));
		}
		catch (e)
		{
			$("errElem").innerHTML=e.message;
			$("ccemail").select();
			$("ccemail").focus();
			return false;
		}	
    }
}

function photoValidation()
{	
	if ($("photoName").value == '')
	{
		$("errElem").innerHTML="Name cannot be empty";
		$("photoName").select();
		$("photoName").focus();
		return false;
	}
	if ($("photoUpload").value == '')
	{
		$("errElem").innerHTML="Upload file cannot be empty";
		$("photoUpload").select();
		$("photoUpload").focus();
		return false;
	}
	
	var file=$("photoUpload").value;
	ext = file.substring(file.length-3,file.length);
	ext = ext.toLowerCase();
	if(ext != 'jpg' && ext != 'gif' && ext != 'png' && ext != 'jpeg' && ext != 'bmp')
	{
		$("errElem").innerHTML="Please select a valid file";
		return false; 
	}	
}

function uploadPictureValidation()
{
	if ($("uploadprofpic").value == '')
	{
		$("errElem").innerHTML="Upload file cannot be empty";
		$("uploadprofpic").select();
		$("uploadprofpic").focus();
		return false;
	}
	
	var file=$("uploadprofpic").value;
	ext = file.substring(file.length-3,file.length);
	ext = ext.toLowerCase();
	if(ext != 'jpg' && ext != 'gif' && ext != 'png' && ext != 'jpeg' && ext != 'bmp')
	{
		$("errElem").innerHTML="Please select a valid file";
		return false; 
	}
}

function passwordValidation()
{	
    if ($("newpassword").value == '')
	{
		$("errElem").innerHTML="Newpassword cannot be empty";
		$("newpassword").select();
		$("newpassword").focus();
		return false;
	}
	if ($("verifypassword").value == '')
	{
		$("errElem").innerHTML="VerifyPassword cannot be empty";
		$("verifypassword").select();
		$("verifypassword").focus();
		return false;
	}
	if ($("newpassword").value.length<6)
	{		
        $("errElem").innerHTML="The password length should be of minimum six characters";
		$("newpassword").select();
		$("newpassword").focus();
		return false;
	} 
	if($("verifypassword").value.length<6)
	{		
        $("errElem").innerHTML="The password length should be of minimum six characters";
		$("verifypassword").select();
		$("verifypassword").focus();
		return false;
	}
    if ($("newpassword").value!=$("verifypassword").value)
	{	
		$("errElem").innerHTML="Password mismatch";
		$("newpassword").select();
		$("newpassword").focus();
		return false;
	} 
}

function blogValidate()
{
	if ($("comment").value == '')
	{
		$("errElem").innerHTML="Posting empty message is not allowed";
		$("comment").select();
		$("comment").focus();
		return false;
	}
}

function forumReplyValidation()
{
	if ($("replyText").value == '')
	{
		$("errElem").innerHTML="Posting empty message is not allowed";
		$("replyText").select();
		$("replyText").focus();
		return false;
	}
}

function pollValidation()
{
	if ($("description").value == '')
	{
		$("errElem").innerHTML="Poll description cannot be empty";
		$("description").select();
		$("description").focus();
		return false;
	}
	try
	{
		isDate($("startdate").value);	
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("startdate").select();
		$("startdate").focus();
		return false;
	}	

	try
	{
		isDate($("enddate").value);	
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("enddate").select();
		$("enddate").focus();
		return false;
	}	
	var len=$("cbxlength").value;
	if(!(isSelectCheckbox(len,"group")))
	{
		$("errElem").innerHTML="select group to display";
		return false;
	}
	if($("polloption1").value==''&& $("polloption2").value==''&& $("polloption3").value==''&& $("polloption4").value=='')
	{
		$("errElem").innerHTML="Can't create poll without any option";
		return false;
	}    
}

function reminderValidation()
{	
	if ($("name").value == '')
	{
		$("errElem").innerHTML="Reminder cannot be empty.";
		$("name").select();
		$("name").focus();
		return false;
	}
	try
	{
		isDate($("duedate").value);
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("duedate").select();
		$("duedate").focus();
		return false;
	}	

	try
	{
		isDate($("startdate").value);
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("startdate").select();
		$("startdate").focus();
		return false;
	}	

	try
	{
		isDate($("enddate").value);	
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("enddate").select();
		$("enddate").focus();
		return false;
	}	
	var len=$("cbxlength").value;
	if(!(isSelectCheckbox(len,"group")))
	{
		$("errElem").innerHTML="Select any group to whom which this reminder should be displayed";
		return false;
	}
}

function announcementValidation()
{
	if ($("title").value == '')
	{
		$("errElem").innerHTML="Title cannot be empty";
		$("title").select();
		$("title").focus();
		return false;
	}
	if ($("description").value == '' && $("link").value == '')
	{
		$("errElem").innerHTML="Both Description and Link cannot be empty";
		$("description").select();
		$("description").focus();
		return false;
	}
	try
	{
		isDate($("startdate").value);
		
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("startdate").select();
		$("startdate").focus();
		return false;
	}	

	try
	{
		isDate($("enddate").value);	
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("enddate").select();
		$("enddate").focus();
		return false;
	}
	var len=$("cbxlength").value;
	if(!(isSelectCheckbox(len,"group")))
	{
		$("errElem").innerHTML="Select any group to whom which this announcement should be displayed";
		return false;
	}
}

function addForumTopicValidation()
{
	if ($("topicName").value == '')
	{
		$("errElem").innerHTML="Topic name cannot be empty";
		$("topicName").select();
		$("topicName").focus();
		return false;
	}
	if ($("file").value == '')
	{
		$("errElem").innerHTML="Choose any image to upload";
		$("file").select();
		$("file").focus();
		return false;
	}
	var file=$("file").value;
	ext = file.substring(file.length-3,file.length);
	ext = ext.toLowerCase();
	if(ext != 'jpg' && ext != 'gif' && ext != 'png' && ext != 'jpeg' && ext != 'bmp')
	{
		$("errElem").innerHTML="Please select a valid file";
		return false; 
	}
}

function addProfileQuestionValidation()
{	
	if ($("questionName").value == '')
	{
		$("errElem").innerHTML="Question name cannot be empty";
		$("questionName").select();
		$("questionName").focus();
		return false;
	}
    if($("required1").checked==false&&$("required2").checked==false)
	{
		$("errElem").innerHTML="Please choose any option";
		$("required1").select();
		$("required1").focus();
		return false;
	}
	if($("public1").checked==false&&$("public2").checked==false)
	{
		$("errElem").innerHTML="Please choose any option";
		$("public1").select();
		$("public1").focus();
		return false;
	}
	if($("active1").checked==false&&$("active2").checked==false)
	{
		$("errElem").innerHTML="Please choose any option";
		$("active1").select();
		$("active1").focus();
		return false;
	}
	var len=$("cbxlength").value;
	
	if(!(isSelectCheckbox(len,"profilename")))
	 {
		$("errElem").innerHTML="Select any available profile type to whom which this question should be displayed";
		return false;
	}
}

function  manageSettingsValidation()
{
	var Phone=$("publishedPhoneNumber").value;
	if ((Phone==null)||(Phone==""))
	{
		$("errElem").innerHTML="Please enter your phone number";
		return false;
	}
	if (checkInternationalPhone(Phone)==false)
	{
		$("errElem").innerHTML="Please enter a valid phone number";
		return false;
	}
	try
	{
		emailCheck(trim($("inviteStudentEmailFromAddress").value));
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("inviteStudentEmailFromAddress").select();
		$("inviteStudentEmailFromAddress").focus();
		return false;
	}	
	
	try
	{
		emailCheck(trim($("forgotPasswordEmailFromAddress").value));
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("forgotPasswordEmailFromAddress").select();
		$("forgotPasswordEmailFromAddress").focus();
		return false;
	}	
	
	try
	{
		emailCheck(trim($("contactUsEmailToAddress").value));
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("contactUsEmailToAddress").select();
		$("contactUsEmailToAddress").focus();
		return false;
	}
	try
	{
		emailCheck(trim($("reportAbuseEmailToAddress").value));
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("reportAbuseEmailToAddress").select();
		$("reportAbuseEmailToAddress").focus();
		return false;
	}
	
}

function addUserValidation()
{	
	if ($("email").value == '')
	{
		$("errElem").innerHTML="Email cannot be empty.";
		$("email").select();
		$("email").focus();
		return false;
	}
	try
	{
		emailCheck(trim($("email").value));
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("email").select();
		$("email").focus();
		return false;
	}	
	if ($("firstname").value == '')
	{
		$("errElem").innerHTML="First name cannot be empty.";
		$("firstname").select();
		$("firstname").focus();
		return false;
	}
	if(isInteger($("firstname").value))
    {
		$("errElem").innerHTML="The first name should be in alpha numeric characters (no spaces/special chars)";
		$("firstname").select();
		$("firstname").focus();
		return false;
	}
	if(!(isAlphaNumeric($("firstname").value)))
	{
		$("errElem").innerHTML="The first name should be in alpha numeric characters (no spaces/special chars)";
		$("firstname").select();
		$("firstname").focus();
		return false;
	}
	if ($("lastname").value == '')
	{
		$("errElem").innerHTML="Last name cannot be empty.";
		$("lastname").select();
		$("lastname").focus();
		return false;
	}
	if(isInteger($("lastname").value))
    {
		$("errElem").innerHTML="The last name should be in alpha numeric characters (no spaces/special chars)";
		$("lastname").select();
		$("lastname").focus();
		return false;
	}
	if(!(isAlphaNumeric($("lastname").value)))
	{
		$("errElem").innerHTML="The last name should be in alpha numeric characters (no spaces/special chars)";
		$("lastname").select();
		$("lastname").focus();
		return false;
	}
/*	if($('usrStep').value == 1)
	{
		if ($("password").value == '')
		{
			$("errElem").innerHTML="Password cannot be empty.";
			$("password").select();
			$("password").focus();
			return false;
		}
		if($("password").value.length<6)
		{
			$("errElem").innerHTML="Password should be minimum of 6 characters";
			$("password").select();
			$("password").focus();
			return false;
		}
	}
*/
}

function EnableEnterStateOption(chkBox)
{
	if(chkBox.checked)
	{
		$('selstate').disabled = true;
		$('enterState').disabled = false;
	}
	else
	{
		$('selstate').disabled = false;
		$('enterState').disabled = true;
	}
}

function validateVideoUploads()
{
	if(trim($('videoUpload').value).length > 0 && trim($('videoUrl').value).length > 7)
	{
		$('errElem').innerHTML = 'Invalid upload. Either provide the video URL or choose the video file.'; 
		return false;
	}
}

function displayImageUpload()
{
	if($('imageUploadRow').style.display == "") {
		$('imageUploadRow').style.display = "none";
	}
	else {
		$('imageUploadRow').style.display = "";
	}
}

function changePhoto(img)
{
	$('defPhoto').src = img.src;
	$('photoName').innerHTML = img.id;
	$('photoDesc').innerHTML = img.title;
}

function photoPagination(startRowNo)
{
	document.photoPaginate.startRow.value = startRowNo;
	document.photoPaginate.submit();
}

function ShoutOutAxn(axnType,shoutId)
{
	if(axnType == 1 && trim(document.shoutOut.txtShoutOut.value)=="") {
		document.getElementById('errorTd').innerHTML = 'Posting empty message is not allowed';
		return false;
	}
	document.shoutOut.shoutAxn.value = axnType;
	if(axnType == 2) {
		document.shoutOut.shoutOutId.value = shoutId;
	}
	document.shoutOut.submit();
}

/*function resizeHomePage()
{
	$('1stMainTd').width = "50%";
	$('3rdMainTd').width = "30%";
	$('univImage').style.width = "491";
	$('univImage').style.height = "246";
	$('2ndMainTd').width = "15%";
	$('2ndMainTd').style.display = "";
}*/

function homeForumSlide(status,forumCatId)
{
	
	if($('forumSlide') == null) return;

	if(status == 1)
	{
		//scrollOut();
		//$('forumSlide').style.display = "";
		//$('containerTable').width = "915";
		//$('3rdMainTd').width = "450";
		highlightForumCategory(forumCatId);
	}
	else
	{
		//$('forumSlide').style.display = "none";
		//$('containerTable').width = "740";
		//$('3rdMainTd').width = "240";
		normalizeForumCategory();
		//scrollIn();
	}
}

function scrollOut()
{
	clearTimeout(pid);
	if(this.expandLevel<1)
	{
		this.expandLevel=0;
	}
	var curMinWidth = parseInt($('forumSlide').style.width);
	if(curMinWidth < defaultMinDivWidth)
	{
		$('forumSlide').style.width = expandLevel + "px";
		if(parseInt($('forumSlide').style.width) > defaultMinDivWidth) {
			$('forumSlide').style.width = defaultMinDivWidth + "px";
		}
		expandLevel+=speed;
		pid=setTimeout('scrollOut()', 15);
	}
}

function scrollIn()
{
	clearTimeout(pid);
	if(this.expandLevel>defaultMinDivWidth)
	{
		this.expandLevel=defaultMinDivWidth;
	}
	if( expandLevel >= 0)
	{
		$('forumSlide').style.width = expandLevel + "px";
		if(parseInt($('forumSlide').style.width) <= 10) {
			$('forumSlide').style.display="none";
		}
		expandLevel-=speed;
		pid=setTimeout('scrollIn()', 15);
	}
}

function ValidateProfile()
{
	var errMsg = "";
	var stateIndex = $('selstate').options.selectedIndex;
	var stateName = "";
	var screenName = $('screenName').value;
	var myPosition = $('position').value;

	if(screenName.length<4){
		$("errorDiv").innerHTML ="Screen name should be of minimum four characters";
		$('screenName').focus();
		return false;
	}	

	if(myPosition.length > 25) {
		$("errorDiv").innerHTML = "please limit Position to 25 characters or less.";
		return false;
	}	 

	if(screenName.length > 14) {
		$("errorDiv").innerHTML = "please limit ScreenName to 14 characters or less.";
		return false;
	}	 

	if ($("email").value == '')
	{
		$("errorDiv").innerHTML="Email cannot be empty.";
		$("email").select();
		$("email").focus();
		return false;
	}
	try
	{
		emailCheck(trim($("email").value));
	}
	catch (e)
	{
		$("errorDiv").innerHTML=e.message;
		$("email").select();
		$("email").focus();
		return false;
	}	

	var mc = document.forms.userprofile.gender[0].checked;
	var fc = document.forms.userprofile.gender[1].checked;
	if(mc == false && fc == false){
		$("errorDiv").innerHTML = "please select a gender.";
		return false; 
	}

	if($('city').value == "-1") {
		errMsg = "please give the city name.";
		return false;
	}	 
	if($('country').value == "-1") {
		errMsg = "Invalid country selected.";
		return false;
	}
	if($('state').style.display == 'block' && $('selstate').value == "-1") {
		errMsg = "Invalid state selected.";
	}
	if($('state').style.display && $('enterState').value.match(/^[0-9]+$/)) {
		errMsg = "Invalid state name. State name should be in alphanumeric";
	}
	if(errMsg != "") {
		$('errorDiv').innerHTML = errMsg;
		return false;
	} else {
		$('errorDiv').innerHTML = "";
		$('stateName').value = ($('state').style.display == 'none')? $('enterState').value : $('selstate').options[stateIndex].text;
		return true;
	}
}

function updateStateNameField()
{
	var stateIndex = $('selstate').options.selectedIndex;
	$('stateName').value = ($('state').style.display == 'none')? $('enterState').value : $('selstate').options[stateIndex].text;
}

function changeClass(img)
{
	if(img.className != '') {
		img.className = '';
	} else {
		img.className = 'imgTransparentSixty';
	}
}

function changeForumHighlight(forumCatId,status)
{
	if(status == 'on')
	{
		highlightForumCategory(forumCatId);
	} 
	else
	{
		img.className = 'imgTransparentSixty';
	}
}

/*function highlightForumPostings(forumCatId)
{
	var forumPostingTable = $('forumPost');
	var rowLength = forumPostingTable.rows.length;
	for(j=0; j<rowLength; j++)
	{
		var tdId = forumPostingTable.getElementsByTagName("tr")[j].getElementsByTagName("td")[0].id;
		indexStr = "_" + forumCatId + "_";
		if(tdId.indexOf(indexStr) != -1) {
			$(tdId).className = "normalFieldText";
		}
	}
}

function normalizeForumPostings()
{
	var forumPostingTable = $('forumPost');
	var rowLength = forumPostingTable.rows.length;
	for(j=0; j<rowLength; j++)
	{
		tdId = forumPostingTable.getElementsByTagName("tr")[j].getElementsByTagName("td")[0].id;
		if($(tdId).className != '' && $(tdId).className != 'globalFont') {
			$(tdId).className = "globalFont";
		}
	}
}*/

function highlightForumCategory(forumCatId)
{
	catTable = $('forumCatTable');
	rowLen = catTable.rows.length;
	for(j=0; j<rowLen; j++)
	{
		anchorTag = catTable.getElementsByTagName('tr')[j].getElementsByTagName('td')[0].getElementsByTagName('a');
		if(anchorTag.length > 0)
		{
			imgId = anchorTag[0].getElementsByTagName('img')[0].id;
			anchorID = anchorTag[0].id;
			if(imgId == "forum_cat_" + forumCatId) {
				$(anchorID).className = 'forum_cat_anchor_on';
				$(imgId).className = '';
			} else {
				$(anchorID).className = 'forum_cat_anchor_off';
				$(imgId).className = 'imgTransparentSixty';
			}
		}
	}
}

function normalizeForumCategory()
{
	catTable = $('forumCatTable');
	rowLen = catTable.rows.length;
	for(j=0; j<rowLen; j++)
	{
		anchorTag = catTable.getElementsByTagName('tr')[j].getElementsByTagName('td')[0].getElementsByTagName('a');
		if(anchorTag.length > 0)
		{
			anchorID = anchorTag[0].id;
			imgId = anchorTag[0].getElementsByTagName('img')[0].id;
			$(anchorID).className = 'forum_cat_anchor_off';
			$(imgId).className = 'imgTransparentSixty';
		}
	}
}

//function scrollWidget(curDiv,axn)
//{
	//if(axn == 0)
	//{
		//if(YAHOO.util.Dom.isAncestor('widgetBox',YAHOO.util.Event.getTarget(e))) return;
		//timeout1 = setTimeout(hideWidgetContent1,2000);
		//timeout2 = setTimeout(hideWidgetContent2,2000);
	//}
 // return;
	//if(axn == 1)
	//{
		//if(curDiv == 1)
		//{
			//curDiv.className = "noBottomBorder";
			//$('upperDiv').style.display = "none";
			//$('lowerDiv').style.display = "";
			//$('horDiv').className = "innerdiv";
			//$('wthDiv').className = "innerdiv";
			//$('polDiv').className = "innerdiv";
			//$('contentDiv2').innerHTML = unescape(widgetMsg);
		//}
		//else if(curDiv == 2)
		//{
			//$('upperDiv').style.display = "none";
			//curDiv.className = "noBottomBorder";
			//$('msgDiv').className = "innerdiv";
			//$('wthDiv').className = "innerdiv";
			//$('polDiv').className = "innerdiv";
			//$('lowerDiv').style.display = "";
			//$('contentDiv2').innerHTML = unescape(widgetHor);
		//}
		//else if(curDiv == 3)
		//{
			//curDiv.className = "noBottomBorder";
			//$('msgDiv').className = "innerdiv";
			//$('horDiv').className = "innerdiv";
			//$('polDiv').className = "innerdiv";
			//$('lowerDiv').style.display = "none";
			//$('upperDiv').style.display = "";
			//$('contentDiv2').innerHTML = unescape(widgetWth);
		//}
		//else if(curDiv == 4)
		//{
			//curDiv.className = "noTopBorder";
			//$('msgDiv').className = "innerdiv";
			//$('horDiv').className = "innerdiv";
			//$('wthDiv').className = "innerdiv";
			//$('lowerDiv').style.display = "none";
			//$('upperDiv').style.display = "";
			//$('contentDiv2').innerHTML = unescape(widgetPol);
		//}
		//Slide('contentDiv1').down();
		//Slide('contentDiv2').down();
	//}
	//if(axn == 0)
	//{
		//if($('msgDiv') == null) return;
		//$('msgDiv').className = "innerdiv";
		//$('horDiv').className = "innerdiv";
		//$('wthDiv').className = "innerdiv";
		//$('polDiv').className = "innerdiv";
		//$('upperDiv').style.display = "";
		//$('lowerDiv').style.display = "none";
		//Slide('contentDiv2').up();
		//Slide('contentDiv1').up();
	//}
//}

function showPollResults(spanObj)
{
	if(spanObj.innerHTML == "results")
	{
		spanObj.innerHTML = "hide";
		$('pollInfo').style.display = "none";
		$('pollResults').style.display = "";
	}
	else if(spanObj.innerHTML == "hide")
	{
		spanObj.innerHTML = "results";
		$('pollInfo').style.display = "";
		$('pollResults').style.display = "none";
	}
}

function contactusValidation()
{
	if($("firstname").value=='')
	{
		$("errElem").innerHTML="FirstName cannot be empty.";
		$("firstname").select();
		$("firstname").focus();
		return false;
	}
	if($("email").value=='')
	{
		$("errElem").innerHTML="Email cannot be empty.";
		$("email").select();
		$("email").focus();
		return false;
	}
	try
	{
		emailCheck(trim($("email").value));
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("email").select();
		$("email").focus();
		return false;
	}	
	if($("subject").value=='')
	{
		$("errElem").innerHTML="Subject cannot be empty.";
		$("subject").select();
		$("subject").focus();
		return false;
	}
    if($("message").value=='')
	{
		$("errElem").innerHTML="Message cannot be empty.";
		$("message").select();
		$("message").focus();
		return false;
	}
}

function deleteSelectedRow(chosenRow)
{	
	if(confirm('Are you sure you want to delete this photo/video? If so, click OK.'))
		chosenRow.parentNode.deleteRow(chosenRow.rowIndex);
}

function swapRowUp(chosenRow)
{	
	if (chosenRow.rowIndex != 0)
	{
		moveRow(chosenRow, chosenRow.rowIndex-1);
	}
}

function swapRowDown(chosenRow)
{	
	if (chosenRow.rowIndex != chosenRow.parentNode.rows.length-1)
	{
		moveRow(chosenRow, chosenRow.rowIndex+1);
	}
}

function photoDeleteSelectedRow(chosenRow)
{	
	if(confirm('Are you sure you want to delete this photo/video? If so, click OK.'))
		document.getElementById('photo-' + chosenRow.rowIndex).value = '';
}

function photoSwapRowUp(chosenRow, photoId, up1, up2, down1, down2)
{
	if (chosenRow.rowIndex != 0)
	{
		var otherPhotoId = document.getElementById('photo-' + (chosenRow.rowIndex - 1)).value;
		if(chosenRow.rowIndex == chosenRow.parentNode.rows.length-1)
		{
			document.getElementById('downarrow-' + photoId).src = down1;
			document.getElementById('downarrow-' + otherPhotoId).src = down2;
		}
		if(chosenRow.rowIndex == 1)
		{
			document.getElementById('uparrow-' + photoId).src = up2;
			document.getElementById('uparrow-' + otherPhotoId).src = up1;
		}
		document.getElementById('photo-' + (chosenRow.rowIndex - 1)).value = photoId;
		document.getElementById('photo-' + chosenRow.rowIndex).value = otherPhotoId;
		moveRow(chosenRow, chosenRow.rowIndex-1);
	}
}

function photoSwapRowDown(chosenRow, photoId, up1, up2, down1, down2)
{
	if (chosenRow.rowIndex != chosenRow.parentNode.rows.length-1)
	{
		var otherPhotoId = document.getElementById('photo-' + (chosenRow.rowIndex + 1)).value;
		if(chosenRow.rowIndex == 0)
		{
			document.getElementById('uparrow-' + photoId).src = up1;
			document.getElementById('uparrow-' + otherPhotoId).src = up2;
		}
		if(chosenRow.rowIndex == chosenRow.parentNode.rows.length-2)
		{
			document.getElementById('downarrow-' + photoId).src = down2;
			document.getElementById('downarrow-' + otherPhotoId).src = down1;
		}
		document.getElementById('photo-' + (chosenRow.rowIndex + 1)).value = photoId;
		document.getElementById('photo-' + chosenRow.rowIndex).value = otherPhotoId;
		moveRow(chosenRow, chosenRow.rowIndex+1);
	}
}

function moveRow(targetRow, newIndex)
{
	if (newIndex > targetRow.rowIndex)
	{
		newIndex++;
	}

	var theCopiedRow = targetRow.parentNode.insertRow(newIndex);
	for (var i=0; i<targetRow.cells.length; i++)
	{
		var oldCell = targetRow.cells[i];
		var newCell = document.createElement("TD");
		newCell.innerHTML = oldCell.innerHTML;
		newCell.className = 'globalFont';
		newCell.align = oldCell.align;
		theCopiedRow.appendChild(newCell);
	}
	targetRow.parentNode.deleteRow(targetRow.rowIndex);
}

function validateForgetPwd()
{
	if(trim($('email').value)=='')
	{
		$('errElem').innerHTML='Email cannot be empty';
		$("email").select();
		$("email").focus();
		return false;
	}
	try
	{
		emailCheck(trim($("email").value));
	}
	catch (e)
	{
		$("errElem").innerHTML=e.message;
		$("email").select();
		$("email").focus();
		return false;
	}	
}

function resetPassword()
{
	if(addUserValidation() != false)
	{
		$('usrStep').value = 1;
		document.adduser.submit();
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
