// JavaScript Document
function show_box(boxid,frame_name,srcfile,w,h,scrolling){    
    var iframer = "<center><iframe name=" + frame_name + " src='" + srcfile + "' width=" + w + " height=" + h + " frameborder=0 scrolling=" + scrolling + " allowautotransparency=false></iframe></center>";
	parent.window.document.getElementById(boxid).innerHTML = iframer;}

function showthis(spanid,msgtoshow,spanclass){parent.window.document.getElementById(spanid).innerHTML ="<span class=" + spanclass + ">" + msgtoshow + "</span>";}
function showlocal(spanid,msgtoshow,spanclass){document.getElementById(spanid).innerHTML ="<span class=" + spanclass + ">" + msgtoshow + "</span>";}
function Replacer(spanid,msgtoshow){document.getElementById(spanid).innerHTML = msgtoshow;}
function Replace_in_parent(spanid,msgtoshow){parent.window.document.getElementById(spanid).innerHTML = msgtoshow;}
function change_value(this_id,thisvalue){document.getElementById(this_id).value = thisvalue;}
function change_value_in_parent(this_id,thisvalue){parent.window.document.getElementById(this_id).value = thisvalue;}
function get_value(this_id){return removeHTMLTags(document.getElementById(this_id).value);}
function toTop(thislayer, action, z){var lref;if(parent.window.document.getElementById && (lRef=parent.window.document.getElementById(thislayer))){lRef.style.visibility=action?'visible':'hidden'; lRef.style.zIndex=z;}
if(action=="false")parent.window.document.getElementById(thislayer).style.visibility='hidden';}
function Closeall_showone(div_name,last_div,show_this_one){
var temp =''; for(var i=1;i<=last_div;i++){temp = div_name + i; toTop(temp,'false',0);}toTop(show_this_one,'true',1);}

function Closeall_showone_new(div_name,starter,last_div,show_this_one){
var temp =''; for(var i=starter;i<=last_div;i++){temp = div_name + i; toTop(temp,'false',0);}toTop(show_this_one,'true',1);}
function wait_open(thiswindow){toTop('Waiting','true',1); setTimeout("toTop('Waiting','false',0); toTop('Domains','true',1)",3000); window.scrollTo(200,100);}
function change_over(thisframe,tothis){document.getElementById(thisframe).src=tothis;}
function change_over_in_parent(thisframe,tothis){parent.window.document.getElementById(thisframe).src=tothis;}
function changedimension(thisframe,w,h) {parent.window.document.getElementById(thisframe).width=w; document.getElementById(thisframe).height=h;}

function removeHTMLTags(thisstuff){var strInputCode = thisstuff;
 	 	processed = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "" : "";
 		});
 		processed = processed.replace(/<\/?[^>]+(>|$)/g, " ");
		processed = replaceAll(processed,"'", ""); processed = replaceAll(processed,'"', '');processed = replaceAll(processed,'(', '');
		processed = replaceAll(processed,'&', ''); processed = replaceAll(processed,')', '');
		return processed;
 	}	
	
function replaceAll(fromthis, search_for, replace_with) {  var idx = fromthis.indexOf(search_for);
  while ( idx > -1 ) {
  fromthis = fromthis.replace(search_for,replace_with); 
  idx = fromthis.indexOf(search_for);}return fromthis;}

//call the next function to check if selected file is .jpg or not
function fileselected()
{ var temp = document.getElementById('Photo').value;
		if (temp.match(/\.(jpeg|jpg)$/i, "")){
			//selected file is okay so show submit button (since we cannot autosubmit multi-part form)
			/*if (browsername.indexOf("Microsoft")!=-1) {
			var tempb = "<input type=submit value=\"Submit \" class=textbox onclick=\"javascript:showLayer('working');\">"
			document.getElementById('buttcell').innerHTML = tempb;}*/
			document.getElementById('buttcell').style.visibility = "visible";
			showlocal('showmsg','<span id=showmsg class=Blueheader><img src=Images/lbulb.gif alt=\'Observe max image size\' width=17 height=19>Max size: 10Mb each. Select only .jpg images</span>','Blueheader');}
		else{document.getElementById('buttcell').style.visibility = "hidden"; showlocal('showmsg','<span id=showmsg class=Blueheader><img src=Images/Rbulb.gif alt=\'Only .jpg or .jpeg files please\' width=17 height=19> Only .jpg or .jpeg files please!</span>','Blueheader');}
}

//call next function to change opacity of individual image
function changeOpac(opacity, id) {
	var object = parent.window.document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

//call next function to switch the style sheet for the page
function switch_style (css_title)
{ var i, link_tag ;
  for (i = 0, link_tag = document.getElementsByTagName("link") ;
    i < link_tag.length ; i++ ) {
    if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) &&
      link_tag[i].title) {
      link_tag[i].disabled = true ;
      if (link_tag[i].title == css_title) {
        link_tag[i].disabled = false ;
      }
    }
  }
}

//next nine functions are called by New-Album.asp
function setthis(thispic,img_id,td_id,imgTitle,Udate,iDimsW,iDimsH,Group_name,Group_num){var temp_img = '<img src=' + thispic + ' width = ' + iDimsW + ' height=' + iDimsH + ' border=0>'; switch_style('Straight'); toTop('Uploadwindow_3','true',1); Replacer('spic',temp_img);
var newsource = "Delete-Album-photo.asp?id=" + img_id + "&td_id=" + td_id; temp = '<input type=button value=Delete class=smalltxtbox title="Delete this picture" onclick="change_over(\'setmat\',\'' + newsource + '\');toTop(\'Uploadwindow_3\',\'false\',0);">';
Replacer('Update','Uploaded on: ' + Udate); Replacer('Delete img',temp); if(Group_name==""){ temp = '<input type=button value=" Do it " class=smalltxtbox Title="Add to existing group or create a new one" onclick="toTop(\'Uploadwindow_4\',\'false\',0);toTop(\'Uploadwindow_5\',\'true\',1);">'; Replacer('Add Group',temp); Replacer('Groups','Group: (none)');}
else{temp = '<input type=button value=" Redo " class=smalltxtbox Title="Add to existing group or create a new one" onclick="toTop(\'Uploadwindow_5\',\'true\',1);">'; Replacer('Add Group',temp);
temp = '<a href=# onclick="change_over(\'setmat\',\'Show-Photo-Group-data.asp?id=' + Group_num + '\'); Replacer(\'6_Description\',\'Fetching data ....\'); toTop(\'Uploadwindow_6\',\'true\',1);" class=bluen title="Click to edit this group title or description">' + Group_name + '</a>'; Replacer('Groups',temp); } 
Replacer('Group_butt','<input type="button" class="bluebuttons" value="Enter" onClick="Add_2_group('+img_id+');">'); change_value('4_This Image',td_id); change_value('5_This Image',td_id);  change_value('Old_group',Group_num); 
temp = '<input type="button" class="bluebuttons" value=" Enter " onClick="create_new_group(' + img_id + ');">'; Replacer('4_button',temp);
if(imgTitle==""){temp = 'Title: <input id="Image Title" name="Image Title" type="text" size="28" maxlength="48" class="textbox" title="Enter a short descriptive title for this picture"> <br><span class="smallgrey">Example: Me & Joe at Anjuna Beach in Goa</span>'; 
Replacer('Title area',temp); temp = '<input type="submit" value="Enter " class="bluebuttons" onClick="Update_img_title();" Title="Enter title for this picture">'; Replacer('Edit Title',temp);}
else{temp = '<input type=button value=" Edit it" class=smalltxtbox Title="Edit title" onclick="doedit(\'' + imgTitle + '\');">';
Replacer('Title area','Title: ' + imgTitle); Replacer('Edit Title',temp);} change_value('This Image',img_id + "|" + td_id);}

function closeUploadwindow2(){var temp = "Upload: <input type=file id=upload_file class=bluebox onchange=\"" + "fileselected('upload_file','showpichere','Blueheader')\""+">";
window.document.getElementById('showpichere').innerHTML = temp; showlocal('showmsg','<img src=Images/lbulb.gif alt=\'Observe max image size\' width=17 height=19>Max size: 10Mb each. Select only .jpg images','Blueheader');
showlocal('submitter','','');}

function Update_img_title(){var new_title = get_value('Image Title'); var this_id = get_value('This Image'); var temp = 'Update-Photo-title.asp?id=' + this_id + '&title=' + new_title; change_over('setmat','Update-Photo-title.asp?id=' + this_id + '&title=' + new_title); 
toTop('Uploadwindow_3','false',0);}

function doedit(imgTitle){var temp = 'Title: <input id="Image Title" name="Image Title" type="text" size="28" maxlength="48" class="textbox" value="' + imgTitle + '"> <br><span class="smallgrey">Example: Me & Joe at Anjuna Beach in Goa</span>'; 
Replacer('Title area',temp); temp = '<input type="button" value="Enter " class="bluebuttons" onClick="Update_img_title();" onMouseOver="Tip(\'Enter title for this picture\');">'; Replacer('Edit Title',temp);}

function create_new_group(thisid){var group_title = get_value('Group Title'); var group_desc = get_value('Description'); var tdid = get_value('4_This Image'); var temp = 'Create-Photo-group.asp?id=' + thisid + '&title=' + group_title + '&desc=' + group_desc + '&tdid=' + tdid;
change_over('setmat',temp); toTop('Uploadwindow_4','false',0);}

function Add_2_group(thisid){var temp = document.grouper.Egroups.selectedIndex; temp = document.grouper.Egroups.options[temp].value; var tdid = get_value('5_This Image'); var old_group = get_value('Old_group'); 
change_over('setmat','Add-Photo-group.asp?datab=' + temp + '|' + tdid + '|' + thisid + '|' + old_group); toTop('Uploadwindow_5','false',0);}

function delete_group_options(){Replacer('6a_Title',get_value('Group-Title'));  change_value('6a_id',get_value('6_id')); toTop('Uploadwindow_6a','true',1);}
function delete_group(){var temp = document.groupd.Delopt[0].checked; if(temp) {//delete only group details
temp = 'Delete-Photo-Group.asp?id=' + get_value('6a_id') + '&opt=1'; }else {//delete group + everything attached to it
temp = 'Delete-Photo-Group.asp?id=' + get_value('6a_id') + '&opt=2'; } opentheWindow(temp,'wind',50,50);}

function Do_marker(this_span,max_ctr,show_this,thisid){var temp =''; for(var i=0;i<=max_ctr;i++){temp = this_span + i; Replacer(temp,'');} temp = this_span + thisid; Replacer(temp,show_this);}
function Add_tagg(this_stuff){change_over('setmat','Add-Tagg.asp?id=' + this_stuff);}

function preload() {for(var i=0;i<arguments.length;i++){var img=new Image();img.src=arguments[i]}}
//preload("Images/slider.png", "Images/slider_fill.png");

function wininvisible(){
	//tiny invisible window
	self.moveTo(9000,9000);
	self.resizeTo(1,1);
	self.focus(); }
	
function winclose(){
	self.moveTo(0,0);
	self.resizeTo(screen.availWidth,screen.availHeight);
	self.focus(); window.close(); }
		
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 browsername(){var browsername=navigator.appName; if (browserName=="Microsoft Internet Explorer") {browsername = "Microsoft"}else{browsername = "NS"} return browsername;}

function browsercheck(writethis,thisbrowser,else_write_this){
	browsername=navigator.appName;
	if (browsername.indexOf(thisbrowser)!=-1) {window.document.write(writethis)}else{window.document.write(else_write_this);}}

function cursorPosition(e) { e = e || window.event; var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) { cursor.x = e.pageX;  cursor.y = e.pageY; } 
    else { var de = document.documentElement; var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    } return cursor; }
	
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  window.document.MM_returnValue = (errors == '');
}
//the three are required by the message center
function deletethis(thisone,displayer){
	var thismail = "Delete-Message.asp?id=" + thisone;
	window.open (thismail,"Deleter");
	window.document.getElementById(displayer).innerHTML = "** Message deleted **"
}
  
function openWindow(winName,width,height) {
    x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }

    window.open('Blank.htm',winName,'resizable=1,scrollbars=1,width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
}
function opentheWindow(filename,winName,width,height) {
    x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }

    window.open(filename,winName,'resizable=1,scrollbars=1,width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
}
	function MM_openBrWindow(theURL,winName,features) { //v2.0
		  window.open(theURL,winName,features);}