var CODE_PATH='/sh';


function newDateSelectWindow(dateId,formName,startYear,endYear) {

   mywindow=open(CODE_PATH+'/widgets/dateselector.ikml?id='+dateId+'&fname='+formName+'&syear='+startYear+'&eyear='+endYear,'myname','modal=yes,resizable=no,width=250,height=270');
   mywindow.location.href = CODE_PATH+'/widgets/dateselector.ikml?id='+dateId+'&fname='+formName+'&syear='+startYear+'&eyear='+endYear;
    if (mywindow.opener == null) mywindow.opener = self;
    
//    wp_openDialog(CODE_PATH+'/widgets/wp_dateselector.ikml?id='+dateId+'&fname='+formName+'&syear='+startYear+'&eyear='+endYear, 'modal',250,270) 

}

function newDateSelectWindowPHP(dateId,formName,startYear,endYear) {

	obj=eval('document.'+formName+'.'+dateId+'month');
	defMonth=obj.options[obj.selectedIndex].value;
	obj=eval('document.'+formName+'.'+dateId+'year');
	defYear=obj.options[obj.selectedIndex].value;
	
	targetPath=CODE_PATH+'/widgets/wp_dateselectorphp.ikml';

	wp_openDialog('/wwp/editor_files/dialog_frame.php?window='+targetPath+'&id='+dateId+'&fname='+formName+'&defmonth='+defMonth+'&defyear='+defYear+'&syear='+startYear+'&eyear='+endYear, 'modal',250,270) 

}


function previewImage(fileName,winTitle,closePhrase) {
	if (fileName!="") {
		file=unescape(fileName);
		rep="\\";
		while (file.indexOf(rep)!=-1) { file=file.replace(rep,'/'); }
		myFloater = window.open("","","scrollbars,resizable,width=600,height=400")
		myFloater.document.write("<HTML><HEAD><BODY><TITLE>"+winTitle+"</TITLE></HEAD><DIV ALIGN=\"CENTER\">")
		myFloater.document.write("<IMG SRC=\""+file+"\" BORDER=\"0\">")
		myFloater.document.write("<br><br><a href=\"javascript:self.close()\">"+closePhrase+"</a>")
		myFloater.document.write("</DIV></BODY></HTML>")
	}
}

// specifically for the new wysiwyg image picker
var thisFieldName=''; 
var thisFormName=''; 
// Open the image picker window
function openImageWindow(sessid,fieldname,mcp_image_upload,formName) {
	thisFieldName=fieldname;
	thisFormName=formName;
	wp_openDialog('/wwp/editor_files/dialog_frame.php?PHPSESSID='+sessid+'&window=image.php&return_function=insertImg&mcp_image_upload='+mcp_image_upload, 'modal',730,466) 
} 
// Recieve the image file from image picker window and insert it into the page
function insertImg(iurl, iwidth, iheight, ialign, ialt, iborder, imargin) { 
	if (thisFieldName!='') {

		fld=eval('self.document.'+thisFormName+'.'+thisFieldName);
		value=construct_image_html(iurl, iwidth, iheight, ialign, ialt, iborder, imargin);
	
		fld.value=value;
		imgfname='disp_'+thisFieldName;
	
		self.document.getElementById(imgfname).src=iurl;
		self.document.getElementById(imgfname).width=iwidth;
		self.document.getElementById(imgfname).height=iheight;
		self.document.getElementById(imgfname).style.display='block';
	}
} 
// construct the html required to display an image
function construct_image_html(iurl, iwidth, iheight, ialign, ialt, iborder, imargin) {
	imageHtml='<img src="'+iurl+'" width="'+iwidth+'" height="'+iheight+'" alt="'+ialt+'" />';
	return imageHtml;
}

//Open the image window in theme mode
function openThemeImageWindow(sessid,fieldname) {
	thisFieldName=fieldname;
    wp_openDialog('/wwp/editor_files/dialog_frame.php?PHPSESSID='+sessid+'&window=image.php&return_function=insertThemeImg', 'modal',730,466) 
}
// insert the image returned by the theme picker window and insert intoi the theme edit page
function insertThemeImg(iurl, iwidth, iheight, ialign, ialt, iborder, imargin) { 
	if (thisFieldName!='') {
		obj=eval('self.document.forms[0].'+thisFieldName);
		
		newval=iurl;
		if (newval!='') {
			newval='url('+iurl+')';
		} 
		obj.value=newval;
		// on change will not fire automatically if we are changing the field like this so fire manually
		obj.onchange();
		imgfname='disp_'+thisFieldName;
		if (self.document.getElementById(imgfname)) {
			if (iurl!='') {
				// we must put the thumbnails directory in
				lastSlash=iurl.lastIndexOf('/');
				f=iurl.substring(0,lastSlash);
				isrc=f+'/wpThumbnails'+iurl.substring(lastSlash);
				self.document.getElementById(imgfname).src=isrc;
				self.document.getElementById(imgfname).style.display='inline';
			} else {
				self.document.getElementById(imgfname).src='/sh/img/blank.gif';
				self.document.getElementById(imgfname).style.display='inline';
			}
		}
	}
} 

// open the new colour picker window
function openColorWindow(sessid,fieldname) {
	thisFieldName=fieldname;
    wp_openDialog('/wwp/editor_files/dialog_frame.php?PHPSESSID='+sessid+'&window=selcolor.php&return_function=insertColor', 'modal',296,352) 
} 
// recieve the chosen color from the popup window then insert into the page
function insertColor(color) { 
	if (thisFieldName!='') {
		obj=eval('self.document.forms[0].'+thisFieldName);
		obj.value=color;
		obj.style.backgroundColor=color;
		// on change will not fire automatically if we are changing the field like this so fire manually
		obj.onchange();
	}
	return true;
} 
// update a particular field with the passed color
function updateColor(field, color) {
	obj=self.document.getElementById('disp_'+field);
	obj.value=color;
	obj.style.backgroundColor=color;
	
}
// do targets in button editor
function openTargetWindow(sessid,fieldname) {
	thisFieldName=fieldname;
    wp_openDialog('/wwp/editor_files/dialog_frame.php?PHPSESSID='+sessid+'&window=hyperlink.php&return_function=insertTarget', 'modal',730,466) 
} 

function insertTarget() {
	alert('inside insertTarget');
}



