// JScript source code

/*
window.onerror = handleErrors
function handleErrors(){return true}
*/

//var hst = "http://www.planetembroidery.com/"
var hst = "http://"+location.host;
var mtr_idx, mtr_tx
var hlp,wzd,txt,ctn,rad
var img_s_r = new Image();
var img_s_b = new Image();

var sh_w,sh_h = 0
hlp = false
img_s_r.src = "../img/kasteel-drop2-10x250.gif"
img_s_b.src = "../img/kasteel-drop3-400x10.gif"

function setHelpVariables() {
if (!document.getElementById("ShowHelp")) return;
document.getElementById("ShowHelp").style.display = ""
if (document.getElementById("WZD"))			wzd = document.getElementById("WZD")
//mtr = self //window.frames["MASTER"]
if (document.getElementById("TXT"))			txt = document.getElementById("TXT")
if (ctn = document.getElementById("CTN"))	ctn = document.getElementById("CTN")
if (document.getElementById("chHelp"))	{	rad = document.getElementById("chHelp") ; rad.disabled=false; }
if (wzd && ctn && txt && rad) {
	hlp = true
}
//alert(wzd +", "+ txt +", "+ ctn +", "+ rad)
}

function nohelp(){
if (self.mtr_idx)
	no_wzd()
}

function do_wzd(idx){
//setHelpVariables();
if (!hlp) return
var idx = mtr_idx
var tx = mtr_tx
var posx,posy,img
var movex = 420
var movey = -100
//alert(mtr.document.body.innerHTML)
//if (show) wzd.style.display=""
//alert(document.getElementById("elWZD_"+idx))
if (document.getElementById("elWZD_"+idx)) {
	posx = getX(document.getElementById("elWZD_"+idx))
	posy = getY(document.getElementById("elWZD_"+idx))				
	//wzd.innerHTML = mtr.document.getElementById("elWZD_"+idx).innerHTML
	if (posx > 300) {
		if (posy > 20) 
			img = "pen.png"
		else
			img = "pen.png"
		movex = -100
	}else{
		if (posy > 20) 
			img = "pen.png"
		else
			img = "pen.png"			
		movey = 20
	}
	ctn.src = img
	txt.innerHTML = tx;
	wzd.style.left = (posx + movex) +"px"
	//alert(wzd.style.left)
	wzd.style.top = (posy + movey) +"px"		
	wzd.style.display = ""	
}
}
function no_wzd(){
wzd.style.display="none"
}
function show_wzd(ch){
if (ch.checked){
	hlp = true
	do_wzd()
}else{
	hlp = false
	no_wzd();
}
}

function getX(obj){
  return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent) );
}
function getY(obj){
  return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
}

function nohelp(){
//self.parent.no_wzd()
}
function doNewImageVerification(img){
var im = new Image();
im.src = "/imageVerification.asp?"+(new Date()).getTime();
document.images[img].src = im.src;
return false;
}
function doShadow(img,stype,iid) {
//alert(1)
sh_w = img.width + 1 + 6;
sh_h = img.height + 1 + 3;
document.getElementById("picshadow_"+stype+"_"+iid).style.width = sh_w + "px"
var h = "<img class=shdw name="+stype+"_shadow_right_"+iid+" src='"+img_s_r.src+"?"+(new Date()).getTime()+"' width=5 height="+sh_h+" ><br>"+
	"<img class=shdw name="+stype+"_shadow_bottom_"+iid+" src='"+img_s_b.src+"?"+(new Date()).getTime()+"' width="+sh_w+" height=5>"
document.getElementById(stype+"_shadow_"+iid).innerHTML = h
//alert(1)
}
function hdPS(f){
var p = document.getElementById("Password")
var s = document.getElementById("PwStrength")
var d = document.getElementById("pwLength")
if (p.value.length>0){
	s.style.display="";	
	d.style.width = ( 100 - ((100 * p.value.length ) / p.maxLength)) +"%"
}else
	s.style.display="none"
}

function doSize(obj,wd,ht){
imh = obj.height;
imw = obj.width;
var rl;
// si el alto es mayor que el ancho
if (imh >= imw){
	rl = imh / imw
	imw = parseInt( (imw * ht) / imh )
	imh = ht 
	if ( imw > wd ) {
		imw = wd;
		imh = parseInt( wd / rl )
	}
	if ( imh > ht ) {
		imh = ht;
		imw = parseInt( ht * rl )
	}
// si el ancho es mayor que el alto	
}else if (imw > imh) {
	rl = imw / imh
	imh = parseInt( (imh * wd) / imw )
	imw = wd 
	if ( imh > ht ) {
		imh = ht;
		imw = parseInt( ht * rl )
	}
	if ( imw > wd ) {
		imw = wd;
		imh = parseInt( wd / rl )
	}

}
obj.style.width = imw;
obj.style.height = imh;
/*
var pdt = parseInt( (ht - imh) / 2 )
obj.style.marginTop = Math.abs(pdt) + "px";
pdt = parseInt( (wd - imw) / 2 )
obj.style.marginLeft = Math.abs(pdt) + "px";
*/
obj.style.visibility='visible';
}
/*
function adv(b){
if (!document.getElementById("AdvLink")) return;
var ch = document.getElementById("AdvOptions")
var lk = document.getElementById("AdvLink")
if (ch.style.display=="none"){
	ch.style.display=""
	lk.innerHTML = "Simple search"
}else{
	ch.style.display="none"
	lk.innerHTML = "Advanced search"
}
	
}
*/
/* <!------------- FUNCIONES PARA AJAX > LISTA DE PALABRAS CLAVES SUGERIDAS ---------------> */

var xmlHttp
var can_submit = false

function GetXmlHttpObject(){
	xmlHttp=null;
	try {		
		xmlHttp=new XMLHttpRequest();
	}catch (e) {  
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


function retrieveKeywords(fld){ 
	xmlHttp=GetXmlHttpObject();
	/*window.open("<%=pg%>?getkeywordsfor="+escape(fld)+"&dmy="+ Math.random())
	return 0*/
	if (xmlHttp==null || fld=="" || fld.length<2) return;
	//var url="http://fileserver/sierrainside/pe08/search.asp?getkeywordsfor="+escape(fld)+"&dmy="+ Math.random();	
	//alert(top.location.host)
	//window.open("http://"+ self.location.host +"/Resources_Center/search.asp?getkeywordsfor="+escape(fld)+"&dmy="+ Math.random())
	var url = "http://"+ self.location.host +"/Resources_Center/search.asp?getkeywordsfor="+escape(fld)+"&dmy="+ Math.random();	
	xmlHttp.onreadystatechange=stateChanged;	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState==4)
		setKeywords(xmlHttp.responseText);
}

document.onkeydown = register;	

function register(e){
	if (!document.getElementById("query") || !document.getElementById("KeywordsList")) return;
	if (!e) e = window.event;
	if (e.keyCode==13 && can_submit) document.sch.submit();	
	if (!can_submit && e.keyCode==40 && document.getElementById("KeywordsList").style.display=="") {
		can_submit=true; 
		document.getElementById("KeywordsList").focus(); 
		document.getElementById("KeywordsList").options[0].selected=true; 
		document.sch.query.value = document.getElementById("KeywordsList").options[0].text;
	}
}

function setKeywords(str){	
	/*alert(str)
	return 0*/
	if (!document.getElementById("KeywordsList")) return
	var newOpt
	var f = document.getElementById("KeywordsList")
	if (str.indexOf("|")==-1)
		f.style.display="none"
	else{		
		f.options.length = 0
		ops = str.split("|")
		for (var i=0; i<ops.length-1; i++) {
			newOpt = new Option(ops[i], ops[i]);			
			f.options[i] = newOpt;			
		}
		f.style.height = (13 * (ops.length)) + "px"
		if (ops.length>6) f.style.height = (13 * 6) + "px"
		f.style.left = getX(document.getElementById("query")) +"px"
		f.style.top = (getY(document.getElementById("query")) + 20) +"px"		
		f.style.width = document.getElementById("query").style.width;
		f.style.display=""
	}	
}

/* <!------------- FUNCIONES PARA AJAX > LISTA DE PALABRAS CLAVES SUGERIDAS ---------------> */ 


function dp(n){
for (var i=1; i<5; i++) {
	if (document.getElementById("doAction_"+i) && i!=n)	{
		document.getElementById("doAction_"+i).style.display="none"
		document.getElementById("dplink"+i).style.backgroundImage=""
		document.getElementById("dplink"+i).style.color=""
	}
}
if (document.getElementById("doAction_"+n).style.display=="none"){
	document.getElementById("doAction_"+n).style.display=""
	document.getElementById("dplink"+n).style.backgroundImage="url(../img/minipanel_tab.gif)"
	document.getElementById("dplink"+n).style.color="black"
}else{
	document.getElementById("doAction_"+n).style.display="none"
	document.getElementById("dplink"+n).style.backgroundImage=""
	document.getElementById("dplink"+n).style.color=""
}
}
function textCounter(field,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
document.getElementById(field.name+"_count").innerHTML = maxlimit - field.value.length
}
function showLoading() {
if (document.getElementById("LoadingDiv")) {
var d = document.getElementById("LoadingDiv");
/*var w = d.style.width;
var h = d.style.height;*/
//var h = "";
//if (navigator.userAgent.toUpperCase().indexOf("MSIE")!=-1) h = "<style type='text/css'>#LoadingDiv{ background-image:url("+hst+"images2/bkg_loadingdiv.gif)}</style> "
var msg = "Loading... Please wait...";  
var h = "<Span style='font-family:MS Sans Serif;color:green;font-size:11px'>"+ msg +"<img src='"+hst+"WebDGuide/images/loading.gif' hspace=10 align=absmiddle >"
//alert(d)
d.innerHTML = h;
d.style.left = (screen.width-200)/2 +"px";
d.style.top = (screen.height-50)/2 +"px";
d.style.visibility="visible";
}
}
function hideLoading(){
if (document.getElementById("LoadingDiv")) {
var d = document.getElementById("LoadingDiv");
d.innerHTML = "";
//d.style.visibility="hidden";
d.style.display="none";
}
}
function pp1aux2(u,w,h){
/*var w = 350
var h = 250*/
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
//var lg = window.open(u,"SignIn","width="+w+",height="+h+",top="+wint+",left="+winl+",scrollbars=yes")
var lg = window.open(u,"hlp")
lg.focus();
}
function pp2aux(f){
var w = 800
var h = 620
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
var rg = window.open( hst + "EOWS/register.asp","Register","width="+w+",height="+h+",top="+wint+",left="+winl+",scrollbars=yes")
if (f) {
	f.target='Register';
	f.submit();
}
rg.focus();
}

function doSubOps(n){
if (!document.getElementById("SOps_1")) return;
for (var i=1; i<4; i++) {
	document.getElementById("SOps_"+i).style.display="none"
	document.getElementById("SOlk"+i).style.backgroundImage=""
	document.getElementById("SOlk"+i).style.color="";
}
if (document.getElementById("SOps_"+n)){
	document.getElementById("SOps_"+n).style.display="";
	document.getElementById("SOlk"+n).style.backgroundImage="url(/img/servtoptab_bkg.gif)";
	document.getElementById("SOlk"+n).style.color="White";
}
}
function setqueries(){
if (!document.getElementById("PopQueries")) {alert(1); return;}
var move = parseInt(document.getElementById("PopQueries").offsetHeight / 2) 
document.getElementById("PopQueries").style.top = (move - (move*2)) +"px"
}
function is_child_of(parent, child) {
			if( child != null ) {			
				while( child.parentNode ) {
					if( (child = child.parentNode) == parent ) {
						return true;
					}
				}
			}
			return false;
		}
		function fixOnMouseOut(element, event, JavaScript_code) {
			var current_mouse_target = null;
			if( event.toElement ) {				
				current_mouse_target 			 = event.toElement;
			} else if( event.relatedTarget ) {				
				current_mouse_target 			 = event.relatedTarget;
			}
			if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
				eval(JavaScript_code);
			}
		}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}



function doMiniSchBox(mde,dv){
dv.style.top = findPos(document.getElementById("MiniSchLink"))[1]  +"px"
dv.style.left = findPos(document.getElementById("MiniSchLink"))[0] +"px"
if (mde) 
	dv.style.display=""
else
	dv.style.display="none"
}

function pp1aux(u){
var w = 350
var h = 310
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
var lg = window.open(u,"SignIn","width="+w+",height="+h+",top="+wint+",left="+winl+",scrollbars=no")
lg.focus();
}


/*******************************************

Este código es para obtener la cuenta de diseños restantes en la tarifa activa del usuario actual
lo llamo desde el lytebox, en su método .end()
y es una llamada ajax, aqui mismo estan los metodos genericos para hacerlo

--- Ariel - 18/05/11 ***********************/


function getDesignsCount() {    
    ajaxSend("/Designs_Center/const.asp?TPcount=" + (new Date()).getTime(), setDesignsCount);
}
function setDesignsCount(s) {
    if (document.getElementById("TPcounter")) {
        document.getElementById("TPcounter").innerHTML = ""+ s;
    }    
}

// threadsafe asynchronous XMLHTTPRequest code
function ajaxSend(url, callback) {
    function ajaxBindCallback() {
        if (ajaxRequest.readyState == 4) {
            if (ajaxRequest.status == 200) {
                if (ajaxCallback) 
                    ajaxCallback(ajaxRequest.responseText);                
            }
        }
    }    
    var ajaxRequest = null;
    var ajaxCallback = callback;    
    if (window.XMLHttpRequest) {        
        ajaxRequest = new XMLHttpRequest();
        ajaxRequest.onreadystatechange = ajaxBindCallback;
        ajaxRequest.open("GET", url, true);
        ajaxRequest.send(null);
    } else if (window.ActiveXObject) {    
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        if (ajaxRequest) {
            ajaxRequest.onreadystatechange = ajaxBindCallback;
            ajaxRequest.open("GET", url, true);
            ajaxRequest.send();
        }
    }
}

