

@import <Foundation/CPObject.j>
@import "ServerConnector.j"
@import "RMAlertPanel.j"
//@import "model/Model.j"

 

@implementation RMControllerObject : CPObject {


	//id mode;
	id useTabl;
	id eventTabl;
	id accoPass;
	id accoUser;
	id appCont;

	id cgiHost;
	id cgiServ;
	id coloOran;
	id coloRed;
	id coloBlue;
	id coloDefa;
	id coloDefaBrig;
	id coloDefaLite;
	id coloGree;
	id coloMess;
	id coloYell;

	id dataBase;

	id heigOran;
	id heigBlue;

	id mapCont;
	id messView;

	id orgaCode;
	id orgaid;
	id countryCode;

	id passFiel;
	id userFiel;
	//add 2017-03-02
	id isLogi;
	id role;
	id clie;
	id prod;
	//id nameDataBase;
	//id hostDataBase;
	id usernameDataBase;
	id passDataBase; 
	//end
    id appHost;


    id glblAlerPane;
    
   // id phpHost;

}


- (id) init {
	[super init];
	
	cgiServ = nil;
	//coloOran    = [CPColor colorWithRed:240.0/255.0 green:140.0/255.0 blue:10.0/255.0 alpha:1.0];
	coloOran    = [CPColor colorWithRed:209.0/255.0 green:137.0/255.0 blue:158.0/255.0 alpha:1.0];
	//coloRed     = [CPColor colorWithRed:220.0/255.0 green:100.0/255.0 blue:0.0/255.0 alpha:1.0];
	coloRed     = [CPColor colorWithRed:216.0/255.0 green:146.0/255.0 blue:62.0/255.0 alpha:1.0];
	//coloBlue    = [CPColor colorWithRed:0/255.0 green:120.0/255.0 blue:175.0/255.0 alpha:1.0];
	coloBlue    = [CPColor colorWithRed:20/255.0 green:70.0/255.0 blue:120.0/255.0 alpha:1.0];
	coloDefa    = [CPColor colorWithRed:134./255. green:140.0/255.0 blue:160.0/255.0 alpha:1.0];
	//coloDefa    = [CPColor colorWithRed:55./255. green:65.0/255.0 blue:75.0/255.0 alpha:1.0];
	//coloDefaLite= [CPColor colorWithRed:60./255. green:70.0/255.0 blue:80.0/255.0 alpha:1.0];
	//coloDefaBrig= [CPColor colorWithRed:90./255. green:100.0/255.0 blue:110.0/255.0 alpha:1.0];
	coloDefaLite= [CPColor colorWithRed:70/255.0 green:102.0/255.0 blue:78.0/255.0 alpha:1.0];
	coloDefaBrig= [CPColor colorWithRed:70/255.0 green:102.0/255.0 blue:78.0/255.0 alpha:1.0];
	coloGree    = [CPColor colorWithRed:0/255.0 green:175.0/255.0 blue:120.0/255.0 alpha:1.0];
	coloYell	= [CPColor colorWithRed:240.0/255.0 green:200.0/255.0 blue:100.0/255.0 alpha:1.0];
	coloMess	= coloBlue;

	dataBase= nil;

	heigOran= 5.;
	heigBlue= 6.;
	
	isLogi = false;
 	appHost = document.location.pathname;

 	glblAlerPane = [[RMAlertPanel alloc] init];
	return self;
}
	
	

- (void) addBanners:(CPView)paneContView heightBlue:(CGFloat)heigBlueTemp heightOrange:(CGFloat)heigOranTemp {

	if ( heigBlueTemp<0. )
		heigBlueTemp= heigBlue;
	if ( heigOranTemp<0. )
		heigOranTemp= heigOran;

	// franja naranja
	var fram= CPRectMake(0,heigBlueTemp,2000,heigOranTemp);
	var bannView= [[CPView alloc] initWithFrame:fram];
	[bannView setBackgroundColor:coloOran];
	[paneContView addSubview:bannView];

	// franja roja (debajo de la naranja)
	fram= CPRectMake(0,heigBlueTemp+heigOranTemp/2.,2000,heigOranTemp/2.);
	bannView= [[CPView alloc] initWithFrame:fram];
	[bannView setBackgroundColor:coloRed];
	[paneContView addSubview:bannView];

	// franja azul (u otro color), encima de la roja
	fram= CPRectMake(0,0,2000,heigBlueTemp);
	bannView= [[CPView alloc] initWithFrame:fram];
	[bannView setBackgroundColor:coloBlue];
	[paneContView addSubview:bannView];
}



- (id) addButton:(CPString)aString TFPosX:(int)aXcoord TFPosY:(int)aYcoord TFWidth:(int)aWidth TFHeight:(int)aHeight VView:(CPView)aView sizeToFit:(BOOL)Size2Fit Action:(SEL)anAction  {
	var Button = [[CPButton alloc] initWithFrame:CGRectMake(aXcoord, aYcoord,aWidth,aHeight)]; 
	[Button setTitle:aString];
	if ( Size2Fit ) {
		[Button sizeToFit];
	}
	[Button setAction:anAction];
	[Button setTarget:self];		
	[aView addSubview:Button]; 
	return Button;
}



- (void) addLogo:(CPView)contView title:(CPString)titl backgroundColor:(CPColor)colo1 :(CPColor)colo2 imageName:(CPString)imagName {

	// franja Logo
	var contFram= [contView frame];
	var fram= CPRectMake((contFram.size.width-500.)/2.,200.,500,240.);
	messView= [[CPView alloc] initWithFrame:fram];

	[messView setBackgroundColor:coloBlue];

	fram= CPRectMake(2.,2.,496.,236.);
	var messViewInte= [[CPView alloc] initWithFrame:fram];
	[messViewInte setBackgroundColor:coloOran];
	[messView addSubview:messViewInte];

	fram= CPRectMake(2.,2.,492.,232.);
	var messViewInne= [[CPImageView alloc] initWithFrame:fram];
	[messViewInte addSubview:messViewInne];

	//console.log("colo1 = "+colo1);
	//console.log("colo2 = "+colo2);

	if ( colo1 && !colo2 ) {
		[messViewInne setBackgroundColor:coloMess];
	}
	else if ( colo1 && colo2 ) {
		var numb= 40;

		var colo1Red = [colo1 redComponent];
		var colo1Gree= [colo1 greenComponent];
		var colo1Blue= [colo1 blueComponent];
		var colo2Red = [colo2 redComponent];
		var colo2Gree= [colo2 greenComponent];
		var colo2Blue= [colo2 blueComponent];
		var redIncr  = (colo2Red - colo1Red)/numb;
		var greeIncr = (colo2Gree - colo1Gree)/numb;
		var blueIncr = (colo2Blue - colo1Blue)/numb;

		var incr1= 232./numb;
		var incr2= 232./(numb-1);
		var i;
		for ( i=0; i<numb; i++ ) {
			fram= CPRectMake(0.,i*incr1,492.,incr2);
			var bandView= [[CPView alloc] initWithFrame:fram];
			var bandColo= [CPColor colorWithCalibratedRed:colo1Red+i*redIncr green:colo1Gree+i*greeIncr blue:colo1Blue+i*blueIncr alpha:1.];
			[bandView setBackgroundColor:bandColo];
			[messViewInne addSubview:bandView];
			
			//console.log("red="+(colo1Red+i*redIncr)+"  green="+(colo1Gree+i*greeIncr)+"  blue="+(colo1Blue+i*blueIncr));
		}
	}
	if ( imagName ) {
		var imag = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:imagName] size:CPSizeMake(500, 240/2.)];
		[messViewInne setImage:imag];
	}

	fram= CPRectMake(20.,20.,460.,60.);
	var messText= [[CPTextField alloc] initWithFrame:fram];
	var font= [CPFont fontWithName:@"Arial" size:42];
	[messText setFont:font];
	[messText setTextColor:[CPColor whiteColor]];
	[messText setTextShadowColor:[CPColor grayColor]];
	[messText setTextShadowOffset:CGSizeMake(2,2)];
	[messText setStringValue:titl];
	[messViewInne addSubview:messText];

	fram= CPRectMake(20.,100.,300.,24.);
	messText= [[CPTextField alloc] initWithFrame:fram];
	font= [CPFont fontWithName:@"Arial" size:10];
	[messText setFont:font];
	[messText setTextColor:[CPColor blackColor]];
	[messText setTextShadowColor:[CPColor grayColor]];
	[messText setStringValue:@"Copyright (c) 2017 Route Miner S.A."];
	[messViewInne addSubview:messText];

        fram= CPRectMake(150.,150.,200.,20.);
        userFiel= [[CPTextField alloc] initWithFrame:fram];
	    [userFiel setPlaceholderString:@"usuario"];
	    //[userFiel setStringValue:@"orkincr"];
        //[userFiel setBezeled:YES];
        [userFiel setBordered:YES];
        [userFiel setEditable:YES];
        [userFiel setFont:[CPFont boldSystemFontOfSize:12.0]];
        [userFiel setTextColor:[CPColor lightGrayColor]];
        [userFiel setDrawsBackground:YES];
        [userFiel setBackgroundColor:[CPColor whiteColor]];
        [messViewInne addSubview:userFiel];

        fram= CPRectMake(150.,180.,200.,20.);
        passFiel= [[CPSecureTextField alloc] initWithFrame:fram];
		[passFiel setPlaceholderString:@"contraseña"];
		//[passFiel setStringValue:@"orkincrpassw"];
        //[passFiel setBezeled:YES];
        [passFiel setBordered:YES];
        [passFiel setEditable:YES];
        [passFiel setFont:[CPFont boldSystemFontOfSize:12.0]];
        [passFiel setTextColor:[CPColor lightGrayColor]];
        [passFiel setDrawsBackground:YES];
        [passFiel setBackgroundColor:[CPColor whiteColor]];
		[passFiel setTarget:self];
	//	[passFiel setAction:@selector(login:)];
        [messViewInne addSubview:passFiel];

	[userFiel setNextKeyView:passFiel];

	//fram= CPRectMake(390.,180.,80.,24.);
	//var messButt= [[CPButton alloc] initWithFrame:fram];
	var messButt = [[CPButton alloc] initWithFrame: CGRectMake(390,180,80,24)];
	[messButt setTitle:@"Ingresar"];
	[messButt setTarget:self];
	[messButt setAction:@selector(messageViewCloseTest:)];
	[messViewInne addSubview:messButt];

	fram= CPRectMake(25.,140.,90.,70.);
	var imagView= [[CPImageView alloc] initWithFrame:fram];

	var imag = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"routeMiner.png"] size:CPSizeMake(30, 30)];
	[imagView setImage:imag];
	[messViewInne addSubview:imagView];

	fram= CPRectMake(30.,30.,128.,70.);
	var imagView= [[CPImageView alloc] initWithFrame:fram];
	[imagView setImageScaling:CPImageScaleAxesIndependently];
	var imag = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"orkinlogo.png"] size:CPSizeMake(30, 30)];
	[imagView setImage:imag];
	[contView addSubview:imagView];
	
	[contView addSubview:messView];
}



- (id) addTextField:(CPString)aString TFPosX:(int)aXcoord TFPosY:(int)aYcoord TFWidth:(int)aWidth TFHeight:(int)aHeight VView:(CPView)aView Editable:(BOOL)edit {
	var textFiel = [[CPTextField alloc] initWithFrame:CGRectMake(aXcoord,aYcoord,aWidth,aHeight)];
	if ( edit) {
		[textFiel setBezeled:YES];
		[textFiel setBordered:YES];
		[textFiel setEditable:YES];
	}
	[textFiel setStringValue:aString];
	[textFiel setFont:[CPFont boldSystemFontOfSize:12.0]];
	[textFiel setTextColor:[CPColor darkGrayColor]];
	if ( !edit && (aWidth==0 || aHeight==0) )
		[textFiel sizeToFit];
	[aView addSubview:textFiel];
	return textFiel;
}



- (id) addPopupButton:(CPString)aString TFPosX:(int)aXcoord TFPosY:(int)aYcoord TFWidth:(int)aWidth TFHeight:(int)aHeight VView:(CPView)aView pullsDown:(BOOL)pullDown {
	var PopUpButton = [[CPPopUpButton alloc] initWithFrame:CGRectMake(aXcoord, aYcoord,aWidth,aHeight) pullsDown:pullDown]; 
	[PopUpButton setTitle:aString];
	[PopUpButton setTarget:self];
	[aView addSubview:PopUpButton]; 
	return PopUpButton;
}



- (id) addHelpIcon:(CPString)aImageFile TFPosX:(int)aXcoord TFPosY:(int)aYcoord TFWidth:(int)aWidth TFHeight:(int)aHeight VView:(CPView)aView Action:(SEL)anAction {
	var Button = [[CPButton alloc] initWithFrame:CGRectMake(aXcoord, aYcoord,aWidth,aHeight)]; 
	[Button setAction:anAction];
	[Button setBordered:NO];
	[Button setImagePosition:CPImageAbove];
	[Button setTarget:self];		
	[aView addSubview:Button]; 
	Button._DOMElement.style.cursor = "pointer";
	var  imagOn = [[CPImage alloc] initWithContentsOfFile:aImageFile];
	//[imagOn setImageScaling:CPImageScaleProportionallyDown];
	[imagOn setSize:CGSizeMake(16,16)];
    [Button setImage:imagOn];
	return Button;	
}



- (id) appController {
	return appCont;
}



- (void) appControllerSet:(id)appContNew {
	appCont = appContNew;
}



- (id) cgiHost {
	return cgiHost;
}



- (id) phpHost {
   return phpHost;
}



- (id) cgiServ {
	return cgiServ;
}


- (void) cgiSetHost:(id)cgiHostNew server:(id)cgiServNew {
	cgiHost = cgiHostNew;
	cgiServ = cgiServNew;
}

//getorgaCode



- (CPDate) dateConvertion:(CPString)_date hours:(CPString)_hours minutes:(CPString)_minu offSet:(CPString)_offSet {
	var dateStarFull = [CPString stringWithFormat:@"%@ %@:%@:00 -0600",_date,_hours,_minu];
 	var dateStar = [[CPDate alloc] initWithString:dateStarFull];
 	//Make a Jump
 	var respDate = [[CPDate alloc] initWithTimeInterval:_offSet*60. sinceDate:dateStar];
 	return respDate;
}



- (id) getOrgaCode {
	return  orgaCode;
}

- (id) getDataBase {
	return  dataBase;
}


- (id) getcgiHost {
	return cgiHost;
}


- (id) getcgiServ {
	return cgiServ;
}

/*
- (id) getModel {
	return mode;
}
*/


- (CPString) getRandomColor {

    var letters = [CPArray arrayWithObjects:@"B","C","D","E","F"];
    var _colo   = @"#";
    for (var i = 0; i < 6; i++ ) {
        var ranI = Math.floor(Math.random() * [letters count]);
        _colo   += [letters objectAtIndex:ranI];
    }
    return _colo;
   
}



- (id) mapController {
	return mapCont;
}



- (void) mapControllerSet:(id)mapContNew {
	mapCont = mapContNew;
}



//add 207-02-28
- (id) messageViewCloseTest:(id)sender {
    accoUser = [userFiel stringValue];
    accoPass = [passFiel stringValue];
    var DBLogi = "riglobal";
    var userTabl = "user";
    var connTabl= "connection";
    var clieTabl = "client";
    var pass = "";
    //var role, clie, prod,nameDataBase, hostDataBase, usernameDataBase, passDataBase; 

    if ( ([accoUser length] <1 ) || ( [accoPass length] < 1) ) {
    	//alert("Datos incompletos");
    	[glblAlerPane showWithMessage:@"Datos incompletos" info:@"Revise la informacion suministrada"];
    	//
    	[userFiel setStringValue:@""];
        [passFiel setStringValue:@""];
    	isLogi = false;
        return messView;
	}
	// SELECT password,fkRoleId,fkClientId,fkProduct FROM test.user where name = 'orkin' ;
	var quer  = [CPString stringWithFormat:@"SELECT password,fkRoleId,fkClientId,fkProduct FROM %@.%@ WHERE name='%@' limit 1",DBLogi,userTabl,accoUser];
	//alert("query=" + quer);
	var resuArra = [self query:quer];
	//alert("Resu = " + resuArra);
	if ([resuArra count ] == 0){
		//alert("Usuario no registrado");
        [glblAlerPane showWithMessage:@"Usuario no registrado" info:@"Intentelo nuevamente"];
		[userFiel setStringValue:@""];
        [passFiel setStringValue:@""];
        isLogi = false;
		return;
	}
	//var coun = [ resuArra count];
	//alert("count=" + coun);
	//for (var i = 0; i < coun; i++){
		var valuList = [ resuArra[0] valueList];
		pass = valuList[0]; 
		role = valuList[1]; 
		clie = valuList[2]; 
		prod = valuList[3]; 
		//alert("pass=" + pass + "  role=" + valuList[1]  + " clienID= " + clie + " productId= " + prod );
	//}
	if( accoPass == pass ){
		//alert("Correct user");
		
	   //SELECT * FROM test.connection WHERE idConnection = ( SELECT fkConnectionId FROM test.client WHERE idClient = 282 );
		var quer = [CPString stringWithFormat:@"SELECT * FROM %@.%@ WHERE idConnection = ( SELECT fkConnectionId FROM %@.%@  WHERE idClient = %@ ) LIMIT 1",DBLogi,connTabl,DBLogi,clieTabl,clie];
	    //alert("query= " +  quer);
		var arra = [self query:quer];
		if ( [ arra count] == 0){
			isLogi = false;
			return;
		}
			
		var valuList = [arra[0] valueList];
		 dataBase         = valuList[1];
		 //cgiHost          = valuList[2];
		 usernameDataBase = valuList[3];
		 passDataBase     = valuList[4];
         dataBase = "rmscheduler_orkincr";//[dataBase stringByReplacingOccurrencesOfString:@"ricore" withString:@"rmscheduler"];
         cgiHost = [cgiHost stringByReplacingOccurrencesOfString:@":3306" withString:@""];
		 //cgiHost = hostDataBase;		
            // alert("dataBase= " + dataBase + " cgiHost= " + cgiHost + " usernameDataBase= " + usernameDataBase + " passDataBase= " + passDataBase );
        //mode = [[Model alloc] init:self]; 
            
		isLogi = true;
		//dataBase= accoUser;
		useTabl = "tbl_"+accoUser + "Event";
		eventTabl = "eventsPermanent";
		if ( messView )
			[messView removeFromSuperview];

		messView = NULL;
		//var div = document.createElement("div");
		//div.id = "container";
		//div.style.display = "none";
		//div.style.z-index = "100";
		//document.body.appendChild(div);

		quer = [CPString stringWithFormat:@"SELECT attributeName,attributeValue FROM %@.userAttributes where objectName = '%@' order by id;",DBLogi,accoUser];
	    //alert("query= " +  quer);
		var arraAttr = [self query:quer];

		var coun = [arraAttr count];
		if ( coun > 0){
			for ( var i=0; i<coun; i++ ) {
			var valuList = [arraAttr[i] valueList];
			var attrName = valuList[0];
			var attrValue = valuList[1];
				
				if(attrName == 'backgroundColor'){
					var comp = [attrValue componentsSeparatedByString:@"#SC#"];
					var coloBack    = [CPColor colorWithRed:comp[0]/255.0 green:comp[1]/255.0 blue:comp[2]/255.0 alpha:1.0];
					[appCont setColorBackground:coloBack];
					[appCont changeColorBackground:coloBack];

				}else if(attrName == 'windowColor'){
					var comp = [attrValue componentsSeparatedByString:@"#SC#"];
					var coloWind    = [CPColor colorWithRed:comp[0]/255.0 green:comp[1]/255.0 blue:comp[2]/255.0 alpha:1.0];
					[appCont setColorWindow:coloWind];
				}
			
			}
		}


		return messView;
		
	}else{
		[userFiel setStringValue:@""];
        [passFiel setStringValue:@""];
		isLogi = false;
		//alert("Datos incorrectos");
		[glblAlerPane showWithMessage:@"Datos incorrectos" info:@"Intentelo nuevamente"];
	}
	
}


/*
//back up 207-02-28
- (id) messageViewClose:(id) sender {
    accoUser = [userFiel stringValue];
    accoPass = [passFiel stringValue];
    
    alert("MessageView: user= " +accoUser + " pass= " + accoPass );

    if ( [accoUser length]<1 ) {
    	alert("Please review your user ("+accoUser+") or password ("+[passFiel stringValue]+","+accoPass+") information and try again.");
        return messView;
	}
	
	if ( ! [accoPass isEqualToString:@"route1Miner2"] ) {
    	alert("Please review your user ("+accoUser+") or password ("+[passFiel stringValue]+","+accoPass+") information and try again.");
        return messView;
	}

	dataBase= accoUser;

	if ( messView )
		[messView removeFromSuperview];

	messView= NULL;
	return messView;
}
*/


- (id) organizationCode {
	return orgaCode;
}


- (void) organizationCodeSet:(id)orgaCodeNew {
	orgaCode = orgaCodeNew;
}

- (id) organizationId {
	return orgaId;
}


- (void) organizationIdSet:(id)orgaIdNew {
	orgaId = orgaIdNew;
}

- (void) countryCodeSet:(id)countryCodeNew {
	countryCode = countryCodeNew;
}

- (void) setColorBackground:(id)color {
	coloDefa = color;
}

- (void) setColorWindow:(id)color {
	coloDefaBrig = color;
	coloDefaLite = color;
}



- (CPArray) query:(CPString)quer {
        var srvrSide = @"cgi-bin";
        srvrSide = @"rm_webservices/index.php/orkin";
        //        var _post = @"/POST";
	var url = [CPString stringWithFormat:@"http://%@%@%@/%@",phpHost,appHost,srvrSide,cgiServ];
	//console.log("MY URL: " + url);	
	var dataBaseConn = [[ServerConnector alloc] initWithURL:url];
	if ( !dataBaseConn ) {
		[glblAlerPane showWithMessage:@"Opps" info:@"Hubo problemas con la conexion a la base de datos... espere y reintente"];
		//alert("No connection with the database could be established.");
		return nil;
	}

    console.log(quer);
	//var quer64  = [[CPData dataWithString:quer] base64];
	if(appCont.accoUser == NULL){
		appCont.accoUser = "";
	}
	quer = [quer stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
	var querNew = [CPString stringWithFormat:@"query=%@&user=%@",quer,appCont.accoUser];

    //console.log(querNew);
    var XML= [dataBaseConn obtainFromServerXML:querNew];
	var regiList= [XML elements];
	[dataBaseConn release];
	return regiList;
}


- (CPArray) query:(CPString)quer newCgiServ:(CPString)_newCgiServ{
        var srvrSide = @"cgi-bin";
        srvrSide = @"rm_webservices/index.php/orkin";
        //        var _post = @"/POST";
	var url = [CPString stringWithFormat:@"http://%@%@%@/%@",phpHost,appHost,srvrSide,_newCgiServ];
	//console.log("MY URL: " + url);	
	var dataBaseConn = [[ServerConnector alloc] initWithURL:url];
	if ( !dataBaseConn ) {
		[glblAlerPane showWithMessage:@"Opps" info:@"Hubo problemas con la conexion a la base de datos... espere y reintente"];
		//alert("No connection with the database could be established.");
		return nil;
	}
    //console.log(quer);
	var quer64 = [[CPData dataWithString:quer] base64];
	var querNew = [CPString stringWithFormat:@"query=%@",escape(quer64)];

//console.log(querNew);
   var XML= [dataBaseConn obtainFromServerXML:querNew];
        //alert(XML);

	var regiList= [XML elements];
	[dataBaseConn release];
	return regiList;
}



- (void) sendEmailGET:(CPString)email urlLink:(CPString)urlLink commEmai:(CPString)commEmai{
    
    //console.log("RMControllerObject\n\nEmail "+ email + "\n\nlink " + urlLink + "\n\nComentario " +  commEmai + "\n\n");
    var finaEmail     = "";
    var finaUrlLink   = "";
    var finaCommEmai  = "";    
    
    //
    
    ///*
    var finaHost     = "mail.orkincr.com";
    var finaUser     = "dastua@orkincr.com";
    //var finaPass     = "*******"; 
    var finaPass	 = "Da2015a%%";
    //*/
    /*
    var finaHost     = "mail.route-miner.com";
    var finaUser     = "alonso.villanueva@route-miner.com";
    var finaPass     = "alonso123"; 
    */
//    var finaPass	 = "Da2015a%%";
    
     
    var finaNameUser = "ORKIN";     
    var finaSubj     = "Reporteria Orkin"; 
    
	if (email != "" ){
		finaEmail = email;
	}else{
		return;
	}
	if (urlLink != ""  ){
		finaUrlLink = urlLink;
	}
	if (commEmai != "" ){
		finaCommEmai = commEmai;
	}
	//alert(finaCommEmai);
    var srvrSide = @"";
    srvrSide = @"rm_webservices/index.php/mailsender/sendEmailPOST";
	var url = [CPString stringWithFormat:@"http://%@%@%@",phpHost,appHost,srvrSide];
	var para = "email=" + finaEmail + "&url=" + finaUrlLink + "&comm=" + finaCommEmai + "&host=" +  finaHost + "&user=" +  finaUser + "&nameUser="+ finaNameUser + "&pass=" +  finaPass + "&subj=" + finaSubj; 
	//console.log("URL = " +  url + "?" + para);
	///*
	//GET
	var settings = {
   	 	"async": true,
    	"crossDomain": true,
	    "url": url,
    	"method": "POST",
	    "data": {
	    	"email": finaEmail,
		    "url": finaUrlLink,
	    	"comm": finaCommEmai,
	    	"host": finaHost,
	    	"user": finaUser,
	    	"nameUser": finaNameUser,
	    	"pass": finaPass,
	    	"subj": finaSubj,
	    	"url": finaUrlLink
     	}
  	}
/*
	var settings = {
   	 	"async": true,
    	"crossDomain": true,
	    "url": url + "?" + para,
    	"method": "GET",
	    "headers": {
    	"email": finaEmail,
	    "url": finaUrlLink,
    	"comm": finaCommEmai,
	    "host": finaHost,
    	"user": finaUser,
	    "pass": finaPass,
    	"subj": finaSubj
     }
  }
*/
	$.ajax(settings).done(function (response) {
	  console.log(response);
	  //alert("Response " + response );
	});
    //*/
    
  /*  
  //POST 
	var form = new FormData();
	form.append("email", finaEmail);
	form.append("url", finaUrlLink);
	form.append("comm", finaCommEmai);

	var settings = {
	  "async": true,
	  "crossDomain": true,
	  "url": url,
	  "method": "POST",
	  "processData": false,
	  "contentType": false,
	  "mimeType": "multipart/form-data",
	  "data": form
	}


	$.ajax(settings).done(function (response) {
		  console.log(response);
	});
 */  

}




- (void) queryAsynchronously:(CPString)querNew completionHandler:(Function)hand {
	var url= [CPString stringWithFormat:@"http://%@/cgi-bin/%@",cgiHost,cgiServ];
	var dataBaseConn= [[ServerConnector alloc] initWithURL:url];
	if ( !dataBaseConn ) {
		[glblAlerPane showWithMessage:@"Opps" info:@"IHubo problemas con la conexion a la base de datos... espere y reintente"];
		//alert("No connection with the database could be established.");
		return nil;
	}
	[dataBaseConn obtainAsynchronouslyFromServerXML:querNew completionHandler:hand];
}



- (CPArray) query:(CPString)quer withCGI:(CPString)cgiServTemp {
	var url= [CPString stringWithFormat:@"http://%@/cgi-bin/%@",cgiHost,cgiServTemp];
	var dataBaseConn= [[ServerConnector alloc] initWithURL:url];
	if ( !dataBaseConn ) {
		[glblAlerPane showWithMessage:@"Opps" info:@"Hubo problemas con la conexion a la base de datos... espere y reintente"];
		//alert("No connection with the database could be established.");
		return nil;
	}
	var querNew = quer;
	querNew = [querNew stringByReplacingOccurrencesOfString:@"#" withString:@"&num;"];
	var XML= [dataBaseConn obtainFromServerXML:querNew];
	var regiList= [XML elements];
	[dataBaseConn release];
	return regiList;
}



@end
