//## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  SITE CONFIGURATIN !!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// DB initialization 
var dbArray = new Array();
var dbreport;
var recordcount;
var coloumcount;

// Ajax initialization 
	var cp = new cpaint();
	cp.set_debug(false);			
	cp.set_response_type('XML');	

//##!!!!!!!!!!!!!!!!!!!!!!!!!!   My FUNCTION ARCHIVE  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//!!!!!!!!! Executer Databse

var dbLloaded=true;

function executeDB(sql){
		var processScriptUrl=baseurl+'ajax/myphpajax.php';
		cp.call(processScriptUrl,'executeDB',return_value,sql);
	
}
	
function return_value(result){
				
		dbreport=result.getElementsByTagName('dbreport').item(0).firstChild.data;
		
		if (dbreport=='1'){
			// GET How many row fetch
			recordcount=result.getElementsByTagName('recordcount').item(0).firstChild.data;
			coloumcount=result.getElementsByTagName('coloumcount').item(0).firstChild.data;

			//Population My DB Values							
				for( i=0;i<recordcount;i++){
					dbArray[i]=new Array(recordcount);
					for( ii=0;ii<coloumcount;ii++){
						dbArray[i][ii]=result.getElementsByTagName('dbvalue'+i+ii).item(0).firstChild.data;															
					}
				}
				
				
		}


dbLoaded = false;
							
															
}
//END 

//!!!!!!!Insert data in to  table HTML patge

	function insertInToTable(tblId, varRow, varCell, varData){
		try{
			var x=document.getElementById(tblId).rows[varRow].cells;
			x[varCell].innerHTML=varData;
			return false;
		}
		catch(Err){
			return false;
		}
	}

//END 



// !!!!!! Input validation empty

	function txtBoxValidation(myId,defaultColor,errColor){
		
		// # My property
		try{	
			me=document.getElementById(myId);

			if(me.value==""){	
				me.style.background=errColor;
				me.setFocus;
				return false;
			}
			else{
				me.style.background=defaultColor;
				me.setFocus;
				return true;
			}
		}
		catch(Err){
			return 'Err';
		}
	}

// END 
 
  
// !!!! !!HIEKE A OBJECT //
function hideMe(myId){
	document.getElementById(myId).style.display="none";
	
}
// END

// !!!!!! TO SHOW A OBJECT 
function showMe(myId){
	document.getElementById(myId).style.display="block";
	
}
//END 




// !!!!!!  ASSIGN VALUE IN TO A OBJECT

function directMyvalueto(myValue,thatId){
	document.getElementById(thatId).value=myValue;
}
// END 


function checkform()
{
	error = 0;

	if( document.getElementById('field_myvideo_title').value == "" )
	{
		alert('Sorry, you need to write a title.');
		error = 1;
	}

	if( document.getElementById('field_myvideo_descr').value == "" )
	{
		alert('Sorry, you need to write a description.');
		error = 1;
	}


	if( document.getElementById('field_myvideo_keywords').value == "" )
	{
		alert('Sorry, you need to write a tag.');
		error = 1;
	}


	if( document.getElementById('listch').value == "" )
	{
		alert('Sorry, you need to select a channel.');
		error = 1;
	}

	if( document.getElementById('embed_code') != undefined )
	{
		if( document.getElementById('embed_code').value == "" )
		{
			alert('Sorry, you need to write a embed code.');
			error = 1;
		}
	}

	if( error == 1 )
	{
		return true;
	}
	else
	{
		if( document.getElementById('submit_embed') != undefined )
		{
			document.getElementById('upload_button').style.display = "none";
		}

		document.form_upload.submit();
		return false;
	}

}



function strstr (haystack, needle, bool) {

    var pos = 0;
    
    haystack += '';
    pos = haystack.indexOf( needle );
    if (pos == -1) {
        return false;
    } else{
        if (bool){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}

function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}

function strrchr (haystack, needle, inclu) {
    var pos = 0;
 
    if (typeof needle !== 'string') {
        needle = String.fromCharCode(parseInt(needle, 10));
    }
    needle = needle.charAt(0);
    pos = haystack.lastIndexOf(needle);
    if (pos === -1) {
        return haystack;
    }
 
	if(inclu == 1)
	{
		pos = pos + 1;
	}

    return haystack.substr(pos);
}

