var win=null;
function openWindow(mypage,myname,w,h,scroll) {
    LeftPosition=(screen.width)?((screen.width-w)/2) - 150:100;
    TopPosition=(screen.height)?((screen.height-h)/2) - 50:100;
    settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    win=window.open(mypage,myname,settings);
    if(win.focus) {
        win.focus();
    }
}

function openWindow(mypage,myname,w,h,scroll,pos) {
    LeftPosition=(screen.width)?((screen.width-w)/2) - 150:100;
    TopPosition=(screen.height)?((screen.height-h)/2) - 50:100;
    settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    win=window.open(mypage,myname,settings);
    if(win.focus) {
        win.focus();
    }
}


function openWindow(mypage,myname,w,h,scroll,pos,resize) {
    LeftPosition=(screen.width)?((screen.width-w)/2) - 150:100;
    TopPosition=(screen.height)?((screen.height-h)/2) - 50:100;
    //alert(mypage);
	if(mypage.indexOf("?") > 0) {
		var link = mypage.substring(mypage.indexOf("?")+1,mypage.length);
		var parameters = link.split("&");
		link = "";
		for( var i = 0; i < parameters.length; i++) {
		var values = parameters[i].split("=");
	  
		link = link + values[0].replace(/,/g,"%2C").replace(/</g,"%3C").replace(/>/g,"%3E")+"="+values[1].replace(/,/g,"%2C").replace(/\//g,"%2F").replace(/</g,"%3C").replace(/>/g,"%3E");
		if(i < parameters.length-1)
		   link = link + "&";
		}
		mypage = mypage.substring(0,mypage.indexOf("?")+1)+link
	}
    //alert(mypage.substring(0,mypage.indexOf("?")+1)+link);
    settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable='+resize;
    win=window.open(mypage,myname,settings);
    if(win.focus) {
        win.focus();
    }
}

function openFullWindow(mypage) {
	var LeftPosition=0;
	var TopPosition=0;
	var settings='width='+screen.width+',height='+screen.height+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=yes,directories=yes,status=yes,menubar=yes,toolbar=yes,resizable=yes';
	win=window.open(mypage,'',settings);
	if(win.focus) {
		win.focus();
	}
}


function textLimit(field, maxlen, msg) {
    if (field.value.length > maxlen) {
        field.value = field.value.substring(0, (maxlen));
        alert(msg);
    }
}

function isParentOpen()
{
	try{
		if(opener == null)
			return false;
		else if(opener.closed)
			return false;
		return true;
	}catch(e){}
	return false;
}

function checkParent()
{
	if(isParentOpen())
		alert("Parent is Open");
	else 
		alert("Parent is not available");
}

function setParentLocation(URL)
{
		try{
			opener.document.location.href = URL;
		}
		catch(e){
			try{
				opener.document.location.reload();
			}
			catch(ep)
			{}
		}
}

function focusParent()
{
	opener.focus();
}

function focusParentOrOpen(URL)
{
	if(isParentOpen())
	{
		focusParent();
		setParentLocation(URL)
	}
	else
	{
		openFullWindow(URL);
	}
}

function prepareSubmitImageButton(imageElement){
    var xInputName = imageElement.name+".x";
    if(!imageElement.form.elements[xInputName]);{
        var input = document.createElement("input");
        input.setAttribute("type", "hidden");
        input.setAttribute("name", xInputName);
        input.setAttribute("value", "1");
        imageElement.form.appendChild(input);
    }
}
