function MM_openBrWindow(theURL,winName,features) { //v2.0
	openWin(theURL);
	return;
	//window.open(theURL,winName,features);
}

function getAvailHeight() {
	screenx = screen.width; 
	screeny = screen.height;
	if (document.getElementById && !document.all) {
		height = window.innerHeight;
		width = window.innerWidth;
	} else if (document.all) {
		height = document.body.offsetHeight;
		width = document.body.offsetWidth;
	}
	return height;
}

function openWin(url) {
	try {
		var width, height, screenx, screeny, popupHeight, popupWidth;
		screenx = screen.width; 
		screeny = screen.height;
		if (document.getElementById && !document.all) {
			height = window.innerHeight;
			width = window.innerWidth;
		} else if (document.all) {
			height = document.body.offsetHeight;
			width = document.body.offsetWidth;
		}
		
		if (screenx<1050 && screenx>800) {
			popupWidth = (parseInt)(screen.availWidth*0.80);
			popupHeight = (parseInt)(screen.availHeight*0.76);
			iW = (parseInt)(popupWidth - 245);
			iH = (parseInt)(popupHeight - 135);
		} else if (screenx<=800) {
			popupWidth = (parseInt)(screen.availWidth*0.95);
			popupHeight = (parseInt)(screen.availHeight*0.90);	
			iW = (parseInt)(popupWidth - 225);
			iH = (parseInt)(popupHeight - 200);
		} else {
			popupWidth = 840;
			popupHeight = 675;
			iW = (parseInt)(popupWidth - 215);
			iH = (parseInt)(popupHeight - 150);
		}
		
		popupHeight = popupHeight + 10;
		
		wleft = (screen.width-popupWidth)/2;
		wtop = (screen.height-popupHeight)/2;
		
		var settings ='height='+popupHeight+',width='+popupWidth+',top='+wtop+'left='+wleft+',scrollbars=yes,resizable=yes';
		win=window.open(url+"?w="+iW+"&h="+iH,"opp",settings);
		
		//chrome has issue with moveTo
		var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		if (is_chrome) return;
		
		//continue
		if (document.getElementById && !document.all) {
			if (win.innerWidth<=popupWidth){
				win.moveTo(wleft,wtop-50);
			}
		} else {
			win.moveTo(wleft,wtop-50);
		}
		
		if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
	
	} catch (ex) {
		var settings ='height=675,width=825,top=50left=50,scrollbars=yes,resizable=yes';
		win=window.open(url+"?w=475&h=475","opp",settings);
		win.moveTo(50,50);
		if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
	}
}

function resizeWin(w, h) {
	try {
		var width, height, screenx, screeny;
		screenx = screen.width; 
		screeny = screen.height;
		
		var popupWidth = w;
		var popupHeight = h;
		
		wleft = (screen.width-popupWidth)/2;
		wtop = (screen.height-popupHeight)/2;
		
		if (document.getElementById && !document.all) {
			if (window.innerWidth < screen.width) {
				window.moveTo(wleft,wtop-50);
				window.resizeTo(popupWidth,popupHeight);
			}
		} else {
			window.moveTo(wleft,wtop-50);
			window.resizeTo(popupWidth,popupHeight);
		}

	} catch (ex) {
		window.resizeTo(825,675);
		//window.moveTo(wleft,wtop-50);
	}
}

function gotoWin(url) {
	try {
		var width, height, screenx, screeny;
		screenx = screen.width; 
		screeny = screen.height;
		if (document.getElementById && !document.all) {
			height = window.innerHeight;
			width = window.innerWidth;
		} else if (document.all) {
			height = document.body.offsetHeight;
			width = document.body.offsetWidth;
		}
		
		if (screenx<1050 && screenx>800) {
			popupWidth = (parseInt)(screen.availWidth*0.80);
			popupHeight = (parseInt)(screen.availHeight*0.76);
			iW = (parseInt)(popupWidth - 245);
			iH = (parseInt)(popupHeight - 135);
		} else if (screenx<=800) {
			popupWidth = (parseInt)(screen.availWidth*0.95);
			popupHeight = (parseInt)(screen.availHeight*0.90);	
			iW = (parseInt)(popupWidth - 225);
			iH = (parseInt)(popupHeight - 200);
		} else {
			popupWidth = 840;
			popupHeight = 675;
			iW = (parseInt)(popupWidth - 215);
			iH = (parseInt)(popupHeight - 150);
		}
		
		wleft = (screen.width-popupWidth)/2;
		wtop = (screen.height-popupHeight)/2;
		
		
		if (document.getElementById && !document.all) {
			if (window.innerWidth < screen.width) {
				window.resizeTo(popupWidth,popupHeight+80);
				window.moveTo(wleft,wtop-50);
			}
		} else {
			window.resizeTo(popupWidth,popupHeight+80);
			window.moveTo(wleft,wtop-50);
		}
		
		//window.resizeTo(popupWidth,popupHeight+80);
		//window.moveTo(wleft,wtop-50);
		
		document.location = url+"?w="+iW+"&h="+iH;

	} catch (ex) {
		window.resizeTo(825,675);
		document.location = url+"?w=475&h=475";
		window.moveTo(wleft,wtop-50);
	}
}

function viewAll() {
	try {
		window.opener.focus();
		//opener.moveTo(0,0);
		//opener.resizeTo(window.screen.availWidth,window.screen.availHeight);
		window.close();
	} catch (ex) {
	}
}

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 YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}

function reloadThumb() {
	try {
	for (i=0;i<document.images.length;i++) {
		if (!document.images[i].complete) document.images[i].src = document.images[i].src;
	}
	} catch (ex) {
	}
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function oppcreateCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function oppreadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function opperaseCookie(name) {
	oppcreateCookie(name,"",-1);
}


/**** siteutils.js ****/


function frameRedirect() {
	try {
		if (self != top) {
			if (top.location.toString().indexOf('onlinepictureproof.com')>0) {
				document.location.href="<?php echo $SITE_URL.$user; ?>/albums";
			}
		}
	} catch (ex) {
	}
}

function chkRefresh() {
	var str = new String(window.location);
	if(str.match(/\//g).length<=4) window.location.href = window.location.href;
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function setFrame() {
    try {
    document.getElementById("main").height = getAvailHeight() - 180;
	pxheight = getAvailHeight() - 180;
	pxheight = pxheight + "px";
	document.getElementById("main").style.height = pxheight;
    } catch (ex) {
    }
}

function setPagesFrame() {
    try {
    document.getElementById("viewphoto").height = getAvailHeight() - 250;
	pxheight = getAvailHeight() - 250;
	pxheight = pxheight + "px";
	document.getElementById("viewphoto").style.height = pxheight;
    } catch (ex) {
    }
}

function setGalleryFrame1() {
    try {
			newheight = getAvailHeight() - 255;
			newheightpx = newheight + "px";
			
			document.getElementById("galleryframe").height = newheight;
			document.getElementById("galleryframe").style.height = newheightpx;
			
			document.getElementById("framecontainer").height = newheight;
			document.getElementById("framecontainer").style.height = newheightpx;
    
		} catch (ex) {
    }
}
 /*** End siteutils.js ***/




