// Validator Used on ChooseUser.asp
function Username_Validator(theForm)
{
/*
  if (theForm.username.value == "")
  {
    alert("Please enter a value for the \"User Name\" field.");
    theForm.username.focus();
    return (false);
  }

  if (theForm.username.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"User Name\" field.");
    theForm.username.focus();
    return (false);
  }

  if (theForm.username.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"User Name\" field.");
    theForm.username.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
  var checkStr = theForm.username.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and digit characters in the \"User Name\" field.");
    theForm.username.focus();
    return (false);
  }
*/
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";	
  if (theForm.password.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.password.focus();
    return (false);
  }

  if (theForm.password.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Password\" field.");
    theForm.password.focus();
    return (false);
  }

  if (theForm.password.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Password\" field.");
    theForm.password.focus();
    return (false);
  }

  
  var checkStr = theForm.password.value;
  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }

  }
  if (!allValid)
  {
    alert("Please enter only letter and digit characters in the \"Password\" field.");
    theForm.password.focus();
    return (false);
  }


  if (theForm.confirmpass.value == "")
  {
    alert("Please enter a value for the \"Confirm Password\" field.");
    theForm.confirmpass.focus();
    return (false);
  }

  if (theForm.confirmpass.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Confirm Password\" field.");
    theForm.confirmpass.focus();
    return (false);
  }

  if (theForm.confirmpass.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Confirm Password\" field.");
    theForm.confirmpass.focus();
    return (false);
  }

  if (theForm.confirmpass.value != theForm.password.value )
    {
      alert("Please re-enter your password correctly.");
      theForm.confirmpass.focus();
      return (false);
  }

  
  var checkStr = theForm.confirmpass.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and digit characters in the \"Confirm Password\" field.");
    theForm.confirmpass.focus();
    return (false);
  }

	  return (true);
}

// Email Validator
function Validate_Email(theForm)
{


  if (theForm.email.value == "")
  {
    alert("Please enter a value for the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
  var checkStr = theForm.email.value;
  var allValid = true;
  var bDotPresent = false;
  var bRatePresent = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      	break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }

    if (j == checkOK.length - 1  )
	    {
	    	bDotPresent = true;

	    }

	    if (j == checkOK.length -2 )
	    {
	    	bRatePresent = true;
	    }

  }

  if (!allValid)
  {
    alert("Please enter only letter, digit and \"-_@.\" characters in the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  if ((!bDotPresent) || (!bRatePresent) )

    {
    	alert ("Please enter a valid email address");
    	theForm.email.focus();
    	return(false);
    }

	  return (true);
}

// Open PopUp Window
function openPopUp (winURL, winName, winFeatures){
	newWindow = window.open(winURL,winName,winFeatures);
	newWindow.focus();
}

// New Gallery Window
function newGalleryWindow(galleryURL, galleryWinName, galleryFeatures){
	window.open(galleryURL, galleryWinName, galleryFeatures);
}

// Display WIndow
function displayWindow (url, width, height){
		var Win = window.open (url,"displayWindow",'width=' + width + ',height=' +
		height + ',resizable=0,scrollbars=no,menubar=no,status=yes');
		Win.focus();
}

// Form Validator
function validateIt(theForm)
 {
  if(theForm.categoryid.value != '')
	{
	theForm.submit()
	}
  else
     	{
     	return false
     	}
 }

// Clear Text
function doClear(theText) {
	if (theText.value == theText.defaultValue) {
	  theText.value = ""
	}
}

// Change Password (I think)
function password(){
	self.name = "Parent_Window"; 
	window.open('/portal/user/send_pass.asp','EmailLoginInfo','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=350,height=260');
}

// Button Over and Active states for IE

//startList = function() {
	//if (document.all&&document.getElementById) {
		// alert("function triggered");
		//inputArray = document.getElementsByTagName("Input");
		//for (i=0; i<inputArray.length; i++) {
			// alert("inside loop");
			//node = inputArray[i];
			//if (node.className=="button") {
				//node.onmouseover=function() {
					//this.className+=" over";
					// alert("if triggered");
				//}
				//node.onmousedown=function() {
					//this.className=this.className.replace(" over", " active");
				//}
				//node.onmouseout=function() {
					//this.className=this.className.replace(" over", "");
					//this.className=this.className.replace(" active", "");
				//}
			//}
		//}
	//}
//}
//window.onload=startList;

// Table row Over state for IE

startList = function() {
	if (document.all&&document.getElementById) {
		//alert("function triggered");
		inputArray = document.getElementsByTagName("TR");
		for (i=0; i<inputArray.length; i++) {
			// alert("inside loop");
			node = inputArray[i];
			if (node.className=="Row") {
				node.onmouseover=function() {
					this.className+=" over";
					// alert("if triggered");
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
			if (node.className=="altRow") {
				node.onmouseover=function() {
					this.className+=" altOver";
					// alert("if triggered");
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" altOver", "");
				}
			}
		}
	}
}
window.onload=startList;

// My Account Display Function

function hideDivs(exempt)
{
  	if (!document.getElementsByTagName) {
  		return null;
  	}
    if (!exempt) exempt = "";
	var divs =
    	document.getElementsByTagName("div");
    	for(var i=0; i < divs.length; i++)
    	{
		node = divs[i];
		if (node.className=="profile") {
			var div = divs[i];
			var id = div.id;
			if ((id != "main") &&
				(id != exempt))
			{
				div.className = "hidden";
			}
		}
    }
}
function fixLinks()
{
	if (!document.getElementsByTagName) {
		return null;
	}
	var anchors =
		document.getElementsByTagName("a");
	for(var i=0; i < anchors.length; i++)
	{
		var a = anchors[i];
		var href = a.href;
		if (href.indexOf("#masthead") != -1) {
			a.className = "hidden";
		} else if ((href.indexOf("#") != -1) &&
		  (href.indexOf("header") == -1))
		{
			var index = href.indexOf("#") + 1;
			href = "javascript:show('" +
				href.substring(index) + "');";
			a.setAttribute("href",href);
		}
	}
}  
function show(what)
{
	if (!document.getElementById) {
		return null;
	}
	showWhat =
		document.getElementById(what);
	showWhat.className = "profile";	
	hideDivs(what);
	
}

function openWin_flashplayer (){
	var Win = window.open ('/portal/player/flash_player.asp','displayWindow','width=350,height=155,resizable=0,scrollbars=no,menubar=no,status=yes'); 
	Win.focus();
}

function openInviteAFriend(winname, wintitle)
{					
	var win = window.open(winname,wintitle,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=740,height=380');
	//win.focus();
}

function RateReview_RateReview_Validate(objForm)
{
    var blnOutReturnVal;
	var blnInReturnVal;	
	blnOutReturnVal = RateReview_TextCheck(objForm.description, "Comments");
	if (blnOutReturnVal)
	{		
		
		blnInReturnVal = RateReview_RadioCheck(objForm, "rate");
			if (blnInReturnVal)	
			{
				return true;
			}
			else
			{
				return false;		
			}
	}
	else
	{
		return false;
	}
}
	

function RateReview_TextCheck(objTextBox, objName)
{
	if (objTextBox.value == "")
	{
		alert("Please enter your " + objName )
		return false;
	}  
	else
	{
		return true;
	}
}
	
	
function RateReview_RadioCheck(objForm, objName)
{	
	
	var i=0;
	var obj;
	var intCheckCount=0;
	
	for (i=0;i<objForm.elements.length;i++)
	{
		obj = objForm.elements[i];
		if ((obj.type == "radio") && (obj.checked))
		{
			intCheckCount++;
		}		
	}
	
	if (intCheckCount>0)
	{
		return true;
	}
	else
	{
		alert("Please " + objName + " this post.");
		return false;
	}	
}
function ValidateBlog(objForm)
{
	if(objForm.description.value=="")
	{
		alert("Description should not blank");	
		objForm.description.focus();
		return false;
	}
	else
	{
		return true;
	}

}

function ValidateBlogComment(objForm)
{
	
	if(trimString(objForm.strTitle.value)=="")
	{
		alert("Title should not blank");	
		objForm.strTitle.focus();
		return false;
	}
	if(trimString(objForm.description.value)=="")
		{
			alert("Description should not blank");	
			objForm.description.focus();
			return false;
	}
	return true;
	

}
function trimString(str)
{ 
	return str.replace(/^\s+/,'').replace(/\s+$/,'');
}