function sendData()
{
		var values=new Array();
		values[0]={name: "isin",value: document.getElementById("isinsValues").value};
		sendHttpRequest("POST",'NewsletterSaveIssin.php',values,putInPage);
	
}
function SaveNewsletterSettings()
{
		var values=new Array();
		var checked
		if(document.getElementById("general").checked==true)
			checked='on';
		else
			checked='off';		  
		values[0]={name: "general",value: checked};
		sendHttpRequest("POST",'NewsLetterSaveSettings.php',values,AfterSaveNewsletterSettings);
	
}
function AfterSaveNewsletterSettings()
{
}
function PrepareData(control)
{
	var refIsinValues=document.getElementById("isinsValues");	
    var formInputs = document.getElementsByTagName('input');
    refIsinValues.value="";
    for (var i = 0; i < formInputs.length; i++) 
    {
        var theInput = formInputs[i];
        if(theInput.type == 'checkbox')
        {
        	if(theInput.checked)
        		if(refIsinValues.value.length==0)
        			refIsinValues.value=theInput.id;
        		else
        			refIsinValues.value+="," + theInput.id;        	        		
        }
        
    }
}
function putInPage(xmlHttp)
{
	document.getElementById("mainContent").innerHTML=xmlHttp.responseText;	
	floatDivClose();
}
function showSearchResults()
{
	var values=new Array();
	values[0]={name: "search",value: document.getElementById("isinText").value};
	var refSearchArea=document.getElementById("SearchArea");
	refSearchArea.innerHTML='<img alt="Searching..." src="images/loading.gif">';
	sendHttpRequest("POST",'SearchIsinTable.php',values,postSearchResults);
}
function postSearchResults(xmlHttp)
{
	var refSearchArea=document.getElementById("SearchArea");
	refSearchArea.innerHTML=xmlHttp.responseText;//html;
}
function postShowFloatDiv(xmlHttp)
{
var refInformationArea=document.getElementById("informationArea");
	refInformationArea.innerHTML=xmlHttp.responseText;//html;
}
function showFloatDiv(values,url,e,Cx,Cy)
{
	var x=y=0;
    if(Cx && Cy)
    {
    	x=Cx;
    	y=Cy;
    }
    else
    {
	    if (e && e != '') {
	        x = document.body.scrollLeft+e.clientX + 20 ;
	        y = document.body.scrollTop+e.clientY-10;
	    }
	    
	  // test if div go out from screen, if so put div an left side
	    if( (x + 300)>document.body.clientWidth)
	    {
	    x=x-320;
	    }
    }
//var refIframe=document.getElementById("floatIframe");
var refDiv=document.getElementById("floatDiv");
//	refIframe.style.top=y;
//	refIframe.style.left=x;
	
	refDiv.style.top=y;
	refDiv.style.left=x;
	refDiv.style.display=""
//	refIframe.style.display= "";
var refInformationArea=document.getElementById("informationArea");
	refInformationArea.innerHTML='<img alt="Loading..." src="images/loading.gif">';
sendHttpRequest("POST",url,values,postShowFloatDiv);
}

function postShowFloatDiv(xmlHttp)
{
var refInformationArea=document.getElementById("informationArea");
	refInformationArea.innerHTML=xmlHttp.responseText;//html;

var refDiv=document.getElementById("floatDiv");	
	var x=refDiv.offsetLeft;
	var y=refDiv.offsetTop;
	// test if div go out from screen
	    if( (x + refDiv.offsetWidth)>document.body.clientWidth)
	    {
	    	x=x-refDiv.offsetWidth;
//			refIframe.style.left=x;
			refDiv.style.left=x;	    	
	    }
}

function showLoadDiv(e,Cx,Cy)
{
		var x=y=0;
    if(Cx && Cy)
    {
    	x=Cx;
    	y=Cy;
    }
    else
    {
	    if (e && e != '') {
	        x = document.body.scrollLeft+e.clientX + 20 ;
	        y = document.body.scrollTop+e.clientY-10;
	    }
	  // test if div go out from screen, if so put div an left side
	    if( (x + 300)>document.body.clientWidth)
	    {
	    x=x-320;
	    }
    }
var refDiv=document.getElementById("floatDiv");
	refDiv.style.top=y;
	refDiv.style.left=x;
	refDiv.style.display="";
var refInformationArea=document.getElementById("informationArea");
	refInformationArea.innerHTML='<img alt="Loading..." src="images/loading.gif">';
}

function floatDivClose()
{
try{
	divClosing();
}catch(e){};
//var refIframe=document.getElementById("floatIframe");
var refDiv=document.getElementById("floatDiv");
//	refIframe.style.display= "none";
	refDiv.style.display = "none";
var refInformationArea=document.getElementById("informationArea");
	refInformationArea.innerHTML='<img alt="Loading..." src="images/loading.gif">';
//	refIframe=null;
	refDiv=null;
	refInformationArea=null;
}
var down=false;
var objMouseX=0;
var objMouseY=0;

function mouseDown(e)
{
	var refDiv=document.getElementById("floatDiv"); 		
	var x=document.body.scrollLeft+e.clientX;
	var y=document.body.scrollTop+e.clientY;
	objMouseX=(x-refDiv.style.left.substring(0,refDiv.style.left.length-2));
	objMouseY=(y-refDiv.style.top.substring(0,refDiv.style.top.length-2));
	down=true;
	refDiv=null;
}

function mouseUp(e)
{
	down=false;
}

if(navigator.appName=="Microsoft Internet Explorer")
{
document.getElementById("mainBody").attachEvent("onmousemove",function(){mouseMove(event);});
}
else
{
document.getElementById("mainBody").onmousemove=function(event){mouseMove(event);};
}


function mouseMove(e)
{
	var x=0;
	var y=0;
	if (e && e != '') 
	{
		x=document.body.scrollLeft+e.clientX;
		y=document.body.scrollTop+e.clientY;
		var refDiv=document.getElementById("floatDiv");
		x=x-objMouseX;
		y=y-objMouseY;
		refDiv=null;
	}
	if(down)
	{
//		var refIframe=document.getElementById("floatIframe");
		var refDiv=document.getElementById("floatDiv");
//		refIframe.style.top=y;
//		refIframe.style.left=x;
		refDiv.style.top=y;
		refDiv.style.left=x;
		refDiv.style.display=""
//		refIframe.style.display= "";
//		refIframe=null;
		refDiv=null;
	}
}

function btnclick(e)
{
var values=new Array();
values[0]={name: "test",value: 1};
showFloatDiv(values,"NewsletterAddIssin.php",e,document.body.clientWidth/2-200,document.body.clientHeight/2-200);
}

function divClosing()
{

}
function CheckEmail(src)
{
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(src);
}
function DoSubscribe()
{
	if (!CheckEmail(document.subscribe.email.value)) 
	{
			alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
			document.subscribe.email.focus();
			return false;
	}
	result1="";
	if(document.getElementById("isin0")===null)
	{
		checkbox_nr=document.getElementById("productscount").value;
		for (i=0;i<=checkbox_nr;i++)
		{
			a=document.getElementById("product"+i)
			if(a!=null)
				if(a.checked==true)
					result1=a.checked;
		}
		if (result1==false)
		{ 
			alert ("Bitte wählen Sie mindestens ein Produkt aus.");
			return false;
		}
	}				
	if (!document.subscribe.password1.value)
	{
		alert("Bitte geben Sie ein Passwort ein, da Sie sonst Ihre Daten zukünftig nicht ändern können.");
		document.subscribe.password1.focus();
		return false;
	}
	if (document.subscribe.password1.value!=document.subscribe.password2.value)
	{
		alert("Die Passwörter stimmen nicht überein. Bitte geben Sie sie erneut ein.");
		document.subscribe.password1.focus();
		return false;
	}
	if (document.subscribe.password1.value.length<3)
	{
		alert("Das Passwort ist zu kurz. Es muss mindestens drei (3) Zeichen haben.");
		document.subscribe.password1.focus();
		return false;
	}
	document.subscribe.submit();
}
function AdminSubscribe()
{
	if(!document.getElementById('delete').checked)
	{
		if (!CheckEmail(document.subscribe.email.value)) 
		{
				alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
				document.subscribe.email.focus();
				return false;
		}
		if(document.subscribe.password1.value.length>0)
		{
			if (!document.subscribe.password1.value)
			{
				alert("Bitte geben Sie ein Passwort ein, da Sie sonst Ihre Daten zukünftig nicht ändern können.");
				document.subscribe.password1.focus();
				return false;
			}
			if (document.subscribe.password1.value!=document.subscribe.password2.value)
			{
				alert("Die Passwörter stimmen nicht überein. Bitte geben Sie sie erneut ein.");
				document.subscribe.password1.focus();
				return false;
			}
			if (document.subscribe.password1.value.length<3)
			{
				alert("Das Passwort ist zu kurz. Es muss mindestens drei (3) Zeichen haben.");
				document.subscribe.password1.focus();
				return false;
			}			
		}
	}
	else
	{
		var result=confirm("Sind Sie sicher, dass Sie Ihren Account löschen wollen?")
		if(!result)
			return false;				
	}
	document.subscribe.submit();
}			
function ActivateAccount()
{
	if(!document.getElementById("activate").checked)
		alert("Sie erhalten in Zukunft keine Emails/Benachrichtigungen mehr von BoersenKiosk.de");
	document.subscribe.submit();
}
function AccountNotActive()
{
	alert("Ihr Benutzerkonto ist nicht aktiviert. Bitte aktivieren Sie es unter 'Administration', so dass Sie Emails/Benachrichtigungen erhalten können.");
}
function SelectCountry()
{	
	if( document.getElementById("selectionCombo")!=null)
		document.getElementById("country").selectedIndex = document.getElementById("selectionCombo").value;
}

function isISINValid(ISIN) {
	// Format check
	if (!/^[A-Z]{2}[A-Z0-9]{9}[0-9]{1}$/.test(ISIN))
		return false;
	
	// ISO 10383
	// The 2 first characters can be checked 
	var countryCode = new Array(
	"AE","AL","AM","AR","AT","AU","AZ","BA","BB","BD","BE","BG","BH","BM","BO","BR","BS","BW","BY",
	"CA","CH","CI","CL","CN","CO","CR","CV","CY","CZ","DE","DK","DO","DZ","EC","EE","EG","ES",
	"FI","FJ","FR","GB","GE","GG","GH","GR","GT","HK","HN","HR","HU",
	"ID","IE","IL","IN","IQ","IR","IS","IT","JM","JO","JP","KE","KG","KN","KR","KW","KY","KZ",
	"LB","LK","LT","LU","LV","MA","MD","ME","MG","MK","MN","MT","MU","MW","MX","MY","MZ",
	"NA","NG","NI","NL","NO","NP","NZ","OM","PA","PE","PG","PH","PK","PL","PS","PT","PY","QA",
	"RO","RS","RU","SA","SD","SE","SG","SI","SK","SV","SZ","TH","TN","TR","TT","TW","TZ",
	"UA","UG","US","UY","UZ","VE","VN","WS","ZA","ZM","ZW","ZZ"
	);	
	var isinCountryCode = ISIN.charAt(0) + ISIN.charAt(1);
	var bCountryCode=false;
	var isinNumber=new String();;
	for(var i=0; i<countryCode.length; i++){
        if(countryCode[i] == isinCountryCode){
            bCountryCode=true;
           	break;
        }
    }
  if(!bCountryCode)
  	return false;
  	
	// ISO 6166
	// Step 1: Alphabetic characters are assigned the numeric values A=10 ... Z=35
	for(var i=0; i <11; i++) 
	{
  		if(ISIN.charCodeAt(i)<59) 
	  		isinNumber += ISIN.charCodeAt(i)-48; // '0'=0 ... '9'=9  	 
  		else   	
  			isinNumber += ISIN.charCodeAt(i)-55; // 'A'=10 ... 'Z'=35
  	}
	// Step 2: Double the value of alternate digits beginning with the first right-hand digit (low order), including zeros
	// Step 3: Add the individual digits composing the products obtained in step 2 and each of the unaffected digits in the original number
	//         collect odd and even and set the group for the first right-hand digit
	var oddChar = "";
	var evenChar = "";
	var group = 0;
	for(var i=0; i<isinNumber.length ; i++) {
		if(i%2) {
			evenChar += isinNumber.charAt(i);
			group = 1;
		} else {
			oddChar += isinNumber.charAt(i);
			group = 2;
		}
	}
	// double the value of the first right-hand digit		
	var total = 0;
	if(group==2) {
		// multiply oddChar by 2
		var oddChar2 = "";
		for(var i=0; i<oddChar.length ; i++) {
			oddChar2 += ((oddChar.charCodeAt(i)-48)*2);
		}
		// and add each char
		for(var i=0; i<oddChar2.length ; i++) {
			total += (oddChar2.charCodeAt(i)-48);
		}
		for(var i=0; i<evenChar.length ; i++) {
			total += (evenChar.charCodeAt(i)-48);
		}
	} else {
		// multiply evenChar by 2
		var evenChar2 = "";
		for(var i=0; i<evenChar.length ; i++) {
			evenChar2 += ((evenChar.charCodeAt(i)-48)*2);
		}
		for(var i=0; i<evenChar2.length ; i++) {
			total += (evenChar2.charCodeAt(i)-48);
		}
		for(var i=0; i<oddChar.length ; i++) {
			total += (oddChar.charCodeAt(i)-48);
		}
	}
		
	/* Step 4: Subtract the total obtained in step 3 from the next higher number ending in 0 [this is the equivalent of calculating
	           the "tens complements" of the low order digit (unit digit) of the total]. If the total obtained in step 3 is a number
	           ending in zero (30, 40, etc.), the check digit is 0.
	*/
	var checksum = (10 - (total%10))%10;
	// make the check
	if((ISIN.charCodeAt(11)-48)!=checksum) {
		return false;
	}
	return true;
}
function validateISIN(obj)
{
	var tISIN=obj.value;
	if(tISIN.length<1)
	  	return false;
	  	// Format check
    if (/^[A-Z]{2}[A-Z0-9]{9}[0-9]{1}$/.test(tISIN)) 
    { 
    	if(isISINValid(tISIN)) 
    	{
			return true;
		} 
		else 
		{
			alert('Invalid ISIN Checksum. Please correct.');
	 	}
	 } 
	 else 
	 {
	 		alert('Invalid ISIN Format (XX?????????9). Please correct.');
 	 }    
	objID = obj.id;
    setTimeout("document.getElementById(objID).focus();",1);
	setTimeout("document.getElementById(objID).select();",1);
    return false;
}
		