// - general function - start

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = { 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	}, 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	}, 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			} 
		} 
		return utftext;
	}, 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0; 
		while ( i < utftext.length ) { 
			c = utftext.charCodeAt(i); 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			} 
		} 
		return string;
	} 
}

function waitingProcess(){
	$("showMsg").style.display = " block ";
	$("showMsg").innerHTML = "<image src='images/ajax-horizontal.gif' />";
}

function hideMessage(){
	$("showMsg").innerHTML = "";
	$("showMsg").style.display = " none ";
}

function showHideMessage(txt){
	$("showMsg").style.display = " block ";
	$("showMsg").innerHTML = txt;
	showCreateVideoLink();
	setTimeout("hideMessage()",800);
}
 
function showError(txt, errorId, txtId){
	if (errorId==''){
		document.getElementById("showErrorId").innerHTML = txt;
	}
	else{
		document.getElementById(errorId).innerHTML = txt; 
		if (txtId){
			document.getElementById(txtId).focus(); 
		}
	}
}

//replace space with -
function replaceSpacesWithDash(str){
	var tt =  str.replace(/ /g,'-');
	return tt; 
}
//
function removeSpecialChar(str){
	var regExp = /[,#{}$@~\/:<>`|\^!()\[\]'\.\?;]/g;
	var tt =  str.replace(regExp,'');
	return tt;
}

//remove space
function removeSpaces(str){
	var tt =  str.replace(/^\s+|\s+$/g,'');
	return tt;
}
//

//required data
function strRequired(str){
	var str1 = removeSpaces(str);
	if (str1.length>0){
		return true;
	} else {
		return false; //return blank number
	}
}
// is number
function isNumeric(str){
	return isNaN(str);
}

//required data
function numberRequired(str){
	var str1 = str;
	if (str1.length>0){
		var tt =  isNumeric(str1);
		if (tt==false){
			return true;
		} else {
			return false;
		}
	} else {
		return false; //return blank number
	}
}

// date converter - start
function getDateObject(dateString,dateSeperator){
	//This function return a date object after accepting 
	//a date string ans dateseparator as arguments
	var curValue=dateString;
	var sepChar=dateSeperator;
	var curPos=0;
	var cDate,cMonth,cYear;

	//extract day portion
	curPos=dateString.indexOf(sepChar);
	cDate=dateString.substring(0,curPos);
	
	//extract month portion				
	endPos=dateString.indexOf(sepChar,curPos+1);
	cMonth=dateString.substring(curPos+1,endPos);

	//extract year portion				
	curPos=endPos;
	endPos=curPos+5;			
	cYear=curValue.substring(curPos+1,endPos);
	
	//Create Date Object
	dtObject = new Date(cYear,cMonth,cDate);	
	return dtObject;
}

// date converter - end
// dateComparison - start
function dateComparison(sdt){
	var chStartDays = parseInt(document.getElementById("challengestartdays").value); 
	var today = new Date();
	var cm = today.getMonth();
	var cy = today.getFullYear();
	var cdTmp = today.getDate();
	var cd = cdTmp + chStartDays; // chStartDays days added by dhannajay as required for  
	var dtc  = cd+'-'+cm+'-'+cy;
	dtcObj = getDateObject(dtc,"-");
	dttObj = getDateObject(sdt,"-");
	//alert(dttObj + '  ' + dtcObj + ' ' + cd  + ' '+cdTmp );
	if (dttObj<dtcObj){
		return false;
	}
}
// dateComparison - end

function checkSpecialChar(charvalue){
	var invalid = /[#{}$@~/:<>`|^!()\[\];]/i;
	var charFound = charvalue.search(invalid);
	if (charFound>=0){
		return false;
	}
    return true;
}

function validateEmailId(emailVal){  
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; 
	var isError = false;  
	if(reg.test(emailVal) == true) {
		return true;
	}
	else {
		return false;
	}
} 

// - general function - end
