/*
-- USE this to set ColdFusion Cookies
@_setThis = value to be saved
@_setAs = ColdFusion Cookie name..i.e., "COOKIE.xxxxxxx"..*/
function setCookieAs( _setThis, _setAs ){

	var _info = "setThis=" + _setThis + "&setAs=" + _setAs ;

	$.ajax({
		type: 'POST',
		url: '/IMS/includes/SetThis.cfm',
		data: _info,
		success: function( newCookieData ){
			console.log( "Returned : " + newCookieData );
		}
	});

}
/* 	end setCookieAs 	*/

// Called from "/Profile.cfm" and "/ProcessMTR.cfm" in "G:\DAO_www\" to process "Motion to Revoke"..
function DA_processMTR( cid, _href ){
	var _uid = getUID();

	/*if( confirm('Did the form print correctly?') ){*/

		$.getJSON(
			"/public/site/updateMTR.cfm",
			{
			"_caseFLID"	: cid,
			"_statusCode"	: "MTR",
			"_uID" 		: _uid
			},
			function(data){

				if( data.success == 1 ){
	
					console.log( "Status update finished successfully!" );
					document.location.href = _href;
	
				} else {
	
					console.log( "Errors encountered. Check variables." );
	
				}


		});
	/*}*/

}
/*		end DA_processMTR		*/

// Called from /Chat/MyConvList.cfm in CORE to either get new chat or join existing chat..
function getNewChatWindow(passedIn) {
		var _windowName = 'ChatWindow_' + getUID();

		if( isNaN(passedIn) ) {
			// If not numeric, it should be 'chatConvFLID-chatUserFLID-windowName'..split it at the '-'
			var _urlArray = passedIn.split('-');

			// Get the integers passed within the string..
			var _ccid = _urlArray[0];
			var _cuid = _urlArray[1];
			var _wind = _urlArray[2];

			var _URLs = '?rejoin=' + true + '&convFLID=' + _ccid + '&userFLID=' + _cuid;

				// Open new chat window and pass 'rejoin chat' vars and window name..
				MyWindow=window.open('/chat/PopUp.cfm' + _URLs, _wind,'toolbar=no,location=no,directories=no, status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=550,left=50,top=50');

		} else {

			if( passedIn == 0 ) {

				// Open Brand New Chat Window..
				MyWindow=window.open('/chat/PopUp.cfm',_windowName,'toolbar=no,location=no,directories=no, status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=550,left=50,top=50');

			} else {
				// Build string with URL param 'passedIn' to join existing conversation..
				var _url = '?convFLID=' + passedIn;

				// Open Existing Conversation in New Window..
				MyWindow=window.open('/chat/PopUp.cfm' + _url, _windowName,'toolbar=no,location=no,directories=no, status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=550,left=50,top=50');

			}

			// Write this window's name to Firebug's console for testing..
			//console.log('Chat Window Name: ' + _windowName);
			
		}
}
/*		\getNewChatWindow		*/

function getUID(){
     var dateObject = new Date();
     var uniqueID =
          dateObject.getFullYear() + '' +
          dateObject.getMonth() + '' +
          dateObject.getDate() + '' +
          dateObject.getTime();

     return uniqueID;
}

var g_LockOutGliderBit = 0;

function testFn(_obj){
	alert('got test in udf.js: '+_obj);
}
function set_globalLockOutGliderBit(mode){
	g_LockOutGliderBit = mode;
}
function get_globalLockOutGliderBit(){
	return g_LockOutGliderBit;
}
function profile_setLastTabID(_obj){
	http_send_SetSessionVar('profile.lastTabID',_obj.id);
}
//send image to mold
	function http_send_imageToMold(_fPathAndType) {
		var url = '/scripts/uploadify/uploadify_format.cfm?fPathAndType='+_fPathAndType;
		http.open("GET", url , true);	
		http.onreadystatechange = http_respond_imageToMold;
		http.send(null);
	}
	function http_respond_imageToMold() {
		if (http.readyState == 4) {
			_success = http.responseText.indexOf('true');
			if(_success > 0){
				location.reload(true);				
			}
		}
	}
//end: set session var

//get var for uploadify
	function http_send_uploadify_getCFVar(_name) {
		var url = '/assets/act_getCFVar.cfm?name='+_name;
		http.open("GET", url , true);	
		http.onreadystatechange = http_respond_uploadify_getCFVar;
		http.send(null);
	}
	
	function http_respond_uploadify_getCFVar() {
		if (http.readyState == 4) {
			alert('x: '+http.responseText);
		}
	}
//end: get any var
//get any var
	function http_send_getCFVar(_name) {
		var url = '/assets/act_getCFVar.cfm?name='+_name;
		http.open("GET", url , true);	
		http.onreadystatechange = http_respond_getCFVar;
		http.send(null);
	}
	
	function http_respond_getCFVar() {
		if (http.readyState == 4) {
			alert(http.responseText);
		}
	}
//end: get any var
//set session var
	function http_send_SetSessionVar(_name,_val) {
		var url = '/assets/act_setSessionVar.cfm?name='+_name+'&value='+_val;
		http.open("GET", url , true);	
		http.onreadystatechange = http_respond_SetSessionVar;
		http.send(null);
	}
	
	function http_respond_SetSessionVar() {
		if (http.readyState == 4) {
			//alert(http.responseText);
		}
	}
//end: set session var

//GET session var
	function http_send_getSessionVar(_name) {
		var url = '/assets/act_getSessionVar.cfm?name='+_name;
		http.open("GET", url , true);	
		http.onreadystatechange = http_respond_getSessionVar;
		http.send(null);
	}
	
	function http_respond_getSessionVar() {
		if (http.readyState == 4) {
			//alert(http.responseText);
		}
	}
//end: GET session var

///delete file
function http_send_delete_file(path) {
	var url = '/assets/act_delete_File.cfm?path='+path;
	http.open("GET", url , true);	
	http.onreadystatechange = http_respond_delete_file;
	http.send(null);
}

function http_respond_delete_file() {
	if (http.readyState == 4) {
		if(trim(http.responseText) == 'true'){
			alert('File Deleted.');
			location.reload(true);
		}else{
			alert('File was not deleted.'+http.responseText);
		}
	}
}
///end: delete file

///delete content
function http_send_content_delete(coid) {
	var url = '/assets/act_content_delete.cfm?coid='+coid;
	http.open("GET", url , true);	
	http.onreadystatechange = http_respond_content_delete;
	http.send(null);
}

function http_respond_content_delete() {
	if (http.readyState == 4) {
		if(trim(http.responseText) == 'true'){
			alert('Content deleted.');
			location.reload(true);
		}else{
			alert('Content was not deleted.');
		}
	}
}
///end: delete content

///add to my network
function http_send_addToMyNetwork(cid,nwf,nwft) {
	var url = '/assets/act_addToNetwork.cfm?cid='+cid+'&nwf='+nwf+'&nwft='+nwft;
	http.open("GET", url , true);	
	http.onreadystatechange = http_respond_addToMyNetwork;
	http.send(null);
}

function http_respond_addToMyNetwork() {
	if (http.readyState == 4) {
		alert(http.responseText);
	}
}
///end:add to my network

function testParent(_str) {
		alert(_str);
}
function iframe_manual_resize(_objID,_width,_height){
	_frame = document.getElementById(_objID) ;
	
	//check that frame exists
	if (_frame.contentDocument){
		frameDoc = _frame.contentDocument;
	}else{ // bad IE  ;) (reference it by array ; obj id)
		frameDoc = document.frames[_frame.id].document;
	}
	_frame.height = _height;//_frame.contentWindow.document.body.scrollHeight+padH;
	_frame.width = _width;//_frame.contentWindow.document.body.scrollWidth+padW;
	centerPopup();	
}


//<iframe src="www.xxxxxx.com" onload="iframe_resize(this);" width="500"></iframe> 
function iframe_resize(_obj,padW,padH){
	var _frame = _obj;
	
	if(padW == undefined){padW=20;}
	if(padH == undefined){padH=20;}
	
	//check that frame exists
	if (_frame.contentDocument){
		frameDoc = _frame.contentDocument;
	}else{ // bad IE  ;) (reference it by array ; obj id)
		frameDoc = document.frames[_frame.id].document;
	}
	_frame.height = _frame.contentWindow.document.body.scrollHeight+padH;
	//_frame.width = _frame.contentWindow.document.body.scrollWidth+padW;
}


function iframe_reload(_objID){
	_iframe = document.getElementById(_objID) ;
	_src = _iframe.contentWindow.location;
	
	_iframe.contentWindow.location = _src ;
}

///my interest group
function http_send_IG_CFL(cid,scIGHFLID,val) {
	var url = '/assets/actInterestGroup_CFL.cfm?cid='+cid+'&scIGHFLID='+scIGHFLID+'&val='+val;
	//alert(url);
	http.open("GET", url , true);	
	http.onreadystatechange = http_respond_IG_CFL;
	http.send(null);
}

function http_respond_IG_CFL() {
	if (http.readyState == 4) {
		//alert('-'+http.responseText+'-');
		if(trim(http.responseText) == 'true'){
			saveScrollCoordinates();
			iframe_reload('ifr_myigs');
		}else{
			//alert('false: resp: '+http.responseText);
		}
	}
}
///end: my interest group

function trackInputMaxLength(_input,_max,_outputID){
	var _ln =_input.value.length;
	if(_ln >= _max){
		_input.value = _input.value.substr(0,_max);
	}
	if(_outputID.length > 0){
		_outStr = _input.value.length+'/'+_max;
		writeDiv(_outputID,_outStr);
	}
}
function writeDiv(_outputID,_str){
	var _div = document.getElementById(_outputID);
	_div.innerHTML = _str;
}

function playMediaPopUp(meid){
	//alert('open media: '+meid);
	window.open('/podcast/PodcastPopUp.cfm?meid='+meid,'MyWindow1','toolbar=no,location=no,directories=no, status=no,menubar=no,scrollbars=no,resizable=no,width=600,height=600,left=50,top=50');
}
trim = function (_str){
	var ret = _str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	return ret;
}
function stripNonNumeric(str,textbox){
	var num = parseInt(str);
	if(isNaN(num)){
		textbox.value = '';		
	}else{
		textbox.value = num;
	}
}
function saveScrollCoordinates() {
	var toX= (document.all)?document.body.scrollLeft:window.pageXOffset;
	var toY= (document.all)?document.body.scrollTop:window.pageYOffset;
	//document.Form1.scrollx.value = (document.all)?document.body.scrollLeft:window.pageXOffset;
	//document.Form1.scrolly.value = (document.all)?document.body.scrollTop:window.pageYOffset;
	url="/includes/SetSessionVar.cfm?varName=scrollToPos&varValue="+toX+','+toY;
	http.open("GET", url , true);
	http.onreadystatechange = saveScrollCoordinates_response;		
	http.send(null);
}

function scrollToCoordinates(_coordX,_coordY) {
	//var v1= _coordX+','+_coordY;
	//window.scrollTo(#FORM.scrollx#, #FORM.scrolly#);
	window.scrollTo(_coordX,_coordY);
	clearScrollCoordinates();
}
function clearScrollCoordinates(){
	var url="/includes/SetSessionVar.cfm?varName=scrollToPos&varValue=0,0";
	http.open("GET", url , true);
	http.onreadystatechange = saveScrollCoordinates_response;
	http.send(null);
	return ' ';
}
function clearScrollCoordinates_response() {
	 if (http.readyState == 4) {
		//DO NOTHING
	}                    
}
function saveScrollCoordinates_response() {
	 if (http.readyState == 4) {
		//DO NOTHING
	}                    
}
function fixDate(str,textbox){
	//if date is "semi-formatted" (1/6/1987) this will pad the segments of a date 
	// changes: 1/6/87 to 01/06/1987
	var input =  textbox.value;
	var date = input.split('/');
	//var dString = textbox.value.replaceAll('/','-');
	if(date.length == 3){
		var mm = padL(date[0],2,'0');
		var dd = padL(date[1],2,'0');
		var yy = century(date[2]);
		//var yy = padL(date[2],4,'0');
		textbox.value = mm +'/'+ dd +'/'+ yy;
	}else{
		//if this is a bad date
		if(! isNaN(input)){
			//if it is a number
			if((input.length >= 6)){
				//,(input.length == 8)
				//add '/' to 6 or 8 characters
				_mm = input.substr(0,2);
				_dd = input.substr(2,2);
				_yy = century(String(input.substr(4,4)));
				_out = _mm+'/'+_dd+'/'+_yy;
				
				textbox.value = _out;
			}else{
				textbox.value = '';					
			}
		}else{
			textbox.value = '';
		}
	}
}

function replaceAllx(string,oldC,newC){
	var s = string;
	var o = oldC;   
	var n = newC; 
	var newS = '';
	
	for (var i = 0; i < s.length; i++) {  
		if(newS.substr(i,1)=='c'){
			newS += 'x'; 
		}else{
			newS += s.substr(i,1);  
		}
		//alert("'"+newS.substr(i,1)+"'");
	 }
	 //alert(newS);
	// alert(newS.substr(2,1));
	 //return 'ss';
}

function century(yy){	
	var yy = yy
	if(yy.length == 2){
		return '19'+yy;
	}else{
		return yy;
	}
}
function padR(string, count, char){
	var s = string;   
	var padLen = count - s.length;
	
	for (var i = 0; i < padLen; i++) {  
		 s += char;  
	 }  
	 //alert(tostring(2));
	 return s;
}


function padL(string, count, char){
	var s = string; 
	var rep = '' 
	var padLen = count - s.length;
	
	for (var i = 0; i < padLen; i++) {  
		rep += char;
	}  
		s = rep +s
	return s;
}


function repeatString(string, count){
	var s = string; 
	var newS = '';
	
	for (var i = 0; i < count; i++) {  
		newS += s;
	}  
	return newS;
}


//function DateAdd(objDate, strInterval, intIncrement)
//    {
//        if(typeof(objDate) == "string")
//        {
//            objDate = new Date(objDate);
// 
//            if (isNaN(objDate))
//            {
//                throw("DateAdd: Date is not a valid date");
//            }
//        }
//        else if(typeof(objDate) != "object" || objDate.constructor.toString().indexOf("Date()") == -1)
//        {
//            throw("DateAdd: First parameter must be a date object");
//        }
//        if(
//        strInterval != "M"
//        &amp;&amp; strInterval != "D"
//        &amp;&amp; strInterval != "Y"
//        &amp;&amp; strInterval != "h"
//        &amp;&amp; strInterval != "m"
//        &amp;&amp; strInterval != "uM"
//        &amp;&amp; strInterval != "uD"
//        &amp;&amp; strInterval != "uY"
//        &amp;&amp; strInterval != "uh"
//        &amp;&amp; strInterval != "um"
//        &amp;&amp; strInterval != "us"
//        )
//        {
//            throw("DateAdd: Second parameter must be M, D, Y, h, m, uM, uD, uY, uh, um or us");
//        }
// 
//        if(typeof(intIncrement) != "number")
//        {
//            throw("DateAdd: Third parameter must be a number");
//        }
// 
//        switch(strInterval)
//        {
//            case "M":
//            objDate.setMonth(parseInt(objDate.getMonth()) + parseInt(intIncrement));
//            break;
// 
//            case "D":
//            objDate.setDate(parseInt(objDate.getDate()) + parseInt(intIncrement));
//            break;
// 
//            case "Y":
//            objDate.setYear(parseInt(objDate.getYear()) + parseInt(intIncrement));
//            break;
// 
//            case "h":
//            objDate.setHours(parseInt(objDate.getHours()) + parseInt(intIncrement));
//            break;
// 
//            case "m":
//            objDate.setMinutes(parseInt(objDate.getMinutes()) + parseInt(intIncrement));
//            break;
// 
//            case "s":
//            objDate.setSeconds(parseInt(objDate.getSeconds()) + parseInt(intIncrement));
//            break;
// 
//            case "uM":
//            objDate.setUTCMonth(parseInt(objDate.getUTCMonth()) + parseInt(intIncrement));
//            break;
// 
//            case "uD":
//            objDate.setUTCDate(parseInt(objDate.getUTCDate()) + parseInt(intIncrement));
//            break;
// 
//            case "uY":
//            objDate.setUTCFullYear(parseInt(objDate.getUTCFullYear()) + parseInt(intIncrement));
//            break;
// 
//            case "uh":
//            objDate.setUTCHours(parseInt(objDate.getUTCHours()) + parseInt(intIncrement));
//            break;
// 
//            case "um":
//            objDate.setUTCMinutes(parseInt(objDate.getUTCMinutes()) + parseInt(intIncrement));
//            break;
// 
//            case "us":
//            objDate.setUTCSeconds(parseInt(objDate.getUTCSeconds()) + parseInt(intIncrement));
//            break;
//        }
//        return objDate;
//    }


///save my cart order qty
function http_add_to_cart(custFLID,MasterFLID,qty,uPrice) {
	var url = '/ims/cart/AddToCart.cfm?custFLID='+custFLID+'&MasterFLID='+MasterFLID+'&qty='+qty+'&uPrice='+uPrice;
	//alert(url);
	http.open("GET", url , true);	
	http.onreadystatechange = http_respond_add_to_cart;
	http.send(null);
}

function http_respond_add_to_cart() {
	if (http.readyState == 4) {
		//alert('-'+http.responseText+'-');
		if(trim(http.responseText) == 'true'){
			//saveScrollCoordinates();
			//iframe_reload('ifr_myigs');
		}else{
			//alert('false: resp: '+http.responseText);
		}
	}
}
///end: my interest group

