﻿function OpenWindowInMiddle( theURL, winName, width, height ) { //v3.0
	var top = screen.height/2 - height/2;
	var left = screen.width/2 - width/2;
	window.open(theURL,winName, 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left );
}


/*******************************
	Opnar Mynd í pop up glugga		
	í miðju skjásin
		
*******************************/
function openPictureWindowInMiddle(imageType,imageName,imageWidth,imageHeight,alt) {
	var top = screen.height/2 - imageHeight/2;
	var left = screen.width/2 - imageWidth/2;

	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+left+",top="+top);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	if (imageType == "swf"){
	newWindow.document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
	newWindow.document.write('<param name=movie value=\"'+imageName+'\"><param name=quality value=high>');
	newWindow.document.write('<embed src=\"'+imageName+'\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
	newWindow.document.write('</embed></object>');	}else{
	newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">'); 	}
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}


function MSOTlPn_ShowListFilter(Id)
{
	alert(Id);
	if (document.all['WebPartListFilter'].style.display == 'none')
	{
		document.all['WebPartListFilter'].style.display = 'block'; 
	}
	else
	{
		document.all['WebPartListFilter'].style.display = 'none';
	}
}
function numeric(){
	return ((event.keyCode - 48 >=0) && (event.keyCode - 48 <= 9)) ? true : false;		
}
function dateMask()
{
	var isValidKey = false;
	var input;
	var val;	
	input = window.event.srcElement;
	
	val = new String(input.value);
	if(event.keyCode == 46 && (val.length == 2 || val.length == 5))
	{
		isValidKey = true;
	}	
	else if((event.keyCode - 48 >=0) && (event.keyCode - 48 <= 9))
	{
		isValidKey = true;
		if(val.length == 2)
		{
			input.value = val + ".";
		}
		else if(val.length == 5)
		{
			input.value = val + ".";
		}
		else if(val.length >= 10)
		{
			input.value = "";
			isValidKey = true;
		}
	}	
			
	return isValidKey;
}

function noenter() 
{
  return !(window.event && window.event.keyCode == 13); 
}

function getElement(sElement){
	var oElement;
	if(document.getElementById)
		oElement = document.getElementById(sElement);
	else if(document.all)
		oElement = document.all(sElement);
	else if(document.layers)
		oElement = document.layers[sElement];
		
	return oElement;

}

/*Sigtar út hvert element útaf fyrir sig*/
function hideShowFields(sElement){
	while (sElement.length > 0){
		var iPosOfSep = sElement.indexOf(',');
		var sCurrElement = '';
		if (iPosOfSep >= 0){
			sCurrElement = sElement.substring(0, iPosOfSep);
			hideShowSingleField(sCurrElement);
			sElement = sElement.substring(iPosOfSep+1);
		}else{
			sCurrElement = sElement;
			hideShowSingleField(sCurrElement);
			return;
		}
	}
}

/*Felur eða birtir eitt element*/
function hideShowSingleField(sElement){
	var oElement;
	if (sElement.length < 1)
		return;
	
	oElement = getElement(sElement);
	if(oElement.style.display == "none")
		oElement.style.display = 'block';
	else
		oElement.style.display = 'none';
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validateHtmlTagsInput(input, alertText)
{
    if (input == null)
        return false;
    
    var openingIdx = input.indexOf("<");    
    var closingIdx = input.indexOf(">");

    var validInput = (openingIdx == -1) && (closingIdx == -1);
    
    if (!validInput)
        alert(alertText);
        
    return validInput;
}
function checkApplForErrors(){ 
	$('.FormBox').removeClass('errorRed');
	var errorList = []; 
	
	if($('#_ctl1__ctl1_C67').val().length < 1) { errorList.push('Kennitala'); $('#_ctl1__ctl1_C67').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C66').val().length < 1) { errorList.push('Nafn'); $('#_ctl1__ctl1_C66').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C68').val().length < 1) { errorList.push('Heimilisfang'); $('#_ctl1__ctl1_C68').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C4').val().length < 1) { errorList.push('Sími'); $('#_ctl1__ctl1_C4').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C89').val().length < 1) { errorList.push('Póstfang'); $('#_ctl1__ctl1_C89').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C6').val().length < 1) { errorList.push('Netfang'); $('#_ctl1__ctl1_C6').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C55').val().length < 1) { errorList.push('Hvenær getur þú hafið störf?'); $('#_ctl1__ctl1_C55').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C11').val().length < 1) { errorList.push('Próf'); $('#_ctl1__ctl1_C11').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C12').val().length < 1) { errorList.push('Skóli'); $('#_ctl1__ctl1_C12').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C13').val().length < 1) { errorList.push('Ár'); $('#_ctl1__ctl1_C13').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C35').val().length < 1) { errorList.push('Vinnuveitandi'); $('#_ctl1__ctl1_C35').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C36').val().length < 1) { errorList.push('Starfsheiti'); $('#_ctl1__ctl1_C36').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C37').val().length < 1) { errorList.push('Tímabil fyrri starfs'); $('#_ctl1__ctl1_C37').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C44').val().length < 1) { errorList.push('Nafn vinnu veitanda'); $('#_ctl1__ctl1_C44').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C45').val().length < 1) { errorList.push('Starfsheiti vinnu veitanda'); $('#_ctl1__ctl1_C45').addClass('errorRed'); }
	if($('#_ctl1__ctl1_C46').val().length < 1) { errorList.push('Sími vinnu veitanda'); $('#_ctl1__ctl1_C46').addClass('errorRed'); }
	
	if(errorList.length > 0) { 
		var ret = '<strong>Vinsamlegast athugið eftirtalda reiti</strong>' 
		ret = '<ul><li>'; 
		ret += errorList.join('</li><li>'); 
		ret += '</li></ul>';  
		$('.ContentDisplay_Text p').html(ret); 
		//$('.errors').show('slow');  
		return false; } 
		
	return true;
}
