//common.js -------------

function submitSearch()
		{
			//archive or stock or etf
			var i = 0;
			var searchType = '';
			for(i=0; i<3; i++)
			{
				if(document.multiSearch.searchType[i].checked)
				{
					searchType = document.multiSearch.searchType[i].value;
					break;
				}
			}
			
			var q = document.multiSearch.q.value;
			var crit = document.multiSearch.q.value;
			if (searchType == "stock")
			{
				document.multiSearch.action = 'http://app.quotemedia.com/quotetools/clientForward';
				document.multiSearch.symbol.value = q;
				document.multiSearch.category.value = 'STOCKLOOKUP';
			}
			else if(searchType == "etf")
			{
				document.multiSearch.action = '/apps/pbcs.dll/section';
				document.multiSearch.category.value = 'ETFLOOKUP';
			}
			else
			{
				document.multiSearch.action = '/apps/pbcs.dll/SEARCH';
				document.multiSearch.crit.value = q;
				document.multiSearch.category.value = 'ADVANCEDSEARCH';
			}
			
			return true;				
		}
		
		function handleAdvancedSearch()
		{
			if (document.advancedsearch.search_type[2].checked)
			{
				document.advancedsearch.q.value='"' + document.advancedsearch.q.value + '"';
			}
			else if (document.advancedsearch.search_type[1].checked)
			{			
				var tstring = "";
				tstring = document.advancedsearch.q.value;
				var splitstring = tstring.split(" ");
				if(splitstring.length > 1)
				{
					for(i = 0; i < splitstring.length; i++)
					{
						tstring += splitstring[i] + ' +';
					}
				}
				
				document.advancedsearch.q.value='+' + tstring;
			}
			else if (document.advancedsearch.search_type[0].checked)
			{
				//do nothing because or is automatic
			}
			
			return true;
		}


		
//--------------------------------------------------

//functions.js
function NewWindow(width,height,url) {
	window.open(url,"PopUp","menubars=0,scrollbars=1,resizable=1,height="+height+",width="+width);
}

function CheckInputData(frm) {
 var skip = false;
 var hobbyselected = false;
 if (!skip && frm.email.value == "") {
 	alert("E-Mail address is required");
 	skip = true;
 }
 
 
 if (!skip && frm.pwd.value =="") {
 	alert("Password is required");
 	skip = true;
 }

 if (!skip && (frm.pwd.value != frm.pwdr.value) ) {
 	alert("Passwords do not match.");
 	skip = true;
 }
  
 if (!skip) {
        InitCookieSearchParams(frm);
 	pbsSetCookie(frm);
 	
 	}
 return (!skip);
}



function choosedate () {
 window.open('/g/kalender_eng.html?searchform.dateselected','','menubar=0,titlebar=0,width=268,height=236');
 document.searchform.Interval.options[document.searchform.Interval.options.length-1].selected = true;
}
function ResetDate () {
 if (document.searchform.Interval.selectedIndex != (document.searchform.Interval.options.length-1))
 {
  document.searchform.dateselected.value = "";
 }
}

function DoPrint () {
 var f = document.searchform;
 f.action = "events?category=print";
 f.submit();
}

function EatTheCookie() {
document.cookie="usernamepassword=;Path=/"
document.cookie="UserRegID=;Path=/"
document.location="/apps/pbcs.dll/news_groups?Category=&ThemeID=2324&RegLogout=1&NoCache=1"
}
//-------------------------------------------------------------------------------------------

//javascripts.js
function Go(url) {
 newurl = url;
 q = window.location.search.substr(1).toLowerCase().split("&");
 for (i=0; i<q.length; i++) {
  if (q[i].substr(0,9) == "expnodes=") {
   newurl += "&"+q[i];
   break;
  }
 }
 window.location = newurl;
}

function NewWindow(bredde,hoyde,url) {
 window.open(url,"ShowProdWindow","menubars=0,scrollbars=1,resizable=1,height="+hoyde+",width="+bredde);
}
function tipVen(bredde,hoyde,url,thisScrollbars,thisResize) {
		window.open(url,"ShowProdWindow","menubars=0,scrollbars="+thisScrollbars+",resizable="+thisResize+",height="+hoyde+",width="+bredde);
}
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return 999
}

function launchCenteredWin(url, name, width, height, otherfeatures)
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',' + otherfeatures);
  if(parseInt(navigator.appVersion) >= 4)
  {
	//delay a bit here because IE4 encounters errors
	//when trying to focus a recently opened window
 	setTimeout('newwin.focus();',250);
  }
}
function getManganFlashUrl()
{
	if (getQueryVariable("getmenu") == 999)
	{
		var flashUrl = "flash_content.html"
	}else
	{
		var flashUrl = "flash_content.html?getmenu=" + getQueryVariable("getmenu")
	}
}

function openLynxWindow(PageURL){
  WindowName="3f";
  settings="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=768,height=636";
  MyNewWindow=window.open(PageURL,WindowName,settings);
}
//--------------------------------------------------------------------------------

//Validate Forum Post form
function checkPostform() 
	{
		Msg = "";
		var errorMsg = 'Email address is invalid';
		
		var name = document.Postform.name.value;
		var Body = document.Postform.Body.value;
		
	 	
	 	if (name == '') 	 	
			 Msg += '  Your Name is missing !!! \n' ;
			 
		if (Body =='') 	
			  Msg += '  Your Message is missing !!! \n' ;
	 	
	
		 if (Msg != '')                                   //--- if there are errors
    { 
        alert('Please correct the following:      \n' + 
              '---------------------------------- \n' + Msg);
	return(false);
    }
		
			
	 	else
	 	{
				return true;
	 	}
	}
	

//Validate Forum Report Abuse form
function checkAbuseform() 
	{
		Msg = "";
		var errorMsg = 'Email address is invalid';
		
		var fname = document.Abuseform.fname.value;
		var lname = document.Abuseform.lname.value;
		var email = document.Abuseform.email.value;
		var message = document.Abuseform.message.value;
			 	
	 	if (fname == '') 	 	
			 Msg += '  Your First Name is missing !!! \n' ;
			 
		if (lname =='') 	
			  Msg += '  Your Last Name is missing !!! \n' ;
		
		if (email =='') 	 	
			 Msg += '  Your Email is missing !!! \n' ;
			
		if (message =='Dear Editor:') 	
			  Msg += '  Your Message is missing !!! \n' ;
			 
				 
		 if (Msg != '')                                   //--- if there are errors
    { 
        alert('Please correct the following:      \n' + 
              '---------------------------------- \n' + Msg);
	return(false);
    }
		
	else if(!validateEmail(email, errorMsg))
	 	{
	 		return false;
	 	}
	 	else
	 	{
			return true;
	 	}
	}
	


//Validate Forum Registration form
function checkRegisterform() 
	{
		Msg = "";
		var errorMsg = 'Email address is invalid';
		
		var fname = document.Registerform.fname.value;
		var lname = document.Registerform.lname.value;
		var email = document.Registerform.email.value;
		var NickName = document.Registerform.NickName.value;
		var pwd = document.Registerform.pwd.value;
		var pwdr = document.Registerform.pwdr.value;
	 	
	 	if (fname == '') 	 	
			 Msg += '  Your First Name is missing !!! \n' ;
			 
		if (lname =='') 	
			  Msg += '  Your Last Name is missing !!! \n' ;
		
		if (email =='') 	 	
			 Msg += '  Your Email is missing !!! \n' ;
			 
		if (NickName =='') 	 	
			 Msg += '  Your User ID is missing !!! \n' ;
				
		if (pwd =='') 	 	
			 Msg += '  Your Password is missing !!! \n' ;
	 	
		if (pwdr =='') 	 	
			 Msg += '  Confirm your Password !!! \n' ;
			 
			 
		 if (Msg != '')                                   //--- if there are errors
    { 
        alert('Please correct the following:      \n' + 
              '---------------------------------- \n' + Msg);
	return(false);
    }
		
	else if (pwd != pwdr) 
			{
			alert(' Invalid password confirmation ');
			return(false);
			}
			
	else if(!validateEmail(email, errorMsg))
	 	{
	 		return false;
	 	}
	 	else
	 	{
			return true;
	 	}
	}
	
function validateAskform() {
	
		Msg = "";
		var errorMsg = 'Email address is invalid';
		
		var message = document.Askform.message.value;
		var name = document.Askform.name.value;
		var company = document.Askform.company.value;
		var email = document.Askform.email.value;
		var phone = document.Askform.phone.value;
			 	
	 	if (message == '') 	 	
			 Msg += '  Your Question is missing !!! \n' ;
			 
		if (name =='') 	
			  Msg += '  Your Name is missing !!! \n' ;
		
		if (company =='') 	 	
			 Msg += '  Your Company is missing !!! \n' ;
			
		if (email =='') 	 	
			 Msg += '  Your Email is missing !!! \n' ;
		
		if (phone =='') 	 	
			 Msg += '  Your Phone is missing !!! \n' ;
			 
				 
		 if (Msg != '')                                   //--- if there are errors
    { 
        alert('Please correct the following:      \n' + 
              '---------------------------------- \n' + Msg);
	return(false);
    }
		
	else if(!validateEmail(email, errorMsg))
	 	{
	 		return false;
	 	}
	 	else
	 	{
			return true;
	 	}
	}


function validateEmail ( emailField, errorMsg ) 
	{
 		emailField = trim(emailField);
		//alert("start" + emailField + "end");
		emailpart =/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
				
 		if( !validEmail( emailField ) ) 
 		{
  			alert( errorMsg);
  			return false;
 		}
 		
 		return true;
	}
		
function validEmail(emailField)
	{
		invalidChars = " /:,;"	
		//if (emailField == "") {
			//return false
		//}
		for (i=0; i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i)
			if (emailField.indexOf(badChar,0) > -1) {
				return false
			}
		}
		atPos = emailField.indexOf("@",1)
		if (atPos == -1) {
			return false
		}
		if (emailField.indexOf("@",atPos+1) > -1) {
			return false
		}
		periodPos = emailField.indexOf(".",atPos)
		if (periodPos == -1) {
			return false
		}
		if (periodPos+3 > emailField.length)	{
			return false
		}
		return true
	}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }   
   
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return 
}

